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