[FOray-commit] SF.net SVN: foray: [7831] trunk/foray/foray-text/src/java/org/foray/text
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2006-07-23 23:50:33
|
Revision: 7831 Author: victormote Date: 2006-07-23 16:50:24 -0700 (Sun, 23 Jul 2006) ViewCVS: http://svn.sourceforge.net/foray/?rev=7831&view=rev Log Message: ----------- Implement standard use of final modifier on local variable and method parameters. Modified Paths: -------------- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java Modified: trunk/foray/foray-text/src/java/org/foray/text/TextServer.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-07-23 23:42:47 UTC (rev 7830) +++ trunk/foray/foray-text/src/java/org/foray/text/TextServer.java 2006-07-23 23:50:24 UTC (rev 7831) @@ -51,7 +51,8 @@ * @param logger The logger instance that should be used to log * user messages. */ - public TextServer(Log logger, HyphenationServer hyphenationServer) { + public TextServer(final Log logger, + final HyphenationServer hyphenationServer) { this.logger = logger; this.hyphenationServer = hyphenationServer; } @@ -67,8 +68,9 @@ /** * {@inheritDoc} */ - public EagerLineBreaker provideEagerLineBreaker(LineBreakControl control, - LineBreakHandler handler, FontConsumer fontConsumer) { + public EagerLineBreaker provideEagerLineBreaker( + final LineBreakControl control, final LineBreakHandler handler, + final FontConsumer fontConsumer) { return new SolitaryLineBreaker(this, control, handler, fontConsumer); } @@ -76,8 +78,8 @@ * {@inheritDoc} */ public PatientLineBreaker providePatientLineBreaker( - LineBreakControl control, LineBreakHandler handler, - FontConsumer fontConsumer) { + final LineBreakControl control, final LineBreakHandler handler, + final FontConsumer fontConsumer) { /* We don't have access to any yet. */ return null; } Modified: trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java 2006-07-23 23:42:47 UTC (rev 7830) +++ trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java 2006-07-23 23:50:24 UTC (rev 7831) @@ -47,20 +47,21 @@ * Constructor. * @param control */ - public EagerLineBreaker(TextServer server, LineBreakControl control, - LineBreakHandler handler, FontConsumer fontConsumer) { + public EagerLineBreaker(final TextServer server, + final LineBreakControl control, + final LineBreakHandler handler, final FontConsumer fontConsumer) { super(server, control, handler, fontConsumer); } /** * @throws TextException */ - protected int processInput(LineContent lineContent, int start, int end) - throws TextException { + protected int processInput(final LineContent lineContent, final int start, + final int end) throws TextException { int status = 0; if (lineContent instanceof LineText) { - LineText lineText = (LineText) lineContent; - char[] text = lineText.inlineText(); + final LineText lineText = (LineText) lineContent; + final char[] text = lineText.inlineText(); if (text.length < 1) { return -1; } @@ -70,7 +71,7 @@ int subsetStart = start; this.inLowerCase = isLowerCase(text[start]); for (int i = start; i < end; i++) { - char c = text[i]; + final char c = text[i]; boolean shouldSwitch = false; if (isLowerCase(c) && ! inLowerCase) { shouldSwitch = true; @@ -108,10 +109,10 @@ * if there is not enough room on the line for it. * @throws TextException */ - protected int processLineNonText(LineNonText nonTextItem) + protected int processLineNonText(final LineNonText nonTextItem) throws TextException { - int lineLength = getCurrentLine().capacityTotal(); - int itemSize = nonTextItem.inlineSizeOptimum(lineLength); + final int lineLength = getCurrentLine().capacityTotal(); + final int itemSize = nonTextItem.inlineSizeOptimum(lineLength); if (itemSize > currentLineWidthRemaining()) { // It doesn't fit on the current line. if (getCurrentLine().capacityUsed() == 0) { @@ -138,8 +139,8 @@ - getCurrentLine().capacityUsed(); } - public int addLineContent(LineContent content, int start, int end, - LineOutput output) throws TextException { + public int addLineContent(final LineContent content, final int start, + final int end, final LineOutput output) throws TextException { this.currentOutput = output; return processInput(content, start, end); } Modified: trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-07-23 23:42:47 UTC (rev 7830) +++ trunk/foray/foray-text/src/java/org/foray/text/line/LineBreaker.java 2006-07-23 23:50:24 UTC (rev 7831) @@ -105,8 +105,9 @@ */ protected boolean inLowerCase = false; - protected LineBreaker(TextServer server, LineBreakControl control, - LineBreakHandler handler, FontConsumer fontConsumer) { + protected LineBreaker(final TextServer server, + final LineBreakControl control, + final LineBreakHandler handler, final FontConsumer fontConsumer) { this.server = server; this.control = control; this.handler = handler; @@ -122,7 +123,8 @@ * @param contentItem The LineContent implementation that should be laid * out. */ - public void addLineContent(LineContent contentItem) throws TextException { + public void addLineContent(final LineContent contentItem) + throws TextException { if (eagerMode) { throw new TextException("Line-Breaking running in \"eager\" mode" + "can't switch to \"patient\"."); @@ -147,8 +149,9 @@ * its text (char []) to the first character that was <em>not</em> * successfully added to the line. */ - public int processLineContent(LineContent contentItem, int start, int end, - LineOutput output) throws TextException { + public int processLineContent(final LineContent contentItem, + final int start, final int end, final LineOutput output) + throws TextException { validateEagerContent(contentItem, output); content.add(contentItem); this.currentOutput = output; @@ -161,8 +164,8 @@ * @param output * @throws TextException */ - private void validateEagerContent(LineContent contentItem, - LineOutput output) throws TextException { + private void validateEagerContent(final LineContent contentItem, + final LineOutput output) throws TextException { if (patientMode) { throw new TextException("Line-Breaking running in \"patient\" mode" + "can't switch to \"eager\"."); @@ -179,9 +182,9 @@ protected abstract int addLineContent(LineContent contentItem, int start, int end, LineOutput output) throws TextException; - public int getCharWidth(LineText lineText, int codePoint) { - FontUse fontUse = lineText.inlinePrimaryFont(); - Font font = fontUse.getFont(); + public int getCharWidth(final LineText lineText, int codePoint) { + final FontUse fontUse = lineText.inlinePrimaryFont(); + final Font font = fontUse.getFont(); int fontSize = lineText.inlineFontSize(); if (lineText.inlineIsFauxSmallCaps() && isLowerCase(codePoint)) { @@ -193,11 +196,11 @@ + lineText.inlineLetterSpacingOptimum(); } - public boolean isLowerCase(int codePoint) { + public boolean isLowerCase(final int codePoint) { if (codePoint > Character.MAX_VALUE) { return false; } - char c = (char) codePoint; + final char c = (char) codePoint; if (java.lang.Character.isLetter(c) && java.lang.Character.isLowerCase(c)) { return true; @@ -205,8 +208,8 @@ return false; } - public int getHyphenWidth(LineText lineText) { - char hyphenChar = lineText.inlineHyphenationCharacter(); + public int getHyphenWidth(final LineText lineText) { + final char hyphenChar = lineText.inlineHyphenationCharacter(); return getCharWidth(lineText, hyphenChar); } @@ -215,7 +218,7 @@ * space with normal behaviour. Normal behaviour means that * it's not non-breaking */ - public static boolean isSpace(int codePoint) { + public static boolean isSpace(final int codePoint) { if (codePoint == ' ' || codePoint == '\u2000' // en quad || codePoint == '\u2001' // em quad @@ -238,7 +241,7 @@ * Method to determine if the character is a nonbreaking * space. */ - public static boolean isNonBreakingSpace(int codePoint) { + public static boolean isNonBreakingSpace(final int codePoint) { if (codePoint == '\u00A0' || codePoint == '\u202F' // narrow no-break space || codePoint == '\u3000' // ideographic space @@ -253,7 +256,7 @@ * @param codePoint The character to be tested. * @return True iff this character forces a line break. */ - public static boolean forcesLineBreak(int codePoint) { + public static boolean forcesLineBreak(final int codePoint) { if (codePoint == '\u2028' // Unicode line separator || codePoint == '\n') { // linefeed return true; @@ -266,7 +269,7 @@ * @param codePoint The character to be tested. * @return True iff this character allows (but does not force) a line break. */ - public static boolean allowsLineBreak(int codePoint) { + public static boolean allowsLineBreak(final int codePoint) { if (isWhitespace(codePoint)) { return true; } @@ -277,7 +280,7 @@ return false; } - public static boolean isWhitespace(int codePoint) { + public static boolean isWhitespace(final int codePoint) { if (isSpace(codePoint) || (codePoint == '\n') || (codePoint == '\r') @@ -288,7 +291,7 @@ return false; } - public static boolean isZeroWidthSpace(int codePoint) { + public static boolean isZeroWidthSpace(final int codePoint) { if ((codePoint == '\u200B') || codePoint == '\uFEFF') { return true; @@ -296,8 +299,8 @@ return false; } - protected int charWidth(LineText lineText, int codePoint, - int whitespaceWidth) { + protected int charWidth(final LineText lineText, final int codePoint, + final int whitespaceWidth) { if (isZeroWidthSpace(codePoint)) { return getCharWidth(lineText, codePoint); } @@ -329,11 +332,11 @@ * based on the current language property. * @return true if legal to break word in the middle */ - public static boolean canBreakMidWord(String language) { + public static boolean canBreakMidWord(final String language) { if (language == null) { return false; } - String lang = language.toLowerCase(); + final String lang = language.toLowerCase(); if (lang.equals("zh")) { // Chinese?? return true; } @@ -349,7 +352,7 @@ return false; } - public void setCurrentLine(LineOutput line) { + public void setCurrentLine(final LineOutput line) { this.currentOutput = line; } @@ -381,8 +384,8 @@ return; } // Make a new array. - int newSize = this.outputLines.length + 20; - LineOutput[] newArray = new LineOutput[newSize]; + final int newSize = this.outputLines.length + 20; + final LineOutput[] newArray = new LineOutput[newSize]; // Copy the old to the new. System.arraycopy(this.outputLines, 0, newArray, 0, this.outputLines.length); @@ -399,9 +402,9 @@ return this.server; } - public int getWordWidth(LineText lineText, CharSequence word) { - FontUse fontUse = lineText.inlinePrimaryFont(); - Font font = fontUse.getFont(); + public int getWordWidth(final LineText lineText, final CharSequence word) { + final FontUse fontUse = lineText.inlinePrimaryFont(); + final Font font = fontUse.getFont(); fontUse.registerCharsUsed(word); return font.width(word, lineText.inlineFontSize(), Modified: trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java =================================================================== --- trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-07-23 23:42:47 UTC (rev 7830) +++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2006-07-23 23:50:24 UTC (rev 7831) @@ -98,16 +98,17 @@ * Constructor. * @param control */ - public SolitaryLineBreaker(TextServer server, LineBreakControl control, - LineBreakHandler handler, FontConsumer fontConsumer) { + public SolitaryLineBreaker(final TextServer server, + final LineBreakControl control, + final LineBreakHandler handler, final FontConsumer fontConsumer) { super(server, control, handler, fontConsumer); } - protected int processLineText(LineText lineText, int start, int end) - throws TextException { + protected int processLineText(final LineText lineText, final int start, + final int end) throws TextException { this.currentLineText = lineText; this.currentChars = currentLineText.inlineText(); - String language = lineText.inlineLanguage(); + final String language = lineText.inlineLanguage(); finalWidth = 0; wordWidth = 0; @@ -118,7 +119,7 @@ } else { canEatLeadingSpaces = true; } - int whitespaceWidth = getCharWidth(lineText, ' '); + final int whitespaceWidth = getCharWidth(lineText, ' '); // Bound start and end by the limits of the array. int startIndex = start; @@ -133,9 +134,10 @@ /* iterate over each character */ for (int i = startIndex; i <= endIndex; i++) { /* get the character */ - char c = this.currentChars[i]; - int thisCharStarts = i; - int codePoint = StringUtilPre5.codePointAt(this.currentChars, i); + final char c = this.currentChars[i]; + final int thisCharStarts = i; + final int codePoint = StringUtilPre5.codePointAt(this.currentChars, + i); int charCount = 1; if (StringUtilPre5.isHighSurrogate(c)) { i++; @@ -152,7 +154,8 @@ // If it got this far, it is TEXT. canEatLeadingSpaces = false; - int charWidth = charWidth(lineText, codePoint, whitespaceWidth); + final int charWidth = charWidth(lineText, codePoint, + whitespaceWidth); processTextChar(language, thisCharStarts, charWidth); if ((finalWidth + spaceWidth + wordWidth) @@ -166,7 +169,7 @@ continue; } if (lineText.inlineHyphenate()) { - int ret = tryHyphenation(); + final int ret = tryHyphenation(); if (ret != wordStart) { finalWidth += spaceWidth; finalWidth += wordWidth; @@ -219,15 +222,16 @@ * it is one past endIndex, indicating that all has been laid out. * @throws TextException */ - private int remainingContentOnThisLine(int startIndex, int endIndex) - throws TextException { + private int remainingContentOnThisLine(final int startIndex, + final int endIndex) throws TextException { finalWidth += spaceWidth; finalWidth += wordWidth; createLineContent(startIndex, endIndex, finalWidth, false); return endIndex + 1; } - private int sizeFirstWordNextText(LineText lineText, int start, int end) { + private int sizeFirstWordNextText(final LineText lineText, final int start, + final int end) { int size = 0; LineText nextText = lineText; int whitespaceWidth = getCharWidth(nextText, ' '); @@ -235,7 +239,7 @@ * that faux small-caps breaks up the text item. */ char[] text = nextText.inlineText(); for (int i = end + 1; i < text.length; i++) { - char c = text[i]; + final char c = text[i]; if (forcesLineBreak(c) || allowsLineBreak(c)) { return size; } @@ -249,7 +253,7 @@ text = nextText.inlineText(); whitespaceWidth = getCharWidth(nextText, ' '); for (int i = 0; i < text.length; i++) { - char c = text[i]; + final char c = text[i]; if (forcesLineBreak(c) || allowsLineBreak(c)) { return size; } @@ -263,7 +267,8 @@ * @param i * @param charWidth */ - private void processTextChar(String language, int i, int charWidth) { + private void processTextChar(final String language, final int i, + final int charWidth) { if (previousCharacter == CONNECTOR) { // Current is TEXT, previous is WHITESPACE. wordWidth = charWidth; @@ -296,7 +301,8 @@ * @param lineText * @param codePoint */ - private void processLineBreakPossibility(LineText lineText, int codePoint) { + private void processLineBreakPossibility(final LineText lineText, + final int codePoint) { if (previousCharacter == TEXT) { // Current is WHITESPACE and previous TEXT. /* @@ -322,10 +328,12 @@ * considered part of this line. * @param sizeInline The size, in millipoints, of the content being created. */ - private void createLineContent(int startIndex, int endIndex, int sizeInline, - boolean isHyphenated) throws TextException { - LineText lineText = (LineText) this.currentLineContent; - boolean everythingWritten = endIndex >= lineText.inlineText().length; + private void createLineContent(final int startIndex, final int endIndex, + final int sizeInline, final boolean isHyphenated) + throws TextException { + final LineText lineText = (LineText) this.currentLineContent; + final boolean everythingWritten = endIndex >= + lineText.inlineText().length; boolean isLastItemOnLine = true; if (everythingWritten) { /* If everything was written, this may not be the last item on @@ -351,23 +359,25 @@ * backward at any text in the same LineText item, and then to prior * LineText items to find the beginning of the word. */ - HyphenationServer server = this.getTextServer().getHyphenationServer(); - String language = this.currentLineText.inlineLanguage(); - String country = this.currentLineText.inlineCountry(); + final HyphenationServer server = + this.getTextServer().getHyphenationServer(); + final String language = this.currentLineText.inlineLanguage(); + final String country = this.currentLineText.inlineCountry(); // Count the number of chars at the beginning that should be ignored. - int actualWordStart = server.wordStarts(this.currentChars, wordStart, - language, country); + final int actualWordStart = server.wordStarts(this.currentChars, + wordStart, language, country); if (actualWordStart < 0) { return this.wordStart; } - int nonWordChars = actualWordStart - wordStart; + final int nonWordChars = actualWordStart - wordStart; // Extract the word that should be evaluated by the hyphenation system. - int wordSize = server.wordSize(this.currentChars, actualWordStart, + final int wordSize = server.wordSize(this.currentChars, actualWordStart, language, country); - String wordToHyphenate = new String(this.currentChars, actualWordStart, + final String wordToHyphenate = new String(this.currentChars, + actualWordStart, wordSize); // See if there are discretionary hyphenation points. - Hyphenation hyph = server.hyphenate(wordToHyphenate, 0, + final Hyphenation hyph = server.hyphenate(wordToHyphenate, 0, wordToHyphenate.length(), language, country, this.currentLineText.inlineHyphenationRemainCount(), this.currentLineText.inlineHyphenationPushCount(), false); @@ -376,14 +386,14 @@ return this.wordStart; } // Select a hyphenation point. - int index = selectDiscretionaryHyphenationPoint(this.currentLineText, - wordToHyphenate, hyph); + final int index = selectDiscretionaryHyphenationPoint( + this.currentLineText, wordToHyphenate, hyph); // If none fit, then the word cannot be hyphenated. if (index < 0) { return wordStart; } // Compute the number of characters that should be included. - int charsToInclude = hyph.getPoints()[index]; + final int charsToInclude = hyph.getPoints()[index]; // Add it and the non-word characters to the count to be returned. return wordStart + nonWordChars + charsToInclude; } @@ -391,26 +401,26 @@ /** * extracts from a hyphenated word the best (most greedy) fit */ - private int selectDiscretionaryHyphenationPoint(LineText lineText, - String word, Hyphenation hyph) throws TextException { - int remainingWidth = this.currentLineWidthRemaining() - finalWidth + private int selectDiscretionaryHyphenationPoint(final LineText lineText, + final String word, final Hyphenation hyph) throws TextException { + final int remainingWidth = this.currentLineWidthRemaining() - finalWidth - spaceWidth - getHyphenWidth(this.currentLineText); - int[] hyphenationPoints = hyph.getPoints(); - byte[] hyphenationWeights = hyph.getWeights(); + final int[] hyphenationPoints = hyph.getPoints(); + final byte[] hyphenationWeights = hyph.getWeights(); int index = -1; String wordBegin = ""; for (int i = 0; i < hyphenationPoints.length; i++) { - byte hyphenationWeight = hyphenationWeights[i]; + final byte hyphenationWeight = hyphenationWeights[i]; if (hyphenationWeight < 1) { /* If the weight is zero or less, it is not a suitable * hyphenation point. */ continue; } wordBegin = word.substring(0, hyphenationPoints[i]); - int provisionalWordWidth = getWordWidth(lineText, wordBegin); + final int provisionalWordWidth = getWordWidth(lineText, wordBegin); if (provisionalWordWidth > remainingWidth) { break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |