Search in sources :

Example 16 with FormattedTextStyle

use of com.xenoage.zong.core.text.FormattedTextStyle in project Zong by Xenoage.

the class FormattedTextConverter method getStyleFromAttributeSet.

private static FormattedTextStyle getStyleFromAttributeSet(AttributeSet attr) {
    if (attr == null) {
        return FormattedTextStyle.Companion.getDefaultStyle();
    }
    // font style
    FontStyle fontStyle = FontStyle.normal;
    if (StyleConstants.isBold(attr)) {
        fontStyle = fontStyle.with(FontStyle.Bold);
    }
    if (StyleConstants.isItalic(attr)) {
        fontStyle = fontStyle.with(FontStyle.Italic);
    }
    if (StyleConstants.isUnderline(attr)) {
        fontStyle = fontStyle.with(FontStyle.Underline);
    }
    if (StyleConstants.isStrikeThrough(attr)) {
        fontStyle = fontStyle.with(FontStyle.Strikethrough);
    }
    // superscript
    Superscript superscript = Superscript.Normal;
    if (StyleConstants.isSuperscript(attr)) {
        superscript = Superscript.Super;
    }
    if (StyleConstants.isSubscript(attr)) {
        superscript = Superscript.Sub;
    }
    // font
    FontInfo fontInfo = new FontInfo(StyleConstants.getFontFamily(attr), (float) StyleConstants.getFontSize(attr), fontStyle);
    return new FormattedTextStyle(fontInfo, fromAwtColor(StyleConstants.getForeground(attr)), superscript);
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) Superscript(com.xenoage.zong.core.text.Superscript) FontInfo(com.xenoage.utils.font.FontInfo)

Example 17 with FormattedTextStyle

use of com.xenoage.zong.core.text.FormattedTextStyle in project Zong by Xenoage.

the class FormattedTextReader method readText.

@Override
public FormattedText readText(MxlFormattedText mxlText) {
    String text = mxlText.getValue().trim();
    FormattedTextStyle style = readStyle(mxlText);
    Alignment alignment = readAlignment(mxlText);
    return FormattedText.Companion.fText(text, style, alignment);
}
Also used : Alignment(com.xenoage.zong.core.text.Alignment) FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle)

Aggregations

FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)17 FormattedTextString (com.xenoage.zong.core.text.FormattedTextString)10 FontInfo (com.xenoage.utils.font.FontInfo)9 FormattedTextElement (com.xenoage.zong.core.text.FormattedTextElement)7 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)6 FormattedText (com.xenoage.zong.core.text.FormattedText)4 Test (org.junit.Test)4 Score (com.xenoage.zong.core.Score)3 Color (com.xenoage.utils.color.Color)2 Chord (com.xenoage.zong.core.music.chord.Chord)2 Alignment (com.xenoage.zong.core.text.Alignment)2 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 NonNull (com.xenoage.utils.annotations.NonNull)1 FontStyle (com.xenoage.utils.font.FontStyle)1 TextMeasurer (com.xenoage.utils.font.TextMeasurer)1 Fraction (com.xenoage.utils.math.Fraction)1 Point2f (com.xenoage.utils.math.geom.Point2f)1 MeasureNumbering (com.xenoage.zong.core.format.MeasureNumbering)1 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)1