Package org.apache.fop.fo
Class FOText
- java.lang.Object
-
- org.apache.fop.fo.FONode
-
- org.apache.fop.fo.FOText
-
- All Implemented Interfaces:
java.lang.CharSequence,java.lang.Cloneable,TextFragment
public class FOText extends FONode implements java.lang.CharSequence, TextFragment
A text node (PCDATA) in the formatting object tree.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classFOText.MapRangeprivate classFOText.TextCharIterator-
Nested classes/interfaces inherited from class org.apache.fop.fo.FONode
FONode.FONodeIterator, FONode.GatherContextInfoFunction
-
-
Field Summary
Fields Modifier and Type Field Description private BlockancestorBlockPoints to the ancestor Block object.private LengthbaselineShiftprivate int[]bidiLevelsprivate java.nio.BuffercharBuffertheCharBuffercontaining the textprivate java.text.CharacterIteratorcharIteratorprivate java.awt.Colorcolorprivate CommonFontcommonFontprivate CommonHyphenationcommonHyphenationprivate java.lang.Stringcountryprivate static intIS_WORD_CHAR_FALSEprivate static intIS_WORD_CHAR_MAYBEprivate static intIS_WORD_CHAR_TRUEprivate KeepPropertykeepTogetherprivate java.lang.Stringlanguageprivate PropertyletterSpacingprivate SpacePropertylineHeightprivate FOTextnextFOTextThisBlockPoints to the next FOText object created within the current block.private FOTextprevFOTextThisBlockPoints to the previous FOText object created within the current block.private java.lang.Stringscriptprivate StructureTreeElementstructureTreeElementprivate CommonTextDecorationtextDecorationHolds the text decoration values.private inttextTransformprivate intwhiteSpaceCollapseprivate intwhiteSpaceTreatmentprivate PropertywordSpacingprivate intwrapOption-
Fields inherited from class org.apache.fop.fo.FONode
FO_URI, FOX_URI, locator, log, nodeChangeBarList, parent, siblings, startOfNodeChangeBarList
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intbidiLevelAt(int position)Obtain bidirectional level of character at specified position, which must be a non-negative integer less than the length of this FO.voidbind(PropertyList pList)Bind the givenPropertyListto this node Does nothing by default.protected voidcharacters(char[] data, int start, int length, PropertyList list, org.xml.sax.Locator locator)Adds characters.charcharAt(int position)Obtain character at specified index within this fragment's sub-sequence, where index 0 corresponds to beginning index in overal text source, and subSequenceIndex must be less than ending index - beginning index.CharIteratorcharIterator()Return aCharIteratorover all characters in this nodeFONodeclone(FONode parent, boolean removeChildren)Performs a shallow cloning operation, sets the clone's parent, and optionally cleans the list of child nodesprotected java.util.Stack<DelimitedTextRange>collectDelimitedTextRanges(java.util.Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange)Collect the sequence of delimited text ranges, where each new range is pushed onto RANGES, where default implementation collects ranges of child nodes.protected voidcreateBlockPointers(Block ancestorBlock)This method is run as part of the ancestor Block's flushText(), to create xref pointers to the previous FOText objects within the same BlockvoidendOfNode()Primarily used for making final content model validation checks and/or informing theFOEventHandlerthat the end of this FO has been reached.voidfinalizeNode()Finalize this node.protected java.lang.StringgatherContextInfo()Gathers context information for the getContextInfo() method.LengthgetBaseLineShift()intgetBeginIndex()Obtain beginning index (inclusive) of sub-sequence of fragment in overall text source.intgetBidiLevel()Obtain associated bidi level (if known) or -1 if not.int[]getBidiLevels()Obtain bidirectional level of each character represented by this FOText.int[]getBidiLevels(int start, int end)Obtain bidirectional level of each character over interval [start,end).private java.nio.CharBuffergetCharBuffer()java.lang.CharSequencegetCharSequence()Return the array of characters for this instance.java.awt.ColorgetColor()CommonFontgetCommonFont()CommonHyphenationgetCommonHyphenation()java.lang.StringgetCountry()intgetEndIndex()Obtain ending index (exclusive) of sub-sequence of fragment in overall text source.java.text.CharacterIteratorgetIterator()Obtain reference to underlying iterator.KeepPropertygetKeepTogether()java.lang.StringgetLanguage()Obtain associated language (if designated) or "none" if not.PropertygetLetterSpacing()SpacePropertygetLineHeight()java.lang.StringgetLocalName()Returns the local name (i.e.java.lang.StringgetNormalNamespacePrefix()Returns the normally used namespace prefix for this nodeprivate chargetRelativeCharInBlock(int i, int offset)Finds a character within the current Block that is relative in location to a character in the current FOText.java.lang.StringgetScript()Obtain associated script (if designated) or "auto" if not.StructureTreeElementgetStructureTreeElement()Returns the structure tree element associated to this object.CommonTextDecorationgetTextDecoration()intgetWhitespaceTreatment()PropertygetWordSpacing()intgetWrapOption()booleanisDelimitedTextRangeBoundary(int boundary)Determine if node has a delimited text range boundary.private booleanisStartOfWord(int i)Determines whether a particular location in an FOText object's text is the start of a new "word".private static intisWordChar(char inputChar)Determines whether the input char should be considered part of a "word".intlength()voidresetBuffer()Resets the backingjava.nio.CharBuffervoidsetBidiLevel(int level, int start, int end)Set bidirectional level over interval [start,end).voidsetStructureTreeElement(StructureTreeElement structureTreeElement)Sets the structure tree element.java.lang.CharSequencesubSequence(int start, int end)private voidtextTransform()This method is run as part of endOfNode(), to handle the text-transform property for accumulated FOTextjava.lang.StringtoString()booleanwillCreateArea()Check if this text node will create an area.-
Methods inherited from class org.apache.fop.fo.FONode
addCharacters, addChildNode, attachSiblings, canHaveMarkers, clone, collectDelimitedTextRanges, createPropertyList, decorateWithContextInfo, errorText, getBuilderContext, getChangeBarList, getChildNodes, getChildNodes, getContentHandlerFactory, getContextInfo, getContextInfoAlt, getExtensionAttachment, getFOEventHandler, getFOValidationEventProducer, getLocator, getLocatorString, getLogger, getName, getName, getNameId, getNamespaceURI, getNodePrefix, getNodeString, getParent, getRoot, getUserAgent, inMarker, invalidChildError, invalidChildError, invalidPropertyValueError, isBidiRangeBlockItem, isChangeBarElement, missingChildElementError, missingChildElementError, missingPropertyError, nodesOutOfOrderError, nodesOutOfOrderError, notSupportedChildError, processNode, removeChild, setLocator, startOfNode, tooManyNodesError, tooManyNodesError, tooManyNodesError, validateChildNode, validateChildNode, warningText
-
-
-
-
Field Detail
-
charBuffer
private java.nio.Buffer charBuffer
theCharBuffercontaining the text
-
charIterator
private java.text.CharacterIterator charIterator
-
commonFont
private CommonFont commonFont
-
commonHyphenation
private CommonHyphenation commonHyphenation
-
color
private java.awt.Color color
-
keepTogether
private KeepProperty keepTogether
-
letterSpacing
private Property letterSpacing
-
lineHeight
private SpaceProperty lineHeight
-
whiteSpaceTreatment
private int whiteSpaceTreatment
-
whiteSpaceCollapse
private int whiteSpaceCollapse
-
textTransform
private int textTransform
-
wordSpacing
private Property wordSpacing
-
wrapOption
private int wrapOption
-
baselineShift
private Length baselineShift
-
country
private java.lang.String country
-
language
private java.lang.String language
-
script
private java.lang.String script
-
prevFOTextThisBlock
private FOText prevFOTextThisBlock
Points to the previous FOText object created within the current block. If this is "null", this is the first such object.
-
nextFOTextThisBlock
private FOText nextFOTextThisBlock
Points to the next FOText object created within the current block. If this is "null", this is the last such object.
-
ancestorBlock
private Block ancestorBlock
Points to the ancestor Block object. This is used to keep track of which FOText nodes are descendants of the same block.
-
textDecoration
private CommonTextDecoration textDecoration
Holds the text decoration values. May be null
-
structureTreeElement
private StructureTreeElement structureTreeElement
-
bidiLevels
private int[] bidiLevels
-
IS_WORD_CHAR_FALSE
private static final int IS_WORD_CHAR_FALSE
- See Also:
- Constant Field Values
-
IS_WORD_CHAR_TRUE
private static final int IS_WORD_CHAR_TRUE
- See Also:
- Constant Field Values
-
IS_WORD_CHAR_MAYBE
private static final int IS_WORD_CHAR_MAYBE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FOText
public FOText(FONode parent)
Creates a new FO text node.- Parameters:
parent- FONode that is the parent of this object
-
-
Method Detail
-
characters
protected void characters(char[] data, int start, int length, PropertyList list, org.xml.sax.Locator locator) throws FOPExceptionAdds characters. Does nothing by default. To be overridden in subclasses that allow#PCDATAcontent.- Overrides:
charactersin classFONode- Parameters:
data- array of characters containing text to be addedstart- starting array element to addlength- number of elements to addlist- currently applicable PropertyListlocator- location in the XSL-FO source file.- Throws:
FOPException- if there's a problem during processing
-
getCharBuffer
private java.nio.CharBuffer getCharBuffer()
-
getCharSequence
public java.lang.CharSequence getCharSequence()
Return the array of characters for this instance.- Returns:
- a char sequence containing the text
-
clone
public FONode clone(FONode parent, boolean removeChildren) throws FOPException
Performs a shallow cloning operation, sets the clone's parent, and optionally cleans the list of child nodes- Overrides:
clonein classFONode- Parameters:
parent- the intended parent of the cloneremoveChildren- if true, clean the list of child nodes- Returns:
- the cloned FO node
- Throws:
FOPException- if there's a problem while cloning the node
-
bind
public void bind(PropertyList pList) throws FOPException
Bind the givenPropertyListto this node Does nothing by default. Subclasses should override this method in case they want to use the properties available on thePropertyList.- Overrides:
bindin classFONode- Parameters:
pList- thePropertyList- Throws:
FOPException- if there was an error when processing thePropertyList
-
endOfNode
public void endOfNode() throws FOPExceptionPrimarily used for making final content model validation checks and/or informing theFOEventHandlerthat the end of this FO has been reached. The default implementation simply callsFONode.finalizeNode(), without sending any event to theFOEventHandler.Note: the recommended way to override this method in subclasses is
super.endOfNode(); // invoke finalizeNode()getFOEventHandler().endXXX(); // send endOfNode() notification- Overrides:
endOfNodein classFONode- Throws:
FOPException- if there's a problem during processing
-
finalizeNode
public void finalizeNode()
Finalize this node. This method can be overridden by subclasses to perform finishing tasks (cleanup, validation checks, ...) without triggering endXXX() events in theFOEventHandler. The method is called by the defaultFONode.endOfNode()implementation.- Overrides:
finalizeNodein classFONode
-
willCreateArea
public boolean willCreateArea()
Check if this text node will create an area. This means either there is non-whitespace or it is preserved whitespace. Maybe this just needs to check length > 0, since char iterators handle whitespace.- Returns:
- true if this will create an area in the output
-
charIterator
public CharIterator charIterator()
Description copied from class:FONodeReturn aCharIteratorover all characters in this node- Overrides:
charIteratorin classFONode- Returns:
- a new TextCharIterator
-
createBlockPointers
protected void createBlockPointers(Block ancestorBlock)
This method is run as part of the ancestor Block's flushText(), to create xref pointers to the previous FOText objects within the same Block- Parameters:
ancestorBlock- the ancestor fo:block
-
textTransform
private void textTransform()
This method is run as part of endOfNode(), to handle the text-transform property for accumulated FOText
-
isStartOfWord
private boolean isStartOfWord(int 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.- Parameters:
i- index into charBuffer- Returns:
- True if the character at this location is the start of a new word.
-
getRelativeCharInBlock
private char getRelativeCharInBlock(int i, int offset)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.- Parameters:
i- index into the CharBufferoffset- 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.- Returns:
- the character in the offset position within the block; if the offset points to an area outside of the block.
-
isWordChar
private static int isWordChar(char inputChar)
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.- Parameters:
inputChar- the character to be tested.- Returns:
- 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.
-
getCommonFont
public CommonFont getCommonFont()
- Returns:
- the Common Font Properties.
-
getCommonHyphenation
public CommonHyphenation getCommonHyphenation()
- Returns:
- the Common Hyphenation Properties.
-
getColor
public java.awt.Color getColor()
- Returns:
- the "color" trait.
-
getKeepTogether
public KeepProperty getKeepTogether()
- Returns:
- the "keep-together" trait.
-
getLetterSpacing
public Property getLetterSpacing()
- Returns:
- the "letter-spacing" trait.
-
getLineHeight
public SpaceProperty getLineHeight()
- Returns:
- the "line-height" trait.
-
getWhitespaceTreatment
public int getWhitespaceTreatment()
- Returns:
- the "white-space-treatment" trait
-
getWordSpacing
public Property getWordSpacing()
- Returns:
- the "word-spacing" trait.
-
getWrapOption
public int getWrapOption()
- Returns:
- the "wrap-option" trait.
-
getTextDecoration
public CommonTextDecoration getTextDecoration()
- Returns:
- the "text-decoration" trait.
-
getBaseLineShift
public Length getBaseLineShift()
- Returns:
- the baseline-shift trait
-
getCountry
public java.lang.String getCountry()
- Returns:
- the country trait
-
getIterator
public java.text.CharacterIterator getIterator()
Description copied from interface:TextFragmentObtain reference to underlying iterator.- Specified by:
getIteratorin interfaceTextFragment
-
getBeginIndex
public int getBeginIndex()
Description copied from interface:TextFragmentObtain beginning index (inclusive) of sub-sequence of fragment in overall text source.- Specified by:
getBeginIndexin interfaceTextFragment
-
getEndIndex
public int getEndIndex()
Description copied from interface:TextFragmentObtain ending index (exclusive) of sub-sequence of fragment in overall text source.- Specified by:
getEndIndexin interfaceTextFragment
-
getLanguage
public java.lang.String getLanguage()
Description copied from interface:TextFragmentObtain associated language (if designated) or "none" if not.- Specified by:
getLanguagein interfaceTextFragment
-
getScript
public java.lang.String getScript()
Description copied from interface:TextFragmentObtain associated script (if designated) or "auto" if not.- Specified by:
getScriptin interfaceTextFragment
-
getBidiLevel
public int getBidiLevel()
Description copied from interface:TextFragmentObtain associated bidi level (if known) or -1 if not.- Specified by:
getBidiLevelin interfaceTextFragment
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejava.lang.CharSequence- Overrides:
toStringin classjava.lang.Object
-
getLocalName
public java.lang.String getLocalName()
Returns the local name (i.e. without namespace prefix) of the node- Specified by:
getLocalNamein classFONode- Returns:
- the local name of this node
-
getNormalNamespacePrefix
public java.lang.String getNormalNamespacePrefix()
Returns the normally used namespace prefix for this node- Specified by:
getNormalNamespacePrefixin classFONode- Returns:
- the normally used namespace prefix for this kind of node (ex. "fo" for XSL-FO)
-
gatherContextInfo
protected java.lang.String gatherContextInfo()
Gathers context information for the getContextInfo() method.- Overrides:
gatherContextInfoin classFONode- Returns:
- the collected context information or null, if none is available
-
charAt
public char charAt(int position)
Obtain character at specified index within this fragment's sub-sequence, where index 0 corresponds to beginning index in overal text source, and subSequenceIndex must be less than ending index - beginning index.- Specified by:
charAtin interfacejava.lang.CharSequence- Specified by:
charAtin interfaceTextFragment
-
subSequence
public java.lang.CharSequence subSequence(int start, int end)- Specified by:
subSequencein interfacejava.lang.CharSequence- Specified by:
subSequencein interfaceTextFragment
-
length
public int length()
- Specified by:
lengthin interfacejava.lang.CharSequence
-
resetBuffer
public void resetBuffer()
Resets the backingjava.nio.CharBuffer
-
isDelimitedTextRangeBoundary
public boolean isDelimitedTextRangeBoundary(int boundary)
Description copied from class:FONodeDetermine if node has a delimited text range boundary. N.B. that we report this to be true by default, while specific subclasses override this method to report false.- Overrides:
isDelimitedTextRangeBoundaryin classFONode- Parameters:
boundary- one of {EN_BEFORE, EN_AFTER, or EN_BOTH} enumeration constants- Returns:
- true if indicated boundary (or boundaries) constitute a delimited text range boundary.
-
setStructureTreeElement
public void setStructureTreeElement(StructureTreeElement structureTreeElement)
Description copied from class:FONodeSets the structure tree element.- Overrides:
setStructureTreeElementin classFONode- Parameters:
structureTreeElement- set.
-
getStructureTreeElement
public StructureTreeElement getStructureTreeElement()
Description copied from class:FONodeReturns the structure tree element associated to this object.- Overrides:
getStructureTreeElementin classFONode- Returns:
- the structure tree element
-
setBidiLevel
public void setBidiLevel(int level, int start, int end)Set bidirectional level over interval [start,end).- Parameters:
level- the resolved levelstart- the starting index of intervalend- the ending index of interval
-
getBidiLevels
public int[] getBidiLevels()
Obtain bidirectional level of each character represented by this FOText.- Returns:
- a (possibly empty) array of bidi levels or null in case no bidi levels have been assigned
-
getBidiLevels
public int[] getBidiLevels(int start, int end)Obtain bidirectional level of each character over interval [start,end).- Parameters:
start- the starting index of intervalend- the ending index of interval- Returns:
- a (possibly empty) array of bidi levels or null in case no bidi levels have been assigned
-
bidiLevelAt
public int bidiLevelAt(int position) throws java.lang.IndexOutOfBoundsExceptionObtain bidirectional level of character at specified position, which must be a non-negative integer less than the length of this FO.- Parameters:
position- an offset position into FO's characters- Returns:
- a resolved bidi level or -1 if default
- Throws:
java.lang.IndexOutOfBoundsException- if position is not non-negative integer or is greater than or equal to length
-
collectDelimitedTextRanges
protected java.util.Stack<DelimitedTextRange> collectDelimitedTextRanges(java.util.Stack<DelimitedTextRange> ranges, DelimitedTextRange currentRange)
Description copied from class:FONodeCollect the sequence of delimited text ranges, where each new range is pushed onto RANGES, where default implementation collects ranges of child nodes.- Overrides:
collectDelimitedTextRangesin classFONode- Parameters:
ranges- a stack of delimited text rangescurrentRange- the current range or null (if none)- Returns:
- the (possibly) updated stack of delimited text ranges
-
-