Example usage for java.text AttributedCharacterIterator getRunStart

List of usage examples for java.text AttributedCharacterIterator getRunStart

Introduction

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

Prototype

public int getRunStart();

Source Link

Document

Returns the index of the first character of the run with respect to all attributes containing the current character.

Usage

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 .  ja  v a  2s . com
@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;
}