Search in sources :

Example 11 with AttributedCharacterIterator

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

Example 12 with AttributedCharacterIterator

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

Example 13 with AttributedCharacterIterator

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;
}
Also used : Attribute(java.text.AttributedCharacterIterator.Attribute) ArrayList(java.util.ArrayList) AttributedCharacterIterator(java.text.AttributedCharacterIterator) AbstractMap(java.util.AbstractMap) DateField(com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.DateField) DateFormat(com.ibm.icu.text.DateFormat) SimpleDateFormat(com.ibm.icu.text.SimpleDateFormat)

Example 14 with AttributedCharacterIterator

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

Example 15 with AttributedCharacterIterator

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

Aggregations

AttributedCharacterIterator (java.text.AttributedCharacterIterator)52 AttributedString (java.text.AttributedString)35 TextLayout (java.awt.font.TextLayout)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)15 Point (java.awt.Point)8 Font (java.awt.Font)7 Paint (java.awt.Paint)7 FontRenderContext (java.awt.font.FontRenderContext)7 Graphics2D (java.awt.Graphics2D)6 Color (java.awt.Color)5 ArrayList (java.util.ArrayList)5 WeakHashMap (java.util.WeakHashMap)5 Rectangle (java.awt.Rectangle)4 Attribute (java.text.AttributedCharacterIterator.Attribute)4 DecimalFormat (java.text.DecimalFormat)4 BigDecimal (java.math.BigDecimal)3 BigInteger (java.math.BigInteger)3 HashSet (java.util.HashSet)3 Dimension (java.awt.Dimension)2 Image (java.awt.Image)2