FileDocCategorySizeDatePackage
TextMeasurer.javaAPI DocAndroid 1.5 API6037Wed May 06 22:41:54 BST 2009java.awt.font

TextMeasurer

public final class TextMeasurer extends Object implements Cloneable
The TextMeasurer class provides utilities for line break operations.
since
Android 1.0

Fields Summary
AttributedCharacterIterator
aci
The aci.
FontRenderContext
frc
The frc.
org.apache.harmony.awt.gl.font.TextRunBreaker
breaker
The breaker.
org.apache.harmony.awt.gl.font.TextMetricsCalculator
tmc
The tmc.
Constructors Summary
public TextMeasurer(AttributedCharacterIterator text, FontRenderContext frc)
Instantiates a new text measurer from the specified text.

param
text the source text.
param
frc the FontRenderContext.


                                                  
         
        this.aci = text;
        this.frc = frc;
        breaker = new TextRunBreaker(aci, this.frc);
        tmc = new TextMetricsCalculator(breaker);
    
Methods Summary
protected java.lang.Objectclone()
Returns a copy of this object.

return
a copy of this object.

        return new TextMeasurer((AttributedCharacterIterator)aci.clone(), frc);
    
public voiddeleteChar(java.text.AttributedCharacterIterator newParagraph, int deletePos)
Replaces the current text with the new text and deletes a character at the specified position.

param
newParagraph the paragraph text after deletion.
param
deletePos the position in the text where the character is removed.

        AttributedCharacterIterator oldAci = aci;
        aci = newParagraph;
        if ((oldAci.getEndIndex() - oldAci.getBeginIndex())
                - (aci.getEndIndex() - aci.getBeginIndex()) != 1) {
            breaker = new TextRunBreaker(aci, this.frc);
            tmc = new TextMetricsCalculator(breaker);
        } else {
            breaker.deleteChar(newParagraph, deletePos);
        }
    
public floatgetAdvanceBetween(int start, int end)
Returns the graphical width of a line beginning at "start" parameter and including characters up to "end" parameter. "start" and "end" are absolute indices, not relative to the "start" of the paragraph.

param
start the character index at which to start measuring.
param
end the character index at which to stop measuring.
return
the graphical width of a line beginning at "start" and including characters up to "end".

        breaker.pushSegments(start - aci.getBeginIndex(), end - aci.getBeginIndex());

        breaker.createAllSegments();
        float retval = tmc.createMetrics().getAdvance();

        breaker.popSegments();
        return retval;
    
public java.awt.font.TextLayoutgetLayout(int start, int limit)
Returns a TextLayout of the specified character range.

param
start the index of the first character.
param
limit the index after the last character.
return
a TextLayout for the characters beginning at "start" up to "end".

        breaker.pushSegments(start - aci.getBeginIndex(), limit - aci.getBeginIndex());

        breaker.createAllSegments();
        TextLayout layout = new TextLayout((TextRunBreaker)breaker.clone());

        breaker.popSegments();
        return layout;
    
public intgetLineBreakIndex(int start, float maxAdvance)
Returns the index of the first character which is not fit on a line beginning at start and possible measuring up to maxAdvance in graphical width.

param
start he character index at which to start measuring.
param
maxAdvance the graphical width in which the line must fit.
return
the index after the last character that is fit on a line beginning at start, which is not longer than maxAdvance in graphical width.

        breaker.createAllSegments();
        return breaker.getLineBreakIndex(start - aci.getBeginIndex(), maxAdvance)
                + aci.getBeginIndex();
    
public voidinsertChar(java.text.AttributedCharacterIterator newParagraph, int insertPos)
Replaces the current text with the new text, inserting a break character at the specified insert position.

param
newParagraph the new paragraph text.
param
insertPos the position in the text where the character is inserted.

        AttributedCharacterIterator oldAci = aci;
        aci = newParagraph;
        if ((oldAci.getEndIndex() - oldAci.getBeginIndex())
                - (aci.getEndIndex() - aci.getBeginIndex()) != -1) {
            breaker = new TextRunBreaker(aci, this.frc);
            tmc = new TextMetricsCalculator(breaker);
        } else {
            breaker.insertChar(newParagraph, insertPos);
        }