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