use of java.text.AttributedString in project playn by threerings.
the class JavaTextLayout method layoutText.
public static JavaTextLayout layoutText(JavaGraphics gfx, String text, TextFormat format) {
// we do some fiddling to work around the fact that TextLayout chokes on the empty string
AttributedString astring = new AttributedString(text.length() == 0 ? " " : text);
if (format.font != null) {
astring.addAttribute(TextAttribute.FONT, ((JavaFont) format.font).jfont);
}
FontRenderContext frc = format.antialias ? gfx.aaFontContext : gfx.aFontContext;
return new JavaTextLayout(text, format, new TextLayout(astring.getIterator(), frc));
}
use of java.text.AttributedString in project antlrworks by antlr.
the class XJGraphics2DPS method drawString.
public void drawString(String s, float x, float y) {
if (s == null || s.length() == 0)
return;
AttributedString as = new AttributedString(s);
as.addAttribute(TextAttribute.FONT, getFont());
drawString(as.getIterator(), x, y);
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getRunLimitLSet.
public void test_getRunLimitLSet() {
AttributedString as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, 3);
AttributedCharacterIterator it = as.getIterator();
HashSet<AttributedCharacterIterator.Attribute> attr = new HashSet<AttributedCharacterIterator.Attribute>();
attr.add(AttributedCharacterIterator.Attribute.LANGUAGE);
assertEquals("non-null value limit", 2, it.getRunLimit(attr));
as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, null, 2, 3);
it = as.getIterator();
assertEquals("null value limit", 4, it.getRunLimit(attr));
attr.add(AttributedCharacterIterator.Attribute.READING);
assertEquals("null value limit", 4, it.getRunLimit(attr));
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getRunStartLjava_util_Set.
public void test_getRunStartLjava_util_Set() {
AttributedString as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "a", 2, 3);
AttributedCharacterIterator it = as.getIterator();
HashSet<AttributedCharacterIterator.Attribute> attr = new HashSet<AttributedCharacterIterator.Attribute>();
attr.add(AttributedCharacterIterator.Attribute.LANGUAGE);
assertEquals(0, it.getRunStart(attr));
as = new AttributedString("test");
as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "ENGLISH", 1, 3);
it = as.getIterator();
assertEquals(0, it.getRunStart(attr));
attr.add(AttributedCharacterIterator.Attribute.READING);
assertEquals(0, it.getRunStart(attr));
}
use of java.text.AttributedString in project robovm by robovm.
the class OldAttributedStringTest method test_ConstructorLAttributedCharacterIterator_1.
public void test_ConstructorLAttributedCharacterIterator_1() {
String testString = "Test string";
AttributedString attrString = new AttributedString(testString);
AttributedCharacterIterator iter = attrString.getIterator();
AttributedString attrString2 = new AttributedString(iter);
assertEqualString("String must match!", testString, attrString2);
}
Aggregations