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

LineBreakMeasurer

public final class LineBreakMeasurer extends Object
The class LineBreakMeasurer provides methods to measure the graphical representation of a text in order to determine where to add line breaks so the resulting line of text fits its wrapping width. The wrapping width defines the visual width of the paragraph.
since
Android 1.0

Fields Summary
private TextMeasurer
tm
The tm.
private int
position
The position.
int
maxpos
The maxpos.
Constructors Summary
public LineBreakMeasurer(AttributedCharacterIterator text, FontRenderContext frc)
Instantiates a new LineBreakMeasurer object for the specified text.

param
text the AttributedCharacterIterator object which contains text with at least one character.
param
frc the FontRenderContext represented information about graphic device.


                                                                                     
         
        // ???AWT: this(text, BreakIterator.getLineInstance(), frc);
    
Methods Summary
public voiddeleteChar(java.text.AttributedCharacterIterator newText, int pos)
Deletes a character from the specified position of the text, updates this LineBreakMeasurer object.

param
newText the new text.
param
pos the position of the character which is deleted.

        tm.deleteChar(newText, pos);
        // ???AWT: bi.setText(newText);

        position = newText.getBeginIndex();

        maxpos--;
    
public intgetPosition()
Gets current position of this LineBreakMeasurer.

return
the current position of this LineBreakMeasurer

        return position;
    
public voidinsertChar(java.text.AttributedCharacterIterator newText, int pos)
Inserts a character at the specified position in the text, updates this LineBreakMeasurer object.

param
newText the new text.
param
pos the position of the character which is inserted.

        tm.insertChar(newText, pos);
        // ???AWT: bi.setText(newText);

        position = newText.getBeginIndex();

        maxpos++;
    
public java.awt.font.TextLayoutnextLayout(float wrappingWidth, int offsetLimit, boolean requireNextWord)
Returns the next line of text, updates current position in this LineBreakMeasurer.

param
wrappingWidth the maximum visible line width.
param
offsetLimit the limit point within the text indicating that no further text should be included on the line; the paragraph break.
param
requireNextWord if true, null is returned (the entire word at the current position does not fit within the wrapping width); if false, a valid layout is returned that includes at least the character at the current position.
return
the next TextLayout which begins at the current position and represents the next line of text with width wrappingWidth, null is returned if the entire word at the current position does not fit within the wrapping width.

        if (position == maxpos) {
            return null;
        }

        int nextPosition = nextOffset(wrappingWidth, offsetLimit, requireNextWord);

        if (nextPosition == position) {
            return null;
        }
        TextLayout layout = tm.getLayout(position, nextPosition);
        position = nextPosition;
        return layout;
    
public java.awt.font.TextLayoutnextLayout(float wrappingWidth)
Returns the next line of text.

param
wrappingWidth the maximum visible line width.
return
the next line of text.

        return nextLayout(wrappingWidth, maxpos, false);
    
public intnextOffset(float wrappingWidth)
Returns the end position of the next line of text.

param
wrappingWidth the maximum visible line width.
return
the end position of the next line of text.

        return nextOffset(wrappingWidth, maxpos, false);
    
public intnextOffset(float wrappingWidth, int offsetLimit, boolean requireNextWord)
Returns the end position of the next line of text.

param
wrappingWidth the maximum visible line width.
param
offsetLimit the limit point withing the text indicating that no further text should be included on the line; the paragraph break.
param
requireNextWord if true, the current position is returned if the entire next word does not fit within wrappingWidth; if false, the offset returned is at least one greater than the current position.
return
the end position of the next line of text.
throws
IllegalArgumentException if the offsetLimit is less than the current position.

        if (offsetLimit <= position) {
            // awt.203=Offset limit should be greater than current position.
            throw new IllegalArgumentException(Messages.getString("awt.203")); //$NON-NLS-1$
        }

        if (position == maxpos) {
            return position;
        }

        int breakPos = tm.getLineBreakIndex(position, wrappingWidth);
        int correctedPos = breakPos;

        // This check is required because bi.preceding(maxpos) throws an
        // exception
        /*
         * ???AWT if (breakPos == maxpos) { correctedPos = maxpos; } else if
         * (Character.isWhitespace(bi.getText().setIndex(breakPos))) {
         * correctedPos = bi.following(breakPos); } else { correctedPos =
         * bi.preceding(breakPos); }
         */

        if (position >= correctedPos) {
            if (requireNextWord) {
                correctedPos = position;
            } else {
                correctedPos = Math.max(position + 1, breakPos);
            }
        }

        return Math.min(correctedPos, offsetLimit);
    
public voidsetPosition(int pos)
Sets the new position of this LineBreakMeasurer.

param
pos the new position of this LineBreakMeasurer.

        if (tm.aci.getBeginIndex() > pos || maxpos < pos) {
            // awt.33=index is out of range
            throw new IllegalArgumentException(Messages.getString("awt.33")); //$NON-NLS-1$
        }
        position = pos;