* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
- *
+ *
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
- *
+ *
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
- */
+ */
package org.apache.fop.fo;
// Java
import org.apache.fop.layoutmgr.TextLayoutManager;
import org.apache.fop.apps.StructureHandler;
import org.apache.fop.fo.properties.WhiteSpaceCollapse;
+import org.apache.fop.fo.flow.Block;
+import org.apache.fop.fo.pagination.Root;
+import org.apache.fop.fo.properties.TextTransform;
/**
* A text node in the formatting object tree.
*
- * Modified by Mark Lillywhite, mark-fop@inomial.com.
* Unfortunately the BufferManager implementatation holds
* onto references to the character data in this object
* longer than the lifetime of the object itself, causing
* excessive memory consumption and OOM errors.
+ *
+ * @author unascribed
+ * @author <a href="mailto:mark-fop@inomial.com">Mark Lillywhite</a>
*/
public class FOText extends FObj {
TextInfo textInfo;
TextState ts;
- public FOText(char[] chars, int s, int e, TextInfo ti) {
- super(null);
+ /**
+ * Keeps track of the last FOText object created within the current
+ * block. This is used to create pointers between such objects.
+ */
+ private static FOText lastFOTextProcessed = null;
+
+ /**
+ * Points to the previous FOText object created within the current
+ * block. If this is "null", this is the first such object.
+ */
+ private FOText prevFOTextThisBlock = null;
+
+ /**
+ * Points to the next FOText object created within the current
+ * block. If this is "null", this is the last such object.
+ */
+ private FOText nextFOTextThisBlock = null;
+
+ /**
+ * Points to the ancestor Block object. This is used to keep track of
+ * which FOText nodes are descendants of the same block.
+ */
+ private Block ancestorBlock = null;
+
+ public static final int IS_WORD_CHAR_FALSE = 0;
+ public static final int IS_WORD_CHAR_TRUE = 1;
+ public static final int IS_WORD_CHAR_MAYBE = 2;
+
+ public FOText(char[] chars, int s, int e, TextInfo ti, FONode parent) {
+ super(parent);
this.start = 0;
this.ca = new char[e - s];
System.arraycopy(chars, s, ca, 0, e - s);
this.length = e - s;
textInfo = ti;
+ createBlockPointers();
+ textTransform();
}
public void setStructHandler(StructureHandler st) {
for (int i = start; i < start + length; i++) {
char ch = ca[i];
- if (!((ch == ' ')
- || (ch == '\n')
+ if (!((ch == ' ')
+ || (ch == '\n')
|| (ch == '\r')
|| (ch == '\t'))) { // whitespace
return true;
private class TextCharIterator extends AbstractCharIterator {
private int curIndex = 0;
-
+
public boolean hasNext() {
return (curIndex < length);
}
}
-}
+ /**
+ * This method is run as part of the Constructor, to create xref pointers to
+ * the previous FOText objects within the same Block
+ */
+ private void createBlockPointers() {
+ // build pointers between the FOText objects withing the same Block
+ //
+ // find the ancestorBlock of the current node
+ FONode ancestorFONode = this;
+ while (this.ancestorBlock == null) {
+ ancestorFONode = ancestorFONode.parent;
+ Class myclass = ancestorFONode.getClass();
+ if (ancestorFONode instanceof Root) {
+ getLogger().warn("Unexpected: fo:text with no fo:block ancestor");
+ }
+ if (ancestorFONode instanceof Block) {
+ this.ancestorBlock = (Block)ancestorFONode;
+ }
+ }
+ // if the last FOText is a sibling, point to it, and have it point here
+ if ( lastFOTextProcessed != null) {
+ if (lastFOTextProcessed.ancestorBlock == this.ancestorBlock) {
+ prevFOTextThisBlock = lastFOTextProcessed;
+ prevFOTextThisBlock.nextFOTextThisBlock = this;
+ }
+ else {
+ prevFOTextThisBlock = null;
+ }
+ }
+ // save the current node in static field so the next guy knows where
+ // to look
+ lastFOTextProcessed = this;
+ return;
+ }
+
+ /**
+ * This method is run as part of the Constructor, to handle the
+ * text-transform property.
+ */
+ private void textTransform() {
+ for (int i = 0; i < ca.length; i++) {
+ ca[i] = charTransform(i);
+ }
+ }
+
+ /**
+ * Determines whether a particular location in an FOText object's text is
+ * the start of a new "word". The use of "word" here is specifically for
+ * the text-transform property, but may be useful for other things as
+ * well, such as word-spacing. The definition of "word" is somewhat ambiguous
+ * and appears to be definable by the user agent.
+ *
+ * @param (int i) with index to ca[]
+ *
+ * @return True if the character at this location is the start of a new
+ * word.
+ */
+ public boolean isStartOfWord (int i) {
+ char prevChar = getRelativeCharInBlock(i, -1);
+ /* All we are really concerned about here is of what type prevChar
+ is. If inputChar is not part of a word, then the Java
+ conversions will (we hope) simply return inputChar.
+ */
+ switch (isWordChar(prevChar)) {
+ case IS_WORD_CHAR_TRUE:
+ return false;
+ case IS_WORD_CHAR_FALSE:
+ return true;
+ /* "MAYBE" implies that additional context is needed. An example is a
+ * single-quote, either straight or closing, which might be interpreted
+ * as a possessive or a contraction, or might be a closing quote.
+ */
+ case IS_WORD_CHAR_MAYBE:
+ char prevPrevChar = getRelativeCharInBlock(i, -2);
+ switch (isWordChar(prevPrevChar)) {
+ case IS_WORD_CHAR_TRUE:
+ return false;
+ case IS_WORD_CHAR_FALSE:
+ return true;
+ case IS_WORD_CHAR_MAYBE:
+ return true;
+ default:
+ return false;
+ }
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * Finds a character within the current Block that is relative in location
+ * to a character in the current FOText. Treats all FOText objects within a
+ * block as one unit, allowing text in adjoining FOText objects to be
+ * returned if the parameters are outside of the current object.
+ *
+ * @param (int i) with the index for ca[]
+ * @param (int offset) signed integer with relative position within the
+ * block of the character to return. To return the character immediately
+ * preceding i, pass -1. To return the character immediately after i,
+ * pass 1.
+ * @return char the character in the offset position within the block.
+ * @return \u0000 if the offset points to an area outside of the block.
+ */
+ public char getRelativeCharInBlock(int i, int offset) {
+ // The easy case is where the desired character is in the same FOText
+ if (((i + offset) >= 0) && ((i + offset) <= this.length)) {
+ return ca[i + offset];
+ }
+ // For now, we can't look at following FOText nodes
+ if (offset > 0) {
+ return '\u0000';
+ }
+ // Remaining case has the text in some previous FOText node
+ boolean foundChar = false;
+ char charToReturn = '\u0000';
+ FOText nodeToTest = this;
+ int remainingOffset = offset + i;
+ while (! foundChar) {
+ if (nodeToTest.prevFOTextThisBlock == null) {
+ foundChar = true;
+ break;
+ }
+ nodeToTest = nodeToTest.prevFOTextThisBlock;
+ if ((nodeToTest.ca.length + remainingOffset) >= 0) {
+ charToReturn = nodeToTest.ca[nodeToTest.ca.length + remainingOffset];
+ foundChar = true;
+ }
+ else {
+ remainingOffset = remainingOffset + nodeToTest.ca.length;
+ }
+ }
+ return charToReturn;
+ }
+
+ /**
+ * @return The previous FOText node in this Block.
+ * @return null, if this is the first FOText in this Block.
+ */
+ public FOText getPrevFOTextThisBlock () {
+ return prevFOTextThisBlock;
+ }
+
+ /**
+ * @return The next FOText node in this Block.
+ * @return null, if this is the last FOText in this Block, or if subsequent
+ * FOText nodes have not yet been processed.
+ */
+ public FOText getNextFOTextThisBlock () {
+ return nextFOTextThisBlock;
+ }
+
+ /**
+ * @return The nearest ancestor block object which contains this FOText.
+ */
+ public Block getAncestorBlock () {
+ return ancestorBlock;
+ }
+
+ /**
+ * Transforms one character in ca[] using the text-transform property.
+ *
+ * @param int with index for ca[]
+ * @return char with transformed value
+ */
+ public char charTransform(int i) {
+ switch (textInfo.textTransform) {
+ /* put NONE first, as this is probably the common case */
+ case TextTransform.NONE:
+ return ca[i];
+ case TextTransform.UPPERCASE:
+ return Character.toUpperCase(ca[i]);
+ case TextTransform.LOWERCASE:
+ return Character.toLowerCase(ca[i]);
+ case TextTransform.CAPITALIZE:
+ if (isStartOfWord(i)) {
+ /*
+ Use toTitleCase here. Apparently, some languages use
+ a different character to represent a letter when using
+ initial caps than when all of the letters in the word
+ are capitalized. We will try to let Java handle this.
+ */
+ return Character.toTitleCase(ca[i]);
+ }
+ else {
+ return Character.toLowerCase(ca[i]);
+ }
+ default:
+ getLogger().warn("Invalid text-tranform value: "
+ + textInfo.textTransform);
+ return ca[i];
+ }
+ }
+
+ /**
+ * Determines whether the input char should be considered part of a
+ * "word". This is used primarily to determine whether the character
+ * immediately following starts a new word, but may have other uses.
+ * We have not found a definition of "word" in the standard (1.0), so the
+ * logic used here is based on the programmer's best guess.
+ *
+ * @parameter char inputChar: the character to be tested.
+ * @return int IS_WORD_CHAR_TRUE, IS_WORD_CHAR_FALSE, or IS_WORD_CHAR_MAYBE,
+ * depending on whether the character should be considered part of a word
+ * or not.
+ */
+ public static int isWordChar(char inputChar) {
+ switch (Character.getType(inputChar)) {
+ case Character.COMBINING_SPACING_MARK:
+ return IS_WORD_CHAR_TRUE;
+ case Character.CONNECTOR_PUNCTUATION:
+ return IS_WORD_CHAR_TRUE;
+ case Character.CONTROL:
+ return IS_WORD_CHAR_FALSE;
+ case Character.CURRENCY_SYMBOL:
+ return IS_WORD_CHAR_TRUE;
+ case Character.DASH_PUNCTUATION:
+ if (inputChar == '-') return IS_WORD_CHAR_TRUE; //hyphen
+ return IS_WORD_CHAR_FALSE;
+ case Character.DECIMAL_DIGIT_NUMBER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.ENCLOSING_MARK:
+ return IS_WORD_CHAR_FALSE;
+ case Character.END_PUNCTUATION:
+ if (inputChar == '\u2019') return IS_WORD_CHAR_MAYBE; //apostrophe, right single quote
+ return IS_WORD_CHAR_FALSE;
+ case Character.FORMAT:
+ return IS_WORD_CHAR_FALSE;
+ case Character.LETTER_NUMBER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.LINE_SEPARATOR:
+ return IS_WORD_CHAR_FALSE;
+ case Character.LOWERCASE_LETTER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.MATH_SYMBOL:
+ return IS_WORD_CHAR_FALSE;
+ case Character.MODIFIER_LETTER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.MODIFIER_SYMBOL:
+ return IS_WORD_CHAR_TRUE;
+ case Character.NON_SPACING_MARK:
+ return IS_WORD_CHAR_TRUE;
+ case Character.OTHER_LETTER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.OTHER_NUMBER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.OTHER_PUNCTUATION:
+ if (inputChar == '\'') return IS_WORD_CHAR_MAYBE; //ASCII apostrophe
+ return IS_WORD_CHAR_FALSE;
+ case Character.OTHER_SYMBOL:
+ return IS_WORD_CHAR_TRUE;
+ case Character.PARAGRAPH_SEPARATOR:
+ return IS_WORD_CHAR_FALSE;
+ case Character.PRIVATE_USE:
+ return IS_WORD_CHAR_FALSE;
+ case Character.SPACE_SEPARATOR:
+ return IS_WORD_CHAR_FALSE;
+ case Character.START_PUNCTUATION:
+ return IS_WORD_CHAR_FALSE;
+ case Character.SURROGATE:
+ return IS_WORD_CHAR_FALSE;
+ case Character.TITLECASE_LETTER:
+ return IS_WORD_CHAR_TRUE;
+ case Character.UNASSIGNED:
+ return IS_WORD_CHAR_FALSE;
+ case Character.UPPERCASE_LETTER:
+ return IS_WORD_CHAR_TRUE;
+ default:
+ return IS_WORD_CHAR_FALSE;
+ }
+ }
+
+}
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
- *
+ *
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
- *
+ *
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
- */
+ */
package org.apache.fop.fo;
// Java
private static final MessageFormat MSGFMT_PADDING = new MessageFormat("padding-{0}");
private static final String NONE = "none";
-
+
/**
* Main constructor
* @param pList property list
}
/**
- * Sets the FontInfo object telling the property manager which fonts are
+ * Sets the FontInfo object telling the property manager which fonts are
* available.
* @param fontInfo available fonts
*/
/**
- * Constructs a FontState object. If it was constructed before it is
+ * Constructs a FontState object. If it was constructed before it is
* reused.
* @param fontInfo FontInfo to work with
* @return a FontState object
this.fontInfo = fontInfo;
}
/**@todo this is ugly. need to improve. */
-
+
String fontFamily = properties.get("font-family").getString();
String fontStyle = properties.get("font-style").getString();
String fw = properties.get("font-weight").getString();
/**
- * Constructs a BorderAndPadding object. If it was constructed before it is
+ * Constructs a BorderAndPadding object. If it was constructed before it is
* reused.
* @return a BorderAndPadding object
*/
}
/**
- * Constructs a HyphenationProps objects. If it was constructed before it is
+ * Constructs a HyphenationProps objects. If it was constructed before it is
* reused.
* @return a HyphenationProps object
*/
/**
- * Constructs a MarginProps objects. If it was constructed before it is
+ * Constructs a MarginProps objects. If it was constructed before it is
* reused.
* @return a MarginProps object
*/
}
/**
- * Constructs a BackgroundProps objects. If it was constructed before it is
+ * Constructs a BackgroundProps objects. If it was constructed before it is
* reused.
* @return a BackgroundProps object
*/
}
/**
- * Constructs a MarginInlineProps objects. If it was constructed before it is
+ * Constructs a MarginInlineProps objects. If it was constructed before it is
* reused.
* @return a MarginInlineProps object
*/
}
/**
- * Constructs a InlineProps objects. If it was constructed before it is
+ * Constructs a InlineProps objects. If it was constructed before it is
* reused.
* @return a InlineProps object
*/
}
/**
- * Constructs a AccessibilityProps objects. If it was constructed before it is
+ * Constructs a AccessibilityProps objects. If it was constructed before it is
* reused.
* @return a AccessibilityProps object
*/
}
/**
- * Constructs a AuralProps objects. If it was constructed before it is
+ * Constructs a AuralProps objects. If it was constructed before it is
* reused.
* @return a AuralProps object
*/
}
/**
- * Constructs a RelativePositionProps objects. If it was constructed before it is
+ * Constructs a RelativePositionProps objects. If it was constructed before it is
* reused.
* @return a RelativePositionProps object
*/
}
/**
- * Constructs a AbsolutePositionProps objects. If it was constructed before
+ * Constructs a AbsolutePositionProps objects. If it was constructed before
* it is reused.
* @return a AbsolutePositionProps object
*/
}
/**
- * Constructs a BlockProps objects. If it was constructed before it is
+ * Constructs a BlockProps objects. If it was constructed before it is
* reused.
* @return a BlockProps object
*/
public BlockProps getBlockProps() {
BlockProps props = new BlockProps();
props.firstIndent = this.properties.get("text-indent").getLength().getValue();
- props.lastIndent = 0;
+ props.lastIndent = 0;
/*this.properties.get("last-line-end-indent").getLength().mvalue(); */
props.textAlign = this.properties.get("text-align").getEnum();
props.textAlignLast = this.properties.get("text-align-last").getEnum();
}
/**
- * Constructs a LayoutProps objects. If it was constructed before it is
+ * Constructs a LayoutProps objects. If it was constructed before it is
* reused.
* @return a LayoutProps object
*/
}
/**
- * Constructs a TextInfo objects. If it was constructed before it is
+ * Constructs a TextInfo objects. If it was constructed before it is
* reused.
* @param fontInfo available fonts
* @return a TextInfo object
textInfo.lineHeight = this.properties.get(
"line-height").getLength().getValue();
+
+ textInfo.textTransform
+ = this.properties.get("text-transform").getEnum();
+
}
return textInfo;
}
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
- *
+ *
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
- *
+ *
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
- *
+ *
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
- *
+ *
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
- *
+ *
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
- *
+ *
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
- *
+ *
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
- */
+ */
package org.apache.fop.fo;
// FOP
import org.apache.fop.layout.FontState;
import org.apache.fop.datatypes.ColorType;
import org.apache.fop.traits.SpaceVal;
+import org.apache.fop.fo.properties.TextTransform;
/**
* Collection of properties used in
public int whiteSpaceCollapse;
public int verticalAlign;
public int lineHeight;
+ public int textTransform = TextTransform.NONE;
// Props used for calculating inline-progression-dimension
public SpaceVal wordSpacing;
public boolean underlined = false;
public boolean overlined = false;
public boolean lineThrough = false;
+
}