use of com.xenoage.zong.renderer.awt.symbol.PathSymbolGraphicAttribute in project Zong by Xenoage.
the class TextLayoutTools method create.
/**
* Creates a {@link TextLayout} for the given {@link FormattedTextParagraph},
* including both {@link FormattedTextString}s and {@link FormattedTextSymbol}s.
* If impossible (e.g. because the paragraph is empty), null is returned.
*/
private static TextLayout create(FormattedTextParagraph p, FontRenderContext frc) {
// get the raw string
AttributedString as = new AttributedString(p.getText());
// set attributes
int pos = 0;
int count = 0;
for (FormattedTextElement e : p.getElements()) {
int len = e.getLength();
if (len > 0) {
if (e instanceof FormattedTextString) {
as.addAttributes(createAttributesMap(e.getStyle()), pos, pos + len);
count++;
} else if (e instanceof FormattedTextSymbol) {
FormattedTextSymbol fts = (FormattedTextSymbol) e;
Symbol symbol = fts.getSymbol();
if (symbol instanceof PathSymbol) {
as.addAttribute(TextAttribute.FOREGROUND, toAwtColor(fts.getStyle().getColor()), pos, pos + 1);
as.addAttribute(TextAttribute.CHAR_REPLACEMENT, new PathSymbolGraphicAttribute((PathSymbol) symbol, fts.getScaling()), pos, pos + 1);
count += 2;
}
}
pos += len;
}
}
if (count == 0)
// creating a TextLayout would fail
return null;
else
return new TextLayout(as.getIterator(), frc);
}
Aggregations