Example usage for java.text AttributedCharacterIterator getIndex

List of usage examples for java.text AttributedCharacterIterator getIndex

Introduction

In this page you can find the example usage for java.text AttributedCharacterIterator getIndex.

Prototype

public int getIndex();

Source Link

Document

Returns the current index.

Usage

From source file:org.apache.fop.svg.NativeTextPainter.java

/**
 * Collects all characters from an {@link AttributedCharacterIterator}.
 * @param runaci the character iterator/* w w w . j  a v  a 2s  .c  o m*/
 * @return the characters
 */
protected CharSequence collectCharacters(AttributedCharacterIterator runaci) {
    StringBuffer chars = new StringBuffer();
    for (runaci.first(); runaci.getIndex() < runaci.getEndIndex();) {
        chars.append(runaci.current());
        runaci.next();
    }
    return chars;
}

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * @see Graphics2D#drawString(AttributedCharacterIterator, float, float)
 *///from w w  w . j  a  v  a 2 s .  c  o m
@Override
public void drawString(final AttributedCharacterIterator iter, float x, final float y) {
    /*
     * StringBuffer sb = new StringBuffer(); for(char c = iter.first(); c != AttributedCharacterIterator.DONE; c =
     * iter.next()) { sb.append(c); } drawString(sb.toString(),x,y);
     */
    final StringBuilder stringbuffer = new StringBuilder(iter.getEndIndex());
    for (char c = iter.first(); c != AttributedCharacterIterator.DONE; c = iter.next()) {
        if (iter.getIndex() == iter.getRunStart()) {
            if (stringbuffer.length() > 0) {
                drawString(stringbuffer.toString(), x, y);
                final FontMetrics fontmetrics = getFontMetrics();
                x = (float) (x + fontmetrics.getStringBounds(stringbuffer.toString(), this).getWidth());
                stringbuffer.delete(0, stringbuffer.length());
            }
            doAttributes(iter);
        }
        stringbuffer.append(c);
    }

    drawString(stringbuffer.toString(), x, y);
    underline = false;
}