use of com.xenoage.utils.font.FontInfo 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;
}
use of com.xenoage.utils.font.FontInfo 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);
}
Aggregations