2362N/A * Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved 0N/A * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved 0N/A * The original version of this source code and documentation is 0N/A * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary 0N/A * of IBM. These materials are provided under terms of a License 0N/A * Agreement between Taligent and Sun. This technology is protected 0N/A * by multiple US and International patents. 0N/A * This notice and attribution to Taligent may not be removed. 0N/A * Taligent is a registered trademark of Taligent, Inc. 0N/A * The <code>TextMeasurer</code> class provides the primitive operations 0N/A * needed for line break: measuring up to a given advance, determining the 0N/A * advance of a range of characters, and generating a 0N/A * <code>TextLayout</code> for a range of characters. It also provides 0N/A * methods for incremental editing of paragraphs. 0N/A * A <code>TextMeasurer</code> object is constructed with an 0N/A * {@link java.text.AttributedCharacterIterator AttributedCharacterIterator} 0N/A * representing a single paragraph of text. The value returned by the 0N/A * {@link AttributedCharacterIterator#getBeginIndex() getBeginIndex} 0N/A * method of <code>AttributedCharacterIterator</code> 0N/A * defines the absolute index of the first character. The value 0N/A * {@link AttributedCharacterIterator#getEndIndex() getEndIndex} 0N/A * method of <code>AttributedCharacterIterator</code> defines the index 0N/A * past the last character. These values define the range of indexes to 0N/A * use in calls to the <code>TextMeasurer</code>. For example, calls to 0N/A * get the advance of a range of text or the line break of a range of text 0N/A * must use indexes between the beginning and end index values. Calls to 0N/A * {@link #insertChar(java.text.AttributedCharacterIterator, int) insertChar} 0N/A * {@link #deleteChar(java.text.AttributedCharacterIterator, int) deleteChar} 0N/A * reset the <code>TextMeasurer</code> to use the beginning index and end 0N/A * index of the <code>AttributedCharacterIterator</code> passed in those calls. 0N/A * Most clients will use the more convenient <code>LineBreakMeasurer</code>, 0N/A * which implements the standard line break policy (placing as many words 0N/A * as will fit on each line). 0N/A * @author John Raley 0N/A * @see LineBreakMeasurer 0N/A // Number of lines to format to. 0N/A String s = System.getProperty("estLines"); 0N/A Float f = new Float(s); 0N/A EST_LINES = f.floatValue(); 0N/A catch(NumberFormatException e) { 0N/A //System.out.println("EST_LINES="+EST_LINES); 0N/A // characters in source text 0N/A // Bidi for this paragraph 0N/A // Levels array for chars in this paragraph - needed to reorder 0N/A // trailing counterdirectional whitespace 0N/A // line components in logical order 0N/A // index where components begin 0N/A // index where components end 0N/A // used to find valid starting points for line components 0N/A // paragraph, with resolved fonts and styles 0N/A // paragraph data - same across all layouts 0N/A * Constructs a <code>TextMeasurer</code> from the source text. 0N/A * The source text should be a single entire paragraph. 0N/A * @param text the source paragraph. Cannot be null. 0N/A * @param frc the information about a graphics device which is needed 0N/A * to measure the text correctly. Cannot be null. 0N/A * Initialize state, including fChars array, direction, and 0N/A // set paragraph attributes 0N/A // If there's an embedded graphic at the start of the 0N/A // paragraph, look for the first non-graphic character 0N/A // and use it and its font to initialize the paragraph. 0N/A // If not, use the first graphic to initialize. 0N/A // hmmm what to do here? Just try to supply reasonable 0N/A * Generate components for the paragraph. fChars, fBidi should have been 0N/A * initialized already. 0N/A int layoutFlags =
0;
// no extra info yet, bidi determines run and line direction 0N/A //debugFormatCount += (endingAt-startingAt); 0N/A // either of these statements removes the bug: 0N/A //generateComponents(0, fChars.length); 0N/A //generateComponents(pos, fChars.length); 0N/A // tlcStart is now the start of the tlc at tlcIndex 0N/A // format more text and try again 0N/A //if (haveLayoutWindow) { 0N/A * According to the Unicode Bidirectional Behavior specification 0N/A * (Unicode Standard 2.0, section 3.11), whitespace at the ends 0N/A * of lines which would naturally flow against the base direction 0N/A * must be made to flow with the line direction, and moved to the 0N/A * end of the line. This method returns the start of the sequence 0N/A * of trailing whitespace characters to move to the end of a 0N/A * line taken from the given range. 0N/A // Back up over counterdirectional whitespace 0N/A // sigh I really hate to do this here since it's part of the 0N/A // cdWsStart is the start of the trailing counterdirectional 0N/A // tlcStart is now the start of the tlc at tlcIndex 0N/A // If we've already gone past the layout window, format to end of paragraph 0N/A * Returns the index of the first character which will not fit on 0N/A * on a line beginning at <code>start</code> and possible 0N/A * measuring up to <code>maxAdvance</code> in graphical width. 0N/A * @param start the character index at which to start measuring. 0N/A * <code>start</code> is an absolute index, not relative to the 0N/A * start of the paragraph 0N/A * @param maxAdvance the graphical width in which the line must fit 0N/A * @return the index after the last character that will fit 0N/A * on a line beginning at <code>start</code>, which is not longer 0N/A * than <code>maxAdvance</code> in graphical width 0N/A * @throws IllegalArgumentException if <code>start</code> is 0N/A * less than the beginning of the paragraph. 0N/A * Returns the graphical width of a line beginning at <code>start</code> 0N/A * and including characters up to <code>limit</code>. 0N/A * <code>start</code> and <code>limit</code> are absolute indices, 0N/A * not relative to the start of the paragraph. 0N/A * @param start the character index at which to start measuring 0N/A * @param limit the character index at which to stop measuring 0N/A * @return the graphical width of a line beginning at <code>start</code> 0N/A * and including characters up to <code>limit</code> 0N/A * @throws IndexOutOfBoundsException if <code>limit</code> is less 0N/A * than <code>start</code> 0N/A * @throws IllegalArgumentException if <code>start</code> or 0N/A * <code>limit</code> is not between the beginning of 0N/A * the paragraph and the end of the paragraph. 0N/A // could cache line in case getLayout is called with same start, limit 0N/A * Returns a <code>TextLayout</code> on the given character range. 0N/A * @param start the index of the first character 0N/A * @param limit the index after the last character. Must be greater 0N/A * than <code>start</code> 0N/A * @return a <code>TextLayout</code> for the characters beginning at 0N/A * <code>start</code> up to (but not including) <code>limit</code> 0N/A * @throws IndexOutOfBoundsException if <code>limit</code> is less 0N/A * than <code>start</code> 0N/A * @throws IllegalArgumentException if <code>start</code> or 0N/A * <code>limit</code> is not between the beginning of 0N/A * the paragraph and the end of the paragraph. 0N/A private static boolean wantStats =
false;
/*"true".equals(System.getProperty("collectStats"));*/ 0N/A //formattedChars = 0; 0N/A * Updates the <code>TextMeasurer</code> after a single character has 0N/A * into the paragraph currently represented by this 0N/A * <code>TextMeasurer</code>. After this call, this 0N/A * <code>TextMeasurer</code> is equivalent to a new 0N/A * <code>TextMeasurer</code> created from the text; however, it will 0N/A * usually be more efficient to update an existing 0N/A * <code>TextMeasurer</code> than to create a new one from scratch. 0N/A * @param newParagraph the text of the paragraph after performing 0N/A * the insertion. Cannot be null. 0N/A * @param insertPos the position in the text where the character was 0N/A * inserted. Must not be less than the start of 0N/A * <code>newParagraph</code>, and must be less than the end of 0N/A * <code>newParagraph</code>. 0N/A * @throws IndexOutOfBoundsException if <code>insertPos</code> is less 0N/A * than the start of <code>newParagraph</code> or greater than 0N/A * or equal to the end of <code>newParagraph</code> 0N/A * @throws NullPointerException if <code>newParagraph</code> is 0N/A * Updates the <code>TextMeasurer</code> after a single character has 0N/A * from the paragraph currently represented by this 0N/A * <code>TextMeasurer</code>. After this call, this 0N/A * <code>TextMeasurer</code> is equivalent to a new <code>TextMeasurer</code> 0N/A * created from the text; however, it will usually be more efficient 0N/A * to update an existing <code>TextMeasurer</code> than to create a new one 0N/A * @param newParagraph the text of the paragraph after performing 0N/A * the deletion. Cannot be null. 0N/A * @param deletePos the position in the text where the character was removed. 0N/A * Must not be less than 0N/A * the start of <code>newParagraph</code>, and must not be greater than the 0N/A * end of <code>newParagraph</code>. 0N/A * @throws IndexOutOfBoundsException if <code>deletePos</code> is 0N/A * less than the start of <code>newParagraph</code> or greater 0N/A * than the end of <code>newParagraph</code> 0N/A * @throws NullPointerException if <code>newParagraph</code> is 0N/A * NOTE: This method is only for LineBreakMeasurer's use. It is package- 0N/A * private because it returns internal data.