Search in sources :

Example 1 with FontStyle

use of com.xenoage.utils.font.FontStyle in project Zong by Xenoage.

the class FontInfoReader method read.

@MaybeNull
public FontInfo read() {
    IList<String> families = readFamilies();
    Float size = readSize();
    FontStyle style = readStyle();
    return new FontInfo(families, size, style);
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) MxlFontStyle(com.xenoage.zong.musicxml.types.enums.MxlFontStyle) FontInfo(com.xenoage.utils.font.FontInfo) MaybeNull(com.xenoage.utils.annotations.MaybeNull)

Example 2 with FontStyle

use of com.xenoage.utils.font.FontStyle in project Zong by Xenoage.

the class FormattedTextConverter method getAttributeSetFromStyle.

private static SimpleAttributeSet getAttributeSetFromStyle(FormattedTextStyle style) {
    SimpleAttributeSet attr = new SimpleAttributeSet();
    if (style == null) {
        return attr;
    }
    // font style
    FontStyle fontStyle = style.getFont().getStyle();
    StyleConstants.setBold(attr, fontStyle.isSet(FontStyle.Bold));
    StyleConstants.setItalic(attr, fontStyle.isSet(FontStyle.Italic));
    StyleConstants.setUnderline(attr, fontStyle.isSet(FontStyle.Underline));
    StyleConstants.setStrikeThrough(attr, fontStyle.isSet(FontStyle.Strikethrough));
    // color
    StyleConstants.setForeground(attr, toAwtColor(style.getColor()));
    // font
    Font font = toAwtFont(style.getFont());
    StyleConstants.setFontFamily(attr, font.getFamily());
    StyleConstants.setFontSize(attr, font.getSize());
    // superscript
    if (style.getSuperscript() == Superscript.Super) {
        StyleConstants.setSuperscript(attr, true);
    } else if (style.getSuperscript() == Superscript.Sub) {
        StyleConstants.setSubscript(attr, true);
    }
    return attr;
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) FontStyle(com.xenoage.utils.font.FontStyle) Font(java.awt.Font) AwtFontUtils.toAwtFont(com.xenoage.utils.jse.font.AwtFontUtils.toAwtFont)

Example 3 with FontStyle

use of com.xenoage.utils.font.FontStyle in project Zong by Xenoage.

the class AwtFontUtils method fromAwtFont.

/**
 * Creates a new {@link FontInfo}.
 * @param font      the AWT font
 */
public static FontInfo fromAwtFont(Font font) {
    IList<String> families = ilist(font.getFamily());
    FontStyle style = FontStyle.normal;
    if (font.isBold())
        style = style.with(FontStyle.Bold, true);
    if (font.isItalic())
        style = style.with(FontStyle.Italic, true);
    return new FontInfo(families, font.getSize2D(), style);
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) FontInfo(com.xenoage.utils.font.FontInfo)

Example 4 with FontStyle

use of com.xenoage.utils.font.FontStyle in project Zong by Xenoage.

the class TextLayoutTools method createAttributesMap.

/**
 * Creates a Map with the attributes representing
 * the given style for an AttibutedString.
 */
private static Map<TextAttribute, Object> createAttributesMap(FormattedTextStyle style) {
    Map<TextAttribute, Object> ret = new HashMap<>();
    FontInfo fontInfo = notNull(style.getFont(), FontInfo.defaultValue);
    // font name
    Font font = toAwtFont(fontInfo);
    ret.put(TextAttribute.FAMILY, font.getFamily());
    // font size
    ret.put(TextAttribute.SIZE, font.getSize2D());
    // color
    ret.put(TextAttribute.FOREGROUND, toAwtColor(style.getColor()));
    // bold
    FontStyle fontStyle = fontInfo.getStyle();
    ret.put(TextAttribute.WEIGHT, (fontStyle.isSet(FontStyle.Bold) ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR));
    // italic
    ret.put(TextAttribute.POSTURE, (fontStyle.isSet(FontStyle.Italic) ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR));
    // underline
    ret.put(TextAttribute.UNDERLINE, (fontStyle.isSet(FontStyle.Underline) ? TextAttribute.UNDERLINE_ON : null));
    // superscript
    switch(style.getSuperscript()) {
        case Super:
            ret.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER);
            break;
        case Sub:
            ret.put(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUB);
            break;
        default:
            ret.put(TextAttribute.SUPERSCRIPT, null);
    }
    return ret;
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) HashMap(java.util.HashMap) TextAttribute(java.awt.font.TextAttribute) FontInfo(com.xenoage.utils.font.FontInfo) AwtFontUtils.toAwtFont(com.xenoage.utils.jse.font.AwtFontUtils.toAwtFont)

Example 5 with FontStyle

use of com.xenoage.utils.font.FontStyle 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)

Aggregations

FontStyle (com.xenoage.utils.font.FontStyle)7 FontInfo (com.xenoage.utils.font.FontInfo)4 AwtFontUtils.toAwtFont (com.xenoage.utils.jse.font.AwtFontUtils.toAwtFont)2 MxlFontStyle (com.xenoage.zong.musicxml.types.enums.MxlFontStyle)2 Font (java.awt.Font)2 MaybeNull (com.xenoage.utils.annotations.MaybeNull)1 FormattedTextStyle (com.xenoage.zong.core.text.FormattedTextStyle)1 Superscript (com.xenoage.zong.core.text.Superscript)1 MxlFontWeight (com.xenoage.zong.musicxml.types.enums.MxlFontWeight)1 TextAttribute (java.awt.font.TextAttribute)1 HashMap (java.util.HashMap)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1