Search in sources :

Example 6 with FontStyle

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

the class FontInfoReader method readStyle.

private FontStyle readStyle() {
    FontStyle style = defaultFont.getStyleOrNull();
    // font style
    MxlFontStyle mxlStyle = mxlFont.getFontStyle();
    if (mxlStyle != MxlFontStyle.Unknown) {
        boolean isItalic = mxlStyle == MxlFontStyle.Italic;
        style = style.with(FontStyle.Italic, isItalic);
    }
    // font weight
    MxlFontWeight mxlWeight = mxlFont.getFontWeight();
    if (mxlWeight != null) {
        boolean isBold = mxlWeight == MxlFontWeight.Bold;
        style = style.with(FontStyle.Bold, isBold);
    }
    return style;
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) MxlFontStyle(com.xenoage.zong.musicxml.types.enums.MxlFontStyle) MxlFontWeight(com.xenoage.zong.musicxml.types.enums.MxlFontWeight) MxlFontStyle(com.xenoage.zong.musicxml.types.enums.MxlFontStyle)

Example 7 with FontStyle

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

the class AwtFontUtils method toAwtFont.

/**
 * Gets the {@link Font} that matches best to the values of the
 * given {@link FontInfo} object.
 */
public static Font toAwtFont(FontInfo fontInfo) {
    if (// TIDY
    fontInfo == null)
        return toAwtFont(FontInfo.defaultValue);
    // find an appropriate family:
    // go through all families, until a known family is found. if no family
    // is found, look for replacements. If also not found, take the base font family.
    String fontFamily = null;
    for (String family : fontInfo.getFamilies()) {
        if (FontUtils.getInstance().isFontFamilySupported(family)) {
            fontFamily = family;
            break;
        }
    }
    if (fontFamily == null) {
        for (String family : fontInfo.getFamilies()) {
            String replacement = FontReplacements.getInstance().getReplacement(family);
            if (replacement != family && FontUtils.getInstance().isFontFamilySupported(replacement)) {
                fontFamily = replacement;
                break;
            }
        }
    }
    if (fontFamily == null) {
        fontFamily = defaultFamily;
    }
    // size
    float fontSize = fontInfo.getSize();
    // style
    FontStyle style = fontInfo.getStyle();
    int fontStyle = Font.PLAIN;
    fontStyle |= (style.isSet(FontStyle.Bold) ? Font.BOLD : 0);
    fontStyle |= (style.isSet(FontStyle.Italic) ? Font.ITALIC : 0);
    return new Font(fontFamily, fontStyle, Math.round(fontSize));
}
Also used : FontStyle(com.xenoage.utils.font.FontStyle) Font(java.awt.Font)

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