[FOray-commit] SF.net SVN: foray: [10434] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2008-03-14 16:20:58
|
Revision: 10434
http://foray.svn.sourceforge.net/foray/?rev=10434&view=rev
Author: victormote
Date: 2008-03-14 09:20:40 -0700 (Fri, 14 Mar 2008)
Log Message:
-----------
Conform to axsl changes returning CharSequence instead of char[] for text items.
Modified Paths:
--------------
trunk/foray/foray-app/src/javatest/org/foray/app/area/AbstractAreaTreeTest.java
trunk/foray/foray-areatree/src/java/org/foray/area/LineArea.java
trunk/foray/foray-areatree/src/java/org/foray/area/TextArea.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/FOLineText.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/FObj.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/axsl/obj/Metadata.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/BookmarkTitle.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/Character.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/CharacterSequence4a.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumber.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitation.java
trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitationLast.java
trunk/foray/foray-pioneer/src/java/org/foray/pioneer/FOTextPL.java
trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java
trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java
Modified: trunk/foray/foray-app/src/javatest/org/foray/app/area/AbstractAreaTreeTest.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/area/AbstractAreaTreeTest.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/area/AbstractAreaTreeTest.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -122,7 +122,7 @@
final OrderedTreeNode otn = iterator.next();
if (otn instanceof TextArea) {
final TextArea textArea = (TextArea) otn;
- final char[] text = textArea.getRawText();
+ final CharSequence text = textArea.getRawText();
builder.append(text);
}
}
Modified: trunk/foray/foray-areatree/src/java/org/foray/area/LineArea.java
===================================================================
--- trunk/foray/foray-areatree/src/java/org/foray/area/LineArea.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-areatree/src/java/org/foray/area/LineArea.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -972,7 +972,7 @@
}
/* If the final text will be empty, don't create the TextArea. */
- final char[] rawText = foText.getAreaTreeText(context);
+ final CharSequence rawText = foText.getAreaTreeText(context);
final boolean isFirstItemOnline = parentArea.getChildren().size() == 0;
final int ignoreAtStart = TextArea.ignoreAtStart(rawText, startOffset,
sizeInChars, isFirstItemOnline,
Modified: trunk/foray/foray-areatree/src/java/org/foray/area/TextArea.java
===================================================================
--- trunk/foray/foray-areatree/src/java/org/foray/area/TextArea.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-areatree/src/java/org/foray/area/TextArea.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -277,7 +277,7 @@
* @return The text to be used in the output document.
*/
public char[] getText() {
- final char[] rawText = this.getTextContent().getAreaTreeText(this);
+ final CharSequence rawText = this.getTextContent().getAreaTreeText(this);
// Count of whitespace that should be ignored at start of array.
final int ignoreAtStart = ignoreAtStart(rawText, this.backingOffset,
this.backingSize, this.isFirstChildOfParent(),
@@ -297,9 +297,9 @@
discretionaryHyphenSize = Character.charCount(hyphenChar);
}
arraySize += discretionaryHyphenSize;
- final char[] returnChars = new char[arraySize];
- System.arraycopy(rawText, this.backingOffset + ignoreAtStart,
- returnChars, 0, returnChars.length);
+ final int start = this.backingOffset + ignoreAtStart;
+ final CharSequence returnSequence = rawText.subSequence(start, start + arraySize);
+ final char[] returnChars = returnSequence.toString().toCharArray();
if (this.hasDiscretionaryHyphen) {
if (discretionaryHyphenSize == 1) {
returnChars[returnChars.length - discretionaryHyphenSize]
@@ -341,12 +341,9 @@
* adjustments.
* @return The raw text from the FO Tree.
*/
- public char[] getRawText() {
- final char[] areaTreeText = this.getTextContent().getAreaTreeText(this);
- final char[] returnArray = new char[this.backingSize];
- System.arraycopy(areaTreeText, this.backingOffset, returnArray, 0,
- returnArray.length);
- return returnArray;
+ public CharSequence getRawText() {
+ final CharSequence foText = this.getTextContent().getAreaTreeText(this);
+ return foText.subSequence(this.backingOffset, this.backingOffset + this.backingSize);
}
/**
@@ -432,7 +429,7 @@
* @param whiteSpaceTreatment The white-space treatment value.
* @return The number of characters that should be ignored.
*/
- public static int ignoreAtStart(final char[] chars, final int start,
+ public static int ignoreAtStart(final CharSequence chars, final int start,
final int size, final boolean firstItemOnLine,
final WhiteSpaceTreatment whiteSpaceTreatment) {
// Only eat leading whitespaces if this is the first item on the line.
@@ -455,7 +452,7 @@
*/
int count = 0;
for (int i = start; i < start + size; i++) {
- final char c = chars[i];
+ final char c = chars.charAt(i);
if (! XMLCharacter.isXMLWhitespace(c)
|| c == WKConstants.LINEFEED) {
return count;
@@ -476,7 +473,7 @@
* @param whiteSpaceTreatment The white-space treatment value.
* @return The number of characters that should be ignored.
*/
- public static int ignoreAtEnd(final char[] chars, final int start,
+ public static int ignoreAtEnd(final CharSequence chars, final int start,
final int size, final boolean lastItemOnLine,
final WhiteSpaceTreatment whiteSpaceTreatment) {
// Only eat trailing whitespaces if this is the last item on the line.
@@ -499,7 +496,7 @@
*/
int count = 0;
for (int i = start + size - 1; i >= start; i--) {
- final char c = chars[i];
+ final char c = chars.charAt(i);
if (! XMLCharacter.isXMLWhitespace(c)
|| c == WKConstants.LINEFEED) {
return count;
@@ -619,15 +616,15 @@
* @return True iff this text-area ends with a linefeed.
*/
public boolean endsWithLinefeed() {
- final char[] rawText = this.getTextContent().getAreaTreeText(this);
+ final CharSequence rawText = this.getTextContent().getAreaTreeText(this);
if (rawText == null) {
return false;
}
- if (rawText.length < 1) {
+ if (rawText.length() < 1) {
return false;
}
- final int lastCharIndex = rawText.length - 1;
- if (rawText[lastCharIndex] == WKConstants.LINEFEED) {
+ final int lastCharIndex = rawText.length() - 1;
+ if (rawText.charAt(lastCharIndex) == WKConstants.LINEFEED) {
return true;
}
return false;
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/FOLineText.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/FOLineText.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FOLineText.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -61,14 +61,14 @@
/**
* {@inheritDoc}
*/
- public char[] inlineText() {
+ public CharSequence inlineText() {
return this.realLineText.inlineText(this.context);
}
/**
* {@inheritDoc}
*/
- public char[] inlineText(final FoContext context) {
+ public CharSequence inlineText(final FoContext context) {
return this.realLineText.inlineText(context);
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/FObj.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/FObj.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/FObj.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -29,6 +29,7 @@
package org.foray.fotree;
import org.foray.common.AbstractOrderedTreeNode;
+import org.foray.common.CharVector;
import org.foray.common.FontUtil;
import org.foray.common.OrderedTreeNode;
import org.foray.common.UnicodeChar;
@@ -415,10 +416,10 @@
protected static final List<FObj> EMPTY_CHILD_LIST =
Collections.emptyList();
- /** Static array containing one space, to be used for obtaining a font
+ /** Static CharSequence containing one space, to be used for obtaining a font
* for the page-citation-* objects. */
- protected static final char[] PAGE_CITATION_TEXT_SEGMENT =
- new char[] { ' ' };
+ protected static final CharSequence PAGE_CITATION_TEXT_SEGMENT = new CharVector(
+ new char[] { ' ' });
/** The path to the document from which this object was parsed, if any. */
private String systemId;
@@ -4007,7 +4008,7 @@
final FoContext context) {
org.axsl.font.FontUse resolvedFont = null;
try {
- final char[] firstTextSegment = this.firstTextSegment();
+ final CharSequence firstTextSegment = this.firstTextSegment();
int firstChar = UnicodeChar.firstPrintable(firstTextSegment);
if (firstChar == WKConstants.INVALID_UNICODE_CHARACTER) {
/* There are no printable characters in the first text segment,
@@ -4121,7 +4122,7 @@
* Returns the underlying text of the first descendant text item.
* @return The underlying text of the first descendant text item.
*/
- public char[] firstTextSegment() {
+ public CharSequence firstTextSegment() {
final LineText firstLineText = firstLineText();
if (firstLineText == null) {
return null;
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/axsl/obj/Metadata.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/axsl/obj/Metadata.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/axsl/obj/Metadata.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -175,7 +175,7 @@
/* Existence and casting verified at validateDescendants(). */
final CharacterSequence4a text =
(CharacterSequence4a) this.getChildAt(0);
- return new String(text.getAreaTreeText(null));
+ return text.getAreaTreeText(null).toString();
}
/**
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/BookmarkTitle.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/BookmarkTitle.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/BookmarkTitle.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -246,8 +246,8 @@
return WKConstants.EMPTY_STRING;
}
final CharacterSequence4a child = this.getChildAt(0);
- final char[] text = child.getAreaTreeText(null);
- return new String(text);
+ final CharSequence text = child.getAreaTreeText(null);
+ return text.toString();
}
/**
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/Character.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/Character.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/Character.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -139,7 +139,7 @@
/**
* {@inheritDoc}
*/
- public char[] getAreaTreeText(final FoContext context) {
+ public CharSequence getAreaTreeText(final FoContext context) {
final CharacterSequence4a text =
(CharacterSequence4a) this.getChildren().get(0);
return text.getAreaTreeText(context);
@@ -198,14 +198,14 @@
/**
* {@inheritDoc}
*/
- public char[] inlineText() {
+ public CharSequence inlineText() {
return this.inlineText(null);
}
/**
* {@inheritDoc}
*/
- public char[] inlineText(final FoContext context) {
+ public CharSequence inlineText(final FoContext context) {
return getAreaTreeText(context);
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/CharacterSequence4a.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/CharacterSequence4a.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/CharacterSequence4a.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -28,6 +28,7 @@
package org.foray.fotree.fo.obj;
+import org.foray.common.CharVector;
import org.foray.common.WKConstants;
import org.foray.common.XMLCharacter;
import org.foray.fotree.FObj;
@@ -93,7 +94,7 @@
private FObj parent;
/** The raw text content. */
- private char[] ca;
+ private CharVector ca;
/** The current status of the filtering of this text item. */
private byte filterStatus = CharacterSequence4a.FILTER_RAW;
@@ -119,7 +120,7 @@
public CharacterSequence4a(final FObj parent, final char[] chars) {
super(parent);
this.parent = parent;
- this.ca = chars;
+ this.ca = new CharVector(chars);
filterContent();
}
@@ -170,8 +171,8 @@
* @return True iff all of the text in this item is whitespace.
*/
public boolean isAllWhiteSpace() {
- for (int i = 0; i < this.ca.length; i++) {
- final char ch = this.ca[i];
+ for (int i = 0; i < this.ca.length(); i++) {
+ final char ch = this.ca.charAt(i);
if ((ch == ' ')
|| (ch == '\n')
|| (ch == '\r')
@@ -198,7 +199,7 @@
*
* @return The text that should appear in the refined FO tree.
*/
- public char[] getRefinedText(final FoContext context) {
+ public CharVector getRefinedText(final FoContext context) {
/* TODO: This needs to come from effectiveParent, with context. */
final FObj effectiveParent = this.getParent();
if (this.filterStatus >= CharacterSequence4a.FILTER_REFINED_FO_TREE) {
@@ -206,14 +207,14 @@
return this.ca;
}
- final char[] charArray = getPreTextTransformText(context);
+ final CharVector charArray = getPreTextTransformText(context);
// Now handle text-transform.
final TextTransform textTransform = effectiveParent.traitTextTransform(
context);
if (textTransform != TextTransform.NONE) {
- for (int i = 0; i < charArray.length; i++) {
- charArray[i] = applyTextTransform(context, charArray, i,
- textTransform);
+ for (int i = 0; i < charArray.length(); i++) {
+ charArray.put(i, applyTextTransform(context, charArray, i,
+ textTransform));
}
}
@@ -242,7 +243,7 @@
* @return The text that should appear in the refined FO tree, except that
* text-transform is not applied.
*/
- private char[] getPreTextTransformText(final FoContext context) {
+ private CharVector getPreTextTransformText(final FoContext context) {
final FObj effectiveParent = this.effectiveParent(context);
if (this.filterStatus >= CharacterSequence4a.FILTER_PRE_TRANSFORM) {
/* The stored text has already been filtered. Just return it. */
@@ -250,7 +251,7 @@
}
/* Must handle white-space-treatment first. */
- char[] workArray = applyWhiteSpaceTreatment(this.ca,
+ CharVector workArray = applyWhiteSpaceTreatment(this.ca,
effectiveParent.traitWhiteSpaceTreatment(context));
// Now handle linefeed-treatment.
@@ -275,9 +276,9 @@
* @return The transformed char.
*/
private char applyTextTransform(final FoContext context,
- final char[] charArray, final int index,
+ final CharSequence charArray, final int index,
final TextTransform textTransform) {
- final char c = charArray[index];
+ final char c = charArray.charAt(index);
switch (textTransform) {
/* This method not be entered if value is NONE. */
case UPPERCASE:
@@ -305,7 +306,7 @@
*/
return c;
}
- return charArray[index];
+ return charArray.charAt(index);
}
/**
@@ -326,7 +327,7 @@
* word.
*/
private boolean isStartOfWord(final FoContext context,
- final char[] charArray, final int index) {
+ final CharSequence charArray, final int index) {
final char prevChar = getRelativeCharInBlock(context, charArray,
index, -1);
/* All we are really concerned about here is of what type prevChar
@@ -464,26 +465,26 @@
* the offset points to an area outside of the block.
*/
private char getRelativeCharInBlock(final FoContext context,
- final char[] charArray, final int index, final int offset) {
+ final CharSequence charArray, final int index, final int offset) {
// The easy case is where the desired character is in the same FOText
final int desiredIndex = index + offset;
- if (desiredIndex >= 0 && desiredIndex < charArray.length) {
- return this.ca[desiredIndex];
+ if (desiredIndex >= 0 && desiredIndex < charArray.length()) {
+ return this.ca.charAt(desiredIndex);
}
int remainingOffset = 0;
if (offset > 0) {
// Look in subsequent text items.
- remainingOffset = offset - (charArray.length - 1 - index);
+ remainingOffset = offset - (charArray.length() - 1 - index);
CharacterSequence4a nextFOText =
this.getNextContiguousTextInBlock();
while (nextFOText != null) {
- final char[] nextText =
+ final CharVector nextText =
nextFOText.getPreTextTransformText(context);
- if (nextText.length >= remainingOffset) {
- return nextText[remainingOffset - 1];
+ if (nextText.length() >= remainingOffset) {
+ return nextText.charAt(remainingOffset - 1);
}
- remainingOffset -= nextText.length;
+ remainingOffset -= nextText.length();
nextFOText = nextFOText.getNextContiguousTextInBlock();
}
return 0x0000;
@@ -493,11 +494,11 @@
CharacterSequence4a prevFOText =
this.getPreviousContiguousTextInBlock();
while (prevFOText != null) {
- final char[] prevText = prevFOText.getPreTextTransformText(context);
- if (prevText.length >= Math.abs(remainingOffset)) {
- return prevText[prevText.length + remainingOffset];
+ final CharVector prevText = prevFOText.getPreTextTransformText(context);
+ if (prevText.length() >= Math.abs(remainingOffset)) {
+ return prevText.charAt(prevText.length() + remainingOffset);
}
- remainingOffset += prevText.length;
+ remainingOffset += prevText.length();
prevFOText = prevFOText.getPreviousContiguousTextInBlock();
}
return 0x0000;
@@ -517,7 +518,7 @@
* issues.
* @return The text that should appear in the area tree.
*/
- public char[] getAreaTreeText(final FoContext context) {
+ public CharSequence getAreaTreeText(final FoContext context) {
final FObj effectiveParent = this.getParent();
if (this.filterStatus >= CharacterSequence4a.FILTER_AREA_TREE) {
/* The stored text has already been filtered. Just return it. */
@@ -525,7 +526,7 @@
}
// Start with the refined FO Tree text
- char[] returnArray = getRefinedText(context);
+ CharVector returnArray = getRefinedText(context);
// Apply white-space-collapse.
final boolean whiteSpaceCollapse =
effectiveParent.traitWhiteSpaceCollapse(context);
@@ -541,14 +542,14 @@
/**
* {@inheritDoc}
*/
- public char[] inlineText() {
+ public CharSequence inlineText() {
return this.inlineText(null);
}
/**
* {@inheritDoc}
*/
- public char[] inlineText(final FoContext context) {
+ public CharSequence inlineText(final FoContext context) {
return getAreaTreeText(context);
}
@@ -808,9 +809,9 @@
* Note that {@link #DISCARD_CHAR} is not a valid Unicode codepoint, and
* should therefore never be in the input.
*/
- public static char applyWhiteSpaceTreatment(final char[] charArray,
+ public static char applyWhiteSpaceTreatment(final CharSequence charArray,
final int index, final WhiteSpaceTreatment whiteSpaceTreatment) {
- final char c = charArray[index];
+ final char c = charArray.charAt(index);
if (! XMLCharacter.isXMLWhitespace(c)) {
/* If it is not whitespace, it cannot be changed. */
return c;
@@ -828,10 +829,10 @@
}
case IGNORE_IF_BEFORE_LINEFEED: {
// If last element, no change needed.
- if (index == charArray.length - 1) {
+ if (index == charArray.length() - 1) {
return c;
}
- if (charArray[index + 1] != WKConstants.LINEFEED) {
+ if (charArray.charAt(index + 1) != WKConstants.LINEFEED) {
return c;
}
return CharacterSequence4a.DISCARD_CHAR;
@@ -841,7 +842,7 @@
if (index == 0) {
return c;
}
- if (charArray[index - 1] != WKConstants.LINEFEED) {
+ if (charArray.charAt(index - 1) != WKConstants.LINEFEED) {
return c;
}
return CharacterSequence4a.DISCARD_CHAR;
@@ -853,22 +854,22 @@
default: {
// If first element, only check next.
if (index == 0) {
- if (index < charArray.length - 1
- && charArray[index + 1] == WKConstants.LINEFEED) {
+ if (index < charArray.length() - 1
+ && charArray.charAt(index + 1) == WKConstants.LINEFEED) {
return CharacterSequence4a.DISCARD_CHAR;
}
return c;
}
// If last element, only check previous
- if (index >= charArray.length - 1) {
- if (charArray[index - 1] == WKConstants.LINEFEED) {
+ if (index >= charArray.length() - 1) {
+ if (charArray.charAt(index - 1) == WKConstants.LINEFEED) {
return CharacterSequence4a.DISCARD_CHAR;
}
return c;
}
// Otherwise, check both
- if (charArray[index - 1] == WKConstants.LINEFEED
- || charArray[index + 1] == WKConstants.LINEFEED) {
+ if (charArray.charAt(index - 1) == WKConstants.LINEFEED
+ || charArray.charAt(index + 1) == WKConstants.LINEFEED) {
return CharacterSequence4a.DISCARD_CHAR;
}
return c;
@@ -890,7 +891,7 @@
* white-space-treatment, <code>charArray</code> is returned.
* Otherwise, a new char array with the result is returned.
*/
- public static char[] applyWhiteSpaceTreatment(final char[] charArray,
+ public static CharVector applyWhiteSpaceTreatment(final CharVector charArray,
final WhiteSpaceTreatment inputWhiteSpaceTreatment) {
WhiteSpaceTreatment whiteSpaceTreatment = inputWhiteSpaceTreatment;
switch (whiteSpaceTreatment) {
@@ -912,8 +913,8 @@
int discardElements = 0;
int changeElements = 0;
- for (int i = 0; i < charArray.length; i++) {
- final char c = charArray[i];
+ for (int i = 0; i < charArray.length(); i++) {
+ final char c = charArray.charAt(i);
final char conversionChar = applyWhiteSpaceTreatment(charArray, i,
whiteSpaceTreatment);
if (conversionChar == CharacterSequence4a.DISCARD_CHAR) {
@@ -929,10 +930,10 @@
/* We now know that changes of some sort must be made. Create a new
* array in which to put the results. */
- final char[] returnArray = new char[charArray.length - discardElements];
+ final char[] returnArray = new char[charArray.length() - discardElements];
discardElements = 0;
- for (int i = 0; i < charArray.length; i++) {
+ for (int i = 0; i < charArray.length(); i++) {
final char conversionChar = applyWhiteSpaceTreatment(charArray,
i, whiteSpaceTreatment);
if (conversionChar == CharacterSequence4a.DISCARD_CHAR) {
@@ -941,7 +942,7 @@
returnArray[i - discardElements] = conversionChar;
}
}
- return returnArray;
+ return new CharVector(returnArray);
}
/**
@@ -987,7 +988,7 @@
* <code>charArray</code> is returned. Otherwise, a new char array with the
* result is returned.
*/
- public static char[] applyLinefeedTreatment(final char[] charArray,
+ public static CharVector applyLinefeedTreatment(final CharVector charArray,
final LinefeedTreatment inputLinefeedTreatment) {
LinefeedTreatment linefeedTreatment = inputLinefeedTreatment;
switch (linefeedTreatment) {
@@ -1009,8 +1010,8 @@
int discardElements = 0;
int changeElements = 0;
- for (int i = 0; i < charArray.length; i++) {
- final char c = charArray[i];
+ for (int i = 0; i < charArray.length(); i++) {
+ final char c = charArray.charAt(i);
if (c == WKConstants.LINEFEED) {
if (linefeedTreatment == LinefeedTreatment.IGNORE) {
discardElements ++;
@@ -1026,10 +1027,10 @@
/* We now know that changes of some sort must be made. Create a new
* array in which to put the results. */
- final char[] returnArray = new char[charArray.length - discardElements];
+ final char[] returnArray = new char[charArray.length() - discardElements];
discardElements = 0;
- for (int i = 0; i < charArray.length; i++) {
- final char c = charArray[i];
+ for (int i = 0; i < charArray.length(); i++) {
+ final char c = charArray.charAt(i);
if (c == WKConstants.LINEFEED) {
final char conversionChar = applyLinefeedTreatment(c,
linefeedTreatment);
@@ -1042,7 +1043,7 @@
returnArray[i - discardElements] = c;
}
}
- return returnArray;
+ return new CharVector(returnArray);
}
/**
@@ -1057,9 +1058,9 @@
* if the next character is a line-feed.
* If neither of these is true, returns the original character.
*/
- public static char applyWhiteSpaceCollapse(final char[] charArray,
+ public static char applyWhiteSpaceCollapse(final CharSequence charArray,
final int index) {
- final char c = charArray[index];
+ final char c = charArray.charAt(index);
if (! XMLCharacter.isXMLWhitespace(c)) {
/* If it is not whitespace, nothing should change. */
return c;
@@ -1069,11 +1070,11 @@
return c;
}
if (index != 0 && XMLCharacter.isXMLWhitespace(
- charArray[index - 1])) {
+ charArray.charAt(index - 1))) {
return CharacterSequence4a.DISCARD_CHAR;
}
- if (index < charArray.length - 1
- && charArray[index + 1] == WKConstants.LINEFEED) {
+ if (index < charArray.length() - 1
+ && charArray.charAt(index + 1) == WKConstants.LINEFEED) {
return CharacterSequence4a.DISCARD_CHAR;
}
return c;
@@ -1091,14 +1092,14 @@
* white-space-collapse, <code>charArray</code> is returned.
* Otherwise, a new char array with the result is returned.
*/
- public static char[] applyWhiteSpaceCollapse(final char[] charArray,
+ public static CharVector applyWhiteSpaceCollapse(final CharVector charArray,
final boolean whiteSpaceCollapse) {
if (! whiteSpaceCollapse) {
return charArray;
}
int discardElements = 0;
- for (int i = 0; i < charArray.length; i++) {
+ for (int i = 0; i < charArray.length(); i++) {
final char convertChar = applyWhiteSpaceCollapse(charArray, i);
if (convertChar == CharacterSequence4a.DISCARD_CHAR) {
discardElements ++;
@@ -1111,9 +1112,9 @@
/* We now know that changes of some sort must be made. Create a new
* array in which to put the results. */
- final char[] returnArray = new char[charArray.length - discardElements];
+ final char[] returnArray = new char[charArray.length() - discardElements];
discardElements = 0;
- for (int i = 0; i < charArray.length; i++) {
+ for (int i = 0; i < charArray.length(); i++) {
final char conversionChar = applyWhiteSpaceCollapse(charArray, i);
if (conversionChar == CharacterSequence4a.DISCARD_CHAR) {
discardElements ++;
@@ -1121,7 +1122,7 @@
returnArray[i - discardElements] = conversionChar;
}
}
- return returnArray;
+ return new CharVector(returnArray);
}
/**
@@ -1182,7 +1183,7 @@
* Returns the raw char array.
* @return The raw char array.
*/
- public char[] getRawText() {
+ public CharVector getRawText() {
return this.ca;
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumber.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumber.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumber.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -83,7 +83,7 @@
* Overrides the superclass because this class has no children but
* encapsulates its underlying text.
*/
- public char[] firstTextSegment() {
+ public CharSequence firstTextSegment() {
return PAGE_CITATION_TEXT_SEGMENT;
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitation.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitation.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitation.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -85,7 +85,7 @@
* Overrides the superclass because this class has no children but
* encapsulates its underlying text.
*/
- public char[] firstTextSegment() {
+ public CharSequence firstTextSegment() {
return PAGE_CITATION_TEXT_SEGMENT;
}
Modified: trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitationLast.java
===================================================================
--- trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitationLast.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-fotree/src/java/org/foray/fotree/fo/obj/PageNumberCitationLast.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -85,7 +85,7 @@
* Overrides the superclass because this class has no children but
* encapsulates its underlying text.
*/
- public char[] firstTextSegment() {
+ public CharSequence firstTextSegment() {
return PAGE_CITATION_TEXT_SEGMENT;
}
Modified: trunk/foray/foray-pioneer/src/java/org/foray/pioneer/FOTextPL.java
===================================================================
--- trunk/foray/foray-pioneer/src/java/org/foray/pioneer/FOTextPL.java 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-pioneer/src/java/org/foray/pioneer/FOTextPL.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -90,7 +90,7 @@
private int addText(final FoLineText lineText, final AreaNode areaNode,
final int start, final GraftingPoint graftingPoint)
throws AreaTreeException {
- final int end = lineText.inlineText().length;
+ final int end = lineText.inlineText().length();
final LineArea la = this.activeLineArea(areaNode);
if (la == null) {
return start;
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 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-text/src/java/org/foray/text/line/EagerLineBreaker.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -83,17 +83,17 @@
int status = 0;
if (lineContent instanceof LineText) {
final LineText lineText = (LineText) lineContent;
- final char[] text = lineText.inlineText();
- if (text.length < 1) {
+ final CharSequence text = lineText.inlineText();
+ if (text.length() < 1) {
return -1;
}
if (lineText.inlineIsFauxSmallCaps()) {
/* If this is small caps, break the text up into pieces,
* starting a new piece when the case of the text changes. */
int subsetStart = start;
- this.setInLowerCase(isLowerCase(text[start]));
+ this.setInLowerCase(isLowerCase(text.charAt(start)));
for (int i = start; i < end; i++) {
- final char c = text[i];
+ final char c = text.charAt(i);
boolean shouldSwitch = false;
if (isLowerCase(c)
&& ! isInLowerCase()) {
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 2008-03-13 23:03:38 UTC (rev 10433)
+++ trunk/foray/foray-text/src/java/org/foray/text/line/solitary/SolitaryLineBreaker.java 2008-03-14 16:20:40 UTC (rev 10434)
@@ -28,6 +28,7 @@
package org.foray.text.line.solitary;
+import org.foray.common.WKConstants;
import org.foray.text.TextServer;
import org.foray.text.line.EagerLineBreaker;
@@ -87,7 +88,7 @@
/** The current characters from {@link #currentLineText}, available here
* merely as a convenience. */
- private char[] currentChars = null;
+ private CharSequence currentChars = null;
/** Indicates whether leading spaces can be ignored. */
private boolean canEatLeadingSpaces = true;
@@ -137,14 +138,14 @@
if (start < 0) {
startIndex = 0;
}
- if (end > this.currentChars.length - 1) {
- endIndex = this.currentChars.length - 1;
+ if (end > this.currentChars.length() - 1) {
+ endIndex = this.currentChars.length() - 1;
}
/* iterate over each character */
for (int i = startIndex; i <= endIndex; i++) {
/* get the character */
- final char c = this.currentChars[i];
+ final char c = this.currentChars.charAt(i);
final int thisCharStarts = i;
final int codePoint = Character.codePointAt(this.currentChars,
i);
@@ -260,9 +261,9 @@
int whitespaceWidth = getCharWidth(nextText, ' ');
/* First see if there is additional text in the current item. Remember
* that faux small-caps breaks up the text item. */
- char[] text = nextText.inlineText();
- for (int i = end + 1; i < text.length; i++) {
- final char c = text[i];
+ CharSequence text = nextText.inlineText();
+ for (int i = end + 1; i < text.length(); i++) {
+ final char c = text.charAt(i);
if (forcesLineBreak(c) || allowsLineBreak(c)) {
return size;
}
@@ -275,8 +276,8 @@
}
text = nextText.inlineText();
whitespaceWidth = getCharWidth(nextText, ' ');
- for (int i = 0; i < text.length; i++) {
- final char c = text[i];
+ for (int i = 0; i < text.length(); i++) {
+ final char c = text.charAt(i);
if (forcesLineBreak(c) || allowsLineBreak(c)) {
return size;
}
@@ -365,7 +366,7 @@
throws TextException {
final LineText lineText = (LineText) this.getLineContent();
final boolean everythingWritten = endIndex >=
- lineText.inlineText().length;
+ lineText.inlineText().length();
boolean isLastItemOnLine = true;
if (everythingWritten) {
/* If everything was written, this may not be the last item on
@@ -409,14 +410,11 @@
// Extract the word that should be evaluated by the hyphenation system.
final int wordSize = server.wordSize(this.currentChars, actualWordStart,
language, country);
- final String wordToHyphenate = new String(this.currentChars,
- actualWordStart,
- wordSize);
// See if there are discretionary hyphenation points.
Hyphenation hyph = null;
try {
- hyph = server.hyphenate(wordToHyphenate, 0,
- wordToHyphenate.length(), language, country,
+ hyph = server.hyphenate(this.currentChars, actualWordStart,
+ wordSize, language, country,
this.currentLineText.inlineHyphenationRemainCount(),
this.currentLineText.inlineHyphenationPushCount(), false);
} catch (final HyphenationException e) {
@@ -428,6 +426,8 @@
return this.wordStart;
}
// Select a hyphenation point.
+ final CharSequence wordToHyphenate = this.currentChars.subSequence(actualWordStart,
+ actualWordStart + wordSize);
final int index = selectDiscretionaryHyphenationPoint(
this.currentLineText, wordToHyphenate, hyph);
// If none fit, then the word cannot be hyphenated.
@@ -452,7 +452,7 @@
* @throws TextException For errors during break selection.
*/
private int selectDiscretionaryHyphenationPoint(final LineText lineText,
- final String word, final Hyphenation hyph) throws TextException {
+ final CharSequence word, final Hyphenation hyph) throws TextException {
final int remainingWidth
= this.lineReceivingContent().capacityRemaining()
- this.finalWidth
@@ -462,7 +462,7 @@
final byte[] hyphenationWeights = hyph.getWeights();
int index = -1;
- String wordBegin = "";
+ CharSequence wordBegin = WKConstants.EMPTY_STRING;
for (int i = 0; i < hyphenationPoints.length; i++) {
final byte hyphenationWeight = hyphenationWeights[i];
@@ -471,7 +471,7 @@
* hyphenation point. */
continue;
}
- wordBegin = word.substring(0, hyphenationPoints[i]);
+ wordBegin = word.subSequence(0, hyphenationPoints[i]);
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.
|