use of java.text.AttributedCharacterIterator in project limelight by slagyr.
the class Lineator method parseTextForMultipleLayouts.
public static void parseTextForMultipleLayouts(TextModel model, ArrayList<TypedLayout> lines) {
String text = model.getDisplayableText();
AttributedString attrString = new AttributedString(text);
attrString.addAttribute(TextAttribute.FONT, model.getFont());
AttributedCharacterIterator iterator = attrString.getIterator();
ArrayList<Integer> newLineCharIndices = findNewLineCharIndices(text);
LineBreakMeasurer breaker = new LineBreakMeasurer(iterator, TextPanel.getRenderContext());
int lastCharIndex = 0, newLineCharIndex = 0;
while (breaker.getPosition() < iterator.getEndIndex()) {
lastCharIndex = addNewLayoutForTheNextLine(text, model, lines, breaker, lastCharIndex, newLineCharIndex, newLineCharIndices);
if (layoutEndedOnNewLineChar(lastCharIndex, newLineCharIndex, newLineCharIndices))
newLineCharIndex++;
}
addBlankLayoutIfLastLineIsEmpty(text, model, lines);
}
use of java.text.AttributedCharacterIterator 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.AttributedCharacterIterator in project es6draft by anba.
the class DateTimeFormatConstructor method CreateDateTimeParts.
/**
* CreateDateTimeParts(dateTimeFormat, x)
*
* @param dateTimeFormat
* the date format object
* @param date
* the date object
* @return the formatted date-time object
*/
private static List<Map.Entry<String, String>> CreateDateTimeParts(DateTimeFormatObject dateTimeFormat, Date date) {
ArrayList<Map.Entry<String, String>> parts = new ArrayList<>();
DateFormat dateFormat = dateTimeFormat.getDateFormat();
AttributedCharacterIterator iterator = dateFormat.formatToCharacterIterator(date);
StringBuilder sb = new StringBuilder();
for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
sb.append(ch);
if (iterator.getIndex() + 1 == iterator.getRunLimit()) {
Iterator<Attribute> keyIterator = iterator.getAttributes().keySet().iterator();
String key;
if (keyIterator.hasNext()) {
key = fieldToString((DateFormat.Field) keyIterator.next());
} else {
key = "separator";
}
String value = sb.toString();
sb.setLength(0);
parts.add(new AbstractMap.SimpleImmutableEntry<>(key, value));
}
}
return parts;
}
use of java.text.AttributedCharacterIterator in project binnavi by google.
the class ZyLineContent method getBackgroundStyleRunData.
public List<CStyleRunData> getBackgroundStyleRunData(final int start, final int end) {
Preconditions.checkState((start >= 0) && (start <= end) && (start < m_text.length()), "Illegal start value.");
Preconditions.checkState((end >= 0) && (end >= start) && (end < m_text.length()), "Illegal end value.");
final List<CStyleRunData> styleRun = new ArrayList<CStyleRunData>();
final AttributedCharacterIterator iterator = m_atext.getIterator();
iterator.setIndex(start);
Color lastColor = null;
int attributeStart = start;
for (int i = start; i <= end; ++i) {
final Color color = (Color) iterator.getAttribute(TextAttribute.BACKGROUND);
if (((color != null) && !color.equals(lastColor)) || ((lastColor != null) && !lastColor.equals(color))) {
if (lastColor != null) {
final CStyleRunData data = new CStyleRunData(attributeStart, (i - attributeStart) + 1, lastColor);
styleRun.add(data);
}
lastColor = color;
attributeStart = i;
}
iterator.next();
}
final CStyleRunData data = new CStyleRunData(attributeStart, (end - attributeStart) + 1, lastColor);
styleRun.add(data);
return styleRun;
}
use of java.text.AttributedCharacterIterator in project j2objc by google.
the class AttributedStringTest method test_ConstructorLjava_lang_String.
/**
* @tests java.text.AttributedString#AttributedString(java.lang.String)
*/
public void test_ConstructorLjava_lang_String() {
String test = "Test string";
AttributedString attrString = new AttributedString(test);
AttributedCharacterIterator it = attrString.getIterator();
StringBuffer buf = new StringBuffer();
buf.append(it.first());
char ch;
while ((ch = it.next()) != CharacterIterator.DONE) buf.append(ch);
assertTrue("Wrong string: " + buf, buf.toString().equals(test));
}
Aggregations