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;
}
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));
}
Aggregations