Search in sources :

Example 56 with AttributedString

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));
}
Also used : AttributedString(java.text.AttributedString) FontRenderContext(java.awt.font.FontRenderContext) AbstractTextLayout(playn.core.AbstractTextLayout) TextLayout(java.awt.font.TextLayout)

Example 57 with AttributedString

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);
}
Also used : AttributedString(java.text.AttributedString)

Example 58 with AttributedString

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));
}
Also used : AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator) HashSet(java.util.HashSet)

Example 59 with AttributedString

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));
}
Also used : AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator) HashSet(java.util.HashSet)

Example 60 with AttributedString

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);
}
Also used : AttributedString(java.text.AttributedString) AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Aggregations

AttributedString (java.text.AttributedString)86 AttributedCharacterIterator (java.text.AttributedCharacterIterator)37 TextLayout (java.awt.font.TextLayout)29 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 FontRenderContext (java.awt.font.FontRenderContext)13 Font (java.awt.Font)11 Point (java.awt.Point)11 Paint (java.awt.Paint)10 Graphics2D (java.awt.Graphics2D)9 WeakHashMap (java.util.WeakHashMap)8 Color (java.awt.Color)4 Bidi (java.text.Bidi)4 ArrayList (java.util.ArrayList)4 TreeSet (java.util.TreeSet)4 Rectangle (java.awt.Rectangle)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Insets (java.awt.Insets)2 AffineTransform (java.awt.geom.AffineTransform)2 Rectangle2D (java.awt.geom.Rectangle2D)2