TextMeasurer class provides the primitive operations
needed for line break: measuring up to a given advance, determining the
advance of a range of characters, and generating a
TextLayout for a range of characters. It also provides
methods for incremental editing of paragraphs.
A TextMeasurer object is constructed with an
AttributedCharacterIterator
representing a single paragraph of text. The value returned by the
getBeginIndex
method of AttributedCharacterIterator
defines the absolute index of the first character. The value
returned by the
getEndIndex
method of AttributedCharacterIterator defines the index
past the last character. These values define the range of indexes to
use in calls to the TextMeasurer. For example, calls to
get the advance of a range of text or the line break of a range of text
must use indexes between the beginning and end index values. Calls to
insertChar
and
deleteChar
reset the TextMeasurer to use the beginning index and end
index of the AttributedCharacterIterator passed in those calls.
Most clients will use the more convenient LineBreakMeasurer,
which implements the standard line break policy (placing as many words
as will fit on each line).
LineBreakMeasurer
| Modifier and Type | Field and Description |
|---|---|
| private CharArrayIterator | |
| private boolean | |
| private static float | |
| private byte | |
| private float[] | |
| private Bidi | |
| private char[] | |
| private int | |
| private TextLineComponent[] | |
| private int | |
| private FontRenderContext | |
| private boolean | |
| private float | |
| private byte[] | |
| private BreakIterator | |
| private int | |
| private StyledParagraph | |
| private int | |
| private boolean | |
| pack-priv int | |
| pack-priv int | |
| private static boolean |
| Access | Constructor and Description |
|---|---|
| public | TextMeasurer(AttributedCharacterIterator
the source paragraph. Cannot be null. text, FontRenderContext the information about a graphics device which is needed
to measure the text correctly. Cannot be null. frc)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| private int | |
| protected Object | |
| public void | deleteChar(AttributedCharacterIterator
the text of the paragraph after performing
the deletion. Cannot be null. newParagraph, int the position in the text where the character was removed.
Must not be less than
the start of deletePos)newParagraph, and must not be greater than the
end of newParagraph.Updates the |
| private void | |
| private void | |
| public float | Returns: the graphical width of a line beginning atstart
and including characters up to limitthe character index at which to start measuring start, int the character index at which to stop measuring limit)Returns the graphical width of a line beginning at |
| pack-priv char[] | |
| public TextLayout | Returns: aTextLayout for the characters beginning at
start up to (but not including) limitthe index of the first character start, int the index after the last character. Must be greater
than limit)startReturns a |
| public int | Returns: the index after the last character that will fit on a line beginning atstart, which is not longer
than maxAdvance in graphical widththe character index at which to start measuring.
start, float start is an absolute index, not relative to the
start of the paragraphthe graphical width in which the line must fit maxAdvance)Returns the index of the first character which will not fit on
on a line beginning at |
| private void | initAll(AttributedCharacterIterator text)
Initialize state, including fChars array, direction, and fBidi. |
| public void | insertChar(AttributedCharacterIterator
the text of the paragraph after performing
the insertion. Cannot be null. newParagraph, int the position in the text where the character was
inserted. Must not be less than the start of
insertPos)newParagraph, and must be less than the end of
newParagraph.Updates the |
| private void | |
| private TextLineComponent[] | |
| private void | |
| private TextLine | |
| private void | |
| private int | trailingCdWhitespaceStart(int startPos, int limitPos)
According to the Unicode Bidirectional Behavior specification (Unicode Standard 2.0, section 3.11), whitespace at the ends of lines which would naturally flow against the base direction must be made to flow with the line direction, and moved to the end of the line. |
| charIter | back to summary |
|---|---|
| private CharArrayIterator charIter | |
| collectStats | back to summary |
|---|---|
| private boolean collectStats | |
| EST_LINES | back to summary |
|---|---|
| private static float EST_LINES | |
| fBaseline | back to summary |
|---|---|
| private byte fBaseline | |
| fBaselineOffsets | back to summary |
|---|---|
| private float[] fBaselineOffsets | |
| fBidi | back to summary |
|---|---|
| private Bidi fBidi | |
| fChars | back to summary |
|---|---|
| private char[] fChars | |
| fComponentLimit | back to summary |
|---|---|
| private int fComponentLimit | |
| fComponents | back to summary |
|---|---|
| private TextLineComponent[] fComponents | |
| fComponentStart | back to summary |
|---|---|
| private int fComponentStart | |
| fFrc | back to summary |
|---|---|
| private FontRenderContext fFrc | |
| fIsDirectionLTR | back to summary |
|---|---|
| private boolean fIsDirectionLTR | |
| fJustifyRatio | back to summary |
|---|---|
| private float fJustifyRatio | |
| fLevels | back to summary |
|---|---|
| private byte[] fLevels | |
| fLineBreak | back to summary |
|---|---|
| private BreakIterator fLineBreak | |
| formattedChars | back to summary |
|---|---|
| private int formattedChars | |
| fParagraph | back to summary |
|---|---|
| private StyledParagraph fParagraph | |
| fStart | back to summary |
|---|---|
| private int fStart | |
| haveLayoutWindow | back to summary |
|---|---|
| private boolean haveLayoutWindow | |
| layoutCharCount | back to summary |
|---|---|
| pack-priv int layoutCharCount | |
| layoutCount | back to summary |
|---|---|
| pack-priv int layoutCount | |
| wantStats | back to summary |
|---|---|
| private static boolean wantStats | |
| TextMeasurer | back to summary |
|---|---|
| public TextMeasurer(AttributedCharacterIterator text, FontRenderContext frc) Constructs a
| |
| calcLineBreak | back to summary |
|---|---|
| private int calcLineBreak(final int pos, final float maxAdvance) | |
| clone | back to summary |
|---|---|
| protected Object clone() Overrides java. Doc from java. Creates and returns a copy of this object. The precise meaning
of "copy" may depend on the class of the object. The general
intent is that, for any object will be true, and that the expression:x.clone() != x will bex.clone().getClass() == x.getClass() true, but these are not absolute requirements.
While it is typically the case that:
will bex.clone().equals(x) true, this is not an absolute requirement.
By convention, the returned object should be obtained by calling
By convention, the object returned by this method should be independent
of this object (which is being cloned). To achieve this independence,
it may be necessary to modify one or more fields of the object returned
by | |
| deleteChar | back to summary |
|---|---|
| public void deleteChar(AttributedCharacterIterator newParagraph, int deletePos) Updates the
| |
| ensureComponents | back to summary |
|---|---|
| private void ensureComponents(int start, int limit) | |
| generateComponents | back to summary |
|---|---|
| private void generateComponents(int startingAt, int endingAt) Generate components for the paragraph. fChars, fBidi should have been initialized already. | |
| getAdvanceBetween | back to summary |
|---|---|
| public float getAdvanceBetween(int start, int limit) Returns the graphical width of a line beginning at
| |
| getChars | back to summary |
|---|---|
| pack-priv char[] getChars() Note This method is only for LineBreakMeasurer's use. It is package- private because it returns internal data. | |
| getLayout | back to summary |
|---|---|
| public TextLayout getLayout(int start, int limit) Returns a
| |
| getLineBreakIndex | back to summary |
|---|---|
| public int getLineBreakIndex(int start, float maxAdvance) Returns the index of the first character which will not fit on
on a line beginning at
| |
| initAll | back to summary |
|---|---|
| private void initAll(AttributedCharacterIterator text) Initialize state, including fChars array, direction, and fBidi. | |
| insertChar | back to summary |
|---|---|
| public void insertChar(AttributedCharacterIterator newParagraph, int insertPos) Updates the
| |
| invalidateComponents | back to summary |
|---|---|
| private void invalidateComponents() | |
| makeComponentsOnRange | back to summary |
|---|---|
| private TextLineComponent[] makeComponentsOnRange(int startPos, int limitPos) | |
| makeLayoutWindow | back to summary |
|---|---|
| private void makeLayoutWindow(int localStart) | |
| makeTextLineOnRange | back to summary |
|---|---|
| private TextLine makeTextLineOnRange(int startPos, int limitPos) | |
| printStats | back to summary |
|---|---|
| private void printStats() | |
| trailingCdWhitespaceStart | back to summary |
|---|---|
| private int trailingCdWhitespaceStart(int startPos, int limitPos) According to the Unicode Bidirectional Behavior specification (Unicode Standard 2.0, section 3.11), whitespace at the ends of lines which would naturally flow against the base direction must be made to flow with the line direction, and moved to the end of the line. This method returns the start of the sequence of trailing whitespace characters to move to the end of a line taken from the given range. | |