Search in sources :

Example 26 with AttributedString

use of java.text.AttributedString in project robovm by robovm.

the class OldAttributedCharacterIteratorTest method test_getRunLimit.

public void test_getRunLimit() {
    int limit = it.getRunLimit();
    assertEquals(string.length(), limit);
    AttributedString as = new AttributedString("");
    assertEquals(0, as.getIterator().getRunLimit());
    as = new AttributedString(new AttributedString("test text").getIterator(), 2, 7);
    AttributedCharacterIterator it = as.getIterator();
    assertEquals(5, it.getRunLimit());
}
Also used : AttributedString(java.text.AttributedString) AttributedCharacterIterator(java.text.AttributedCharacterIterator)

Example 27 with AttributedString

use of java.text.AttributedString in project limelight by slagyr.

the class TextPanel method addLines.

private synchronized void addLines() {
    AttributedString aText = prepareAttributedString();
    AttributedCharacterIterator styledTextIterator = aText.getIterator();
    List<Integer> newlineLocations = getNewlineLocations(styledTextIterator);
    LineBreakMeasurer lbm = new LineBreakMeasurer(styledTextIterator, getRenderContext());
    float width = (float) consumableArea.width;
    if (width <= 0)
        return;
    TextLayout layout;
    int startOfNextLayout;
    int currentLine = 0;
    int endIndex = styledTextIterator.getEndIndex();
    do {
        if (currentLine < newlineLocations.size())
            startOfNextLayout = newlineLocations.get(currentLine) + 1;
        else
            startOfNextLayout = endIndex + 1;
        layout = lbm.nextLayout(width, startOfNextLayout, false);
        lines.add(layout);
        if (lbm.getPosition() == startOfNextLayout)
            currentLine += 1;
    } while (layout != null && lbm.getPosition() < endIndex);
}
Also used : AttributedString(java.text.AttributedString) LineBreakMeasurer(java.awt.font.LineBreakMeasurer) AttributedCharacterIterator(java.text.AttributedCharacterIterator) TextLayout(java.awt.font.TextLayout)

Example 28 with AttributedString

use of java.text.AttributedString in project limelight by slagyr.

the class TextPanel method prepareAttributedString.

private AttributedString prepareAttributedString() {
    List<StyledText> textChunks = getTextChunks();
    StringBuilder buf = new StringBuilder();
    for (StyledText textChunk : textChunks) {
        buf.append(textChunk.getText());
    }
    AttributedString attributedString = new AttributedString(buf.toString());
    int startIndex = 0;
    int endIndex = 0;
    for (StyledText textChunk : textChunks) {
        if (textChunk == textChunks.get(textChunks.size() - 1))
            endIndex = buf.length();
        else
            endIndex = startIndex + textChunk.getText().length();
        attributedString.addAttribute(TextAttribute.FONT, textChunk.getFont(), startIndex, endIndex);
        attributedString.addAttribute(TextAttribute.FOREGROUND, textChunk.getColor(), startIndex, endIndex);
        startIndex += textChunk.getText().length();
    }
    return attributedString;
}
Also used : StyledText(limelight.ui.text.StyledText) AttributedString(java.text.AttributedString)

Example 29 with AttributedString

use of java.text.AttributedString in project robovm by robovm.

the class OldAttributedCharacterIteratorTest method test_getRunStartLAttribute.

public void test_getRunStartLAttribute() {
    assertEquals(0, it.getRunStart(AttributedCharacterIterator.Attribute.LANGUAGE));
    AttributedString as = new AttributedString("test text");
    as.addAttribute(AttributedCharacterIterator.Attribute.LANGUAGE, "GERMAN", 2, 5);
    as.addAttribute(AttributedCharacterIterator.Attribute.READING, "READ", 2, 7);
    assertEquals(0, as.getIterator().getRunStart(AttributedCharacterIterator.Attribute.LANGUAGE));
    assertEquals(0, as.getIterator().getRunStart(AttributedCharacterIterator.Attribute.READING));
}
Also used : AttributedString(java.text.AttributedString)

Example 30 with AttributedString

use of java.text.AttributedString in project robovm by robovm.

the class OldAttributedStringTest method test_ConstructorLAttributedCharacterIterator_3.

public void test_ConstructorLAttributedCharacterIterator_3() {
    String testString = "Test string";
    AttributedString attrString = new AttributedString(testString);
    AttributedCharacterIterator iter = attrString.getIterator();
    AttributedString attrString2;
    attrString2 = new AttributedString(iter, 2, 7, new AttributedCharacterIterator.Attribute[] {});
    assertEqualString("String must match!", "st st", attrString2);
    attrString2 = new AttributedString(iter, 2, 7, null);
    assertEqualString("String must match!", "st st", 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