org.apache.batik.bridge

Class SVGTextElementBridge

public class SVGTextElementBridge extends AbstractGraphicsNodeBridge implements SVGTextContent

Bridge class for the <text> element.
Nested Class Summary
protected abstract classSVGTextElementBridge.AbstractTextChildBridgeUpdateHandler
Implementation for the BridgeUpdateHandler for the child elements of <text>.
abstract classSVGTextElementBridge.AbstractTextChildSVGContext
Implementation of SVGContext for the children of <text>
protected classSVGTextElementBridge.AbstractTextChildTextContent
protected static classSVGTextElementBridge.AttributedStringBuffer
This class is used to build an AttributedString.
protected static classSVGTextElementBridge.CharacterInformation
Helper class to collect information about one Glyph in the GlyphVector
protected classSVGTextElementBridge.DOMChildNodeRemovedEventListener
The DOM EventListener invoked when a node is removed.
protected classSVGTextElementBridge.DOMSubtreeModifiedEventListener
The DOM EventListener invoked when the subtree is modified.
protected classSVGTextElementBridge.TextPathBridge
BridgeUpdateHandle for <textPath> element.
protected classSVGTextElementBridge.TRefBridge
BridgeUpdateHandle for <tref> element.
protected classSVGTextElementBridge.TspanBridge
BridgeUpdateHandle for <tspan> element.
Field Summary
static AttributeALT_GLYPH_HANDLER
static AttributeANCHOR_TYPE
static AttributeBASELINE_SHIFT
protected SVGTextElementBridge.DOMChildNodeRemovedEventListenerchildNodeRemovedEventListener
The DOM EventListener to receive 'DOMNodeRemoved' event.
protected WeakHashMapelemTPI
protected intendLimit
This is used to store the end of the last piece of text content from an element with xml:space="preserve".
static AttributeGVT_FONTS
static AttributeGVT_FONT_FAMILIES
protected AttributedStringlaidoutText
static AttributePAINT_INFO
protected SVGTextElementBridge.DOMSubtreeModifiedEventListenersubtreeModifiedEventListener
The DOM EventListener to receive 'DOMSubtreeModified' event.
static AttributeTEXTPATH
static AttributeTEXT_COMPOUND_DELIMITER
static AttributeTEXT_COMPOUND_ID
protected booleanusingComplexSVGFont
protected static IntegerZERO
Constructor Summary
SVGTextElementBridge()
Constructs a new bridge for the <text> element.
Method Summary
protected voidaddChildGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx)
protected voidaddChildPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo parentPI, BridgeContext ctx)
protected voidaddContextToChild(BridgeContext ctx, Element e)
Add to the element children of the node, a SVGContext to support dynamic update.
protected voidaddGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx)
Adds glyph position attributes to an AttributedString.
protected voidaddPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo pi, BridgeContext ctx)
Adds painting attributes to an AttributedString.
protected voidaddTextEventListeners(BridgeContext ctx, NodeEventTarget e)
Adds the DOM listeners for this text bridge.
protected AttributedStringbuildAttributedString(BridgeContext ctx, Element element)
Creates the attributed string which represents the given text element children.
voidbuildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node)
Builds using the specified BridgeContext and element, the specified graphics node.
protected voidcomputeLaidoutText(BridgeContext ctx, Element e, GraphicsNode node)
Recompute the layout of the <text> node.
GraphicsNodecreateGraphicsNode(BridgeContext ctx, Element e)
Creates a GraphicsNode according to the specified parameters.
protected floatdistanceBetweenRun(SVGTextElementBridge.CharacterInformation last, SVGTextElementBridge.CharacterInformation first)
protected floatdistanceFirstLastCharacterInRun(SVGTextElementBridge.CharacterInformation first, SVGTextElementBridge.CharacterInformation last)
protected voidfillAttributedStringBuffer(BridgeContext ctx, Element element, boolean top, TextPath textPath, Integer bidiLevel, SVGTextElementBridge.AttributedStringBuffer asb)
Fills the given AttributedStringBuffer.
protected MapgetAttributeMap(BridgeContext ctx, Element element, TextPath textPath, Integer bidiLevel)
Returns the map to pass to the current characters.
protected SVGTextElementBridge.CharacterInformationgetCharacterInformation(List list, int startIndex, int charnum, AttributedCharacterIterator aci)
Retrieve the information about a character of en element.
intgetCharNumAtPosition(float x, float y)
protected intgetCharNumAtPosition(Element e, float x, float y)
floatgetComputedTextLength()
protected floatgetComputedTextLength(Element e)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getComputedTextLength()}.
protected Point2DgetEndPoint(SVGTextElementBridge.CharacterInformation info)
Point2DgetEndPositionOfChar(int charnum)
protected Point2DgetEndPositionOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getEndPositionOfChar(int charnum)}.
Rectangle2DgetExtentOfChar(int charnum)
protected Rectangle2DgetExtentOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getExtentOfChar(int charnum)}.
protected NodegetFirstChild(Node n)
Returns the first child node of the given node that should be processed by the text bridge.
protected ListgetFontList(BridgeContext ctx, Element element, Map result)
This method adds all the font related properties to result It also builds a List of the GVTFonts and returns it.
BridgegetInstance()
Returns a new instance of this bridge.
StringgetLocalName()
Returns 'text'.
protected Point2DgetLocation(BridgeContext ctx, Element e)
Returns the text node location according to the 'x' and 'y' attributes of the specified text element.
protected NodegetNextSibling(Node n)
Returns the next sibling node of the given node that should be processed by the text bridge.
intgetNumberOfChars()
protected intgetNumberOfChars(Element element)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getNumberOfChars()}.
protected NodegetParentNode(Node n)
Returns the parent node of the given node that should be processed by the text bridge.
protected TextPaintInfogetParentTextPaintInfo(Element child)
Retrieve in the AttributeString the closest parent of the node 'child' and extract the text decorations of the parent.
floatgetRotationOfChar(int charnum)
protected floatgetRotationOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getRotationOfChar(int charnum)}.
protected Point2DgetStartPoint(SVGTextElementBridge.CharacterInformation info)
Point2DgetStartPositionOfChar(int charnum)
protected Point2DgetStartPositionOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getStartPositionOfChar(int charnum)}.
floatgetSubStringLength(int charnum, int nchars)
protected floatgetSubStringLength(Element element, int charnum, int nchars)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getSubStringLength(int charnum,int nchars)}.
static Rectangle2DgetTextBounds(BridgeContext ctx, Element elem, boolean checkSensitivity)
SetgetTextEnclosureSet(AffineTransform at, Rectangle2D rect)
static booleangetTextIntersection(BridgeContext ctx, Element elem, AffineTransform ati, Rectangle2D rect, boolean checkSensitivity)
SetgetTextIntersectionSet(AffineTransform at, Rectangle2D rect)
protected TextNodegetTextNode()
protected TextPaintInfogetTextPaintInfo(Element element, GraphicsNode node, TextPaintInfo parentTPI, BridgeContext ctx)
Constructs a TextDecoration object for the specified element.
protected ListgetTextRuns(TextNode node)
Retrieve the list of layout for the text node.
voidhandleAnimatedAttributeChanged(AnimatedLiveAttributeValue alav)
Invoked when the animated value of an animatable attribute has changed.
voidhandleCSSEngineEvent(CSSEngineEvent evt)
Invoked when CSS properties have changed on an element.
protected voidhandleCSSPropertyChanged(int property)
Invoked for each CSS property that has changed.
voidhandleDOMCharacterDataModified(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMCharacterDataModified' is fired.
voidhandleDOMChildNodeRemovedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired.
voidhandleDOMNodeInsertedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeInserted' is fired.
voidhandleDOMNodeRemovedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired.
voidhandleDOMSubtreeModifiedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMSubtree' is fired.
protected voidinitializeDynamicSupport(BridgeContext ctx, Element e, GraphicsNode node)
This method ensures that any modification to a text element and its children is going to be reflected into the GVT tree.
protected GraphicsNodeinstantiateGraphicsNode()
Creates the GraphicsNode depending on the GraphicsNodeBridge implementation.
booleanisComposite()
Returns false as text is not a container.
protected booleanisParentDisplayed(Node childNode)
Indicate of the parent of a node is a displayed element.
protected booleanisTextChild(Element e)
protected booleanisTextElement(Element e)
static booleanisTextSensitive(Element e)
protected booleannodeAncestorOf(Node node1, Node node2)
Returns true if node1 is an ancestor of node2
protected StringnormalizeString(String s, boolean preserve, boolean stripfirst)
Normalizes the given string.
protected voidrebuildACI()
protected voidremoveTextEventListeners(BridgeContext ctx, NodeEventTarget e)
Removes the DOM listeners for this text bridge.
voidselectSubString(int charnum, int nchars)
protected voidselectSubString(Element element, int charnum, int nchars)
Select an ensemble of characters for that element.
voidsetBaseTextPaintInfo(TextPaintInfo pi, Element element, GraphicsNode node, BridgeContext ctx)
voidsetDecorationTextPaintInfo(TextPaintInfo pi, Element element)

Field Detail

ALT_GLYPH_HANDLER

public static final Attribute ALT_GLYPH_HANDLER

ANCHOR_TYPE

public static final Attribute ANCHOR_TYPE

BASELINE_SHIFT

public static final Attribute BASELINE_SHIFT

childNodeRemovedEventListener

protected SVGTextElementBridge.DOMChildNodeRemovedEventListener childNodeRemovedEventListener
The DOM EventListener to receive 'DOMNodeRemoved' event.

elemTPI

protected WeakHashMap elemTPI

endLimit

protected int endLimit
This is used to store the end of the last piece of text content from an element with xml:space="preserve". When we are stripping trailing spaces we need to make sure we don't strip anything before this point.

GVT_FONTS

public static final Attribute GVT_FONTS

GVT_FONT_FAMILIES

public static final Attribute GVT_FONT_FAMILIES

laidoutText

protected AttributedString laidoutText

PAINT_INFO

public static final Attribute PAINT_INFO

subtreeModifiedEventListener

protected SVGTextElementBridge.DOMSubtreeModifiedEventListener subtreeModifiedEventListener
The DOM EventListener to receive 'DOMSubtreeModified' event.

TEXTPATH

public static final Attribute TEXTPATH

TEXT_COMPOUND_DELIMITER

public static final Attribute TEXT_COMPOUND_DELIMITER

TEXT_COMPOUND_ID

public static final Attribute TEXT_COMPOUND_ID

usingComplexSVGFont

protected boolean usingComplexSVGFont

ZERO

protected static final Integer ZERO

Constructor Detail

SVGTextElementBridge

public SVGTextElementBridge()
Constructs a new bridge for the <text> element.

Method Detail

addChildGlyphPositionAttributes

protected void addChildGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx)

addChildPaintAttributes

protected void addChildPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo parentPI, BridgeContext ctx)

addContextToChild

protected void addContextToChild(BridgeContext ctx, Element e)
Add to the element children of the node, a SVGContext to support dynamic update. This is recursive, the children of the nodes are also traversed to add to the support elements their context

Parameters: ctx a BridgeContext value e an Element value

See Also: SVGContext BridgeUpdateHandler

addGlyphPositionAttributes

protected void addGlyphPositionAttributes(AttributedString as, Element element, BridgeContext ctx)
Adds glyph position attributes to an AttributedString.

addPaintAttributes

protected void addPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo pi, BridgeContext ctx)
Adds painting attributes to an AttributedString.

addTextEventListeners

protected void addTextEventListeners(BridgeContext ctx, NodeEventTarget e)
Adds the DOM listeners for this text bridge.

buildAttributedString

protected AttributedString buildAttributedString(BridgeContext ctx, Element element)
Creates the attributed string which represents the given text element children.

Parameters: ctx the bridge context to use element the text element

buildGraphicsNode

public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node)
Builds using the specified BridgeContext and element, the specified graphics node.

Parameters: ctx the bridge context to use e the element that describes the graphics node to build node the graphics node to build

computeLaidoutText

protected void computeLaidoutText(BridgeContext ctx, Element e, GraphicsNode node)
Recompute the layout of the <text> node. Assign onto the TextNode pending to the element the new recomputed AttributedString. Also update laidoutText with the new value.

createGraphicsNode

public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e)
Creates a GraphicsNode according to the specified parameters.

Parameters: ctx the bridge context to use e the element that describes the graphics node to build

Returns: a graphics node that represents the specified element

distanceBetweenRun

protected float distanceBetweenRun(SVGTextElementBridge.CharacterInformation last, SVGTextElementBridge.CharacterInformation first)

distanceFirstLastCharacterInRun

protected float distanceFirstLastCharacterInRun(SVGTextElementBridge.CharacterInformation first, SVGTextElementBridge.CharacterInformation last)

fillAttributedStringBuffer

protected void fillAttributedStringBuffer(BridgeContext ctx, Element element, boolean top, TextPath textPath, Integer bidiLevel, SVGTextElementBridge.AttributedStringBuffer asb)
Fills the given AttributedStringBuffer.

getAttributeMap

protected Map getAttributeMap(BridgeContext ctx, Element element, TextPath textPath, Integer bidiLevel)
Returns the map to pass to the current characters.

getCharacterInformation

protected SVGTextElementBridge.CharacterInformation getCharacterInformation(List list, int startIndex, int charnum, AttributedCharacterIterator aci)
Retrieve the information about a character of en element. The element first character in the ACI is 'firstChar' and the character look for is the charnum th character in the element

Parameters: list list of the layouts startIndex index in the ACI of the first character for the element charnum index of the character (among the characters of the element) looked for.

Returns: information about the glyph representing the character

getCharNumAtPosition

public int getCharNumAtPosition(float x, float y)

getCharNumAtPosition

protected int getCharNumAtPosition(Element e, float x, float y)

getComputedTextLength

public float getComputedTextLength()

getComputedTextLength

protected float getComputedTextLength(Element e)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getComputedTextLength()}.

getEndPoint

protected Point2D getEndPoint(SVGTextElementBridge.CharacterInformation info)

getEndPositionOfChar

public Point2D getEndPositionOfChar(int charnum)

getEndPositionOfChar

protected Point2D getEndPositionOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getEndPositionOfChar(int charnum)}.

getExtentOfChar

public Rectangle2D getExtentOfChar(int charnum)

getExtentOfChar

protected Rectangle2D getExtentOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getExtentOfChar(int charnum)}.

getFirstChild

protected Node getFirstChild(Node n)
Returns the first child node of the given node that should be processed by the text bridge.

getFontList

protected List getFontList(BridgeContext ctx, Element element, Map result)
This method adds all the font related properties to result It also builds a List of the GVTFonts and returns it.

getInstance

public Bridge getInstance()
Returns a new instance of this bridge.

getLocalName

public String getLocalName()
Returns 'text'.

getLocation

protected Point2D getLocation(BridgeContext ctx, Element e)
Returns the text node location according to the 'x' and 'y' attributes of the specified text element.

Parameters: ctx the bridge context to use e the text element

getNextSibling

protected Node getNextSibling(Node n)
Returns the next sibling node of the given node that should be processed by the text bridge.

getNumberOfChars

public int getNumberOfChars()

getNumberOfChars

protected int getNumberOfChars(Element element)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getNumberOfChars()}.

getParentNode

protected Node getParentNode(Node n)
Returns the parent node of the given node that should be processed by the text bridge.

getParentTextPaintInfo

protected TextPaintInfo getParentTextPaintInfo(Element child)
Retrieve in the AttributeString the closest parent of the node 'child' and extract the text decorations of the parent.

Parameters: child an Element value

Returns: a TextDecoration value

getRotationOfChar

public float getRotationOfChar(int charnum)

getRotationOfChar

protected float getRotationOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getRotationOfChar(int charnum)}.

getStartPoint

protected Point2D getStartPoint(SVGTextElementBridge.CharacterInformation info)

getStartPositionOfChar

public Point2D getStartPositionOfChar(int charnum)

getStartPositionOfChar

protected Point2D getStartPositionOfChar(Element element, int charnum)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getStartPositionOfChar(int charnum)}.

getSubStringLength

public float getSubStringLength(int charnum, int nchars)

getSubStringLength

protected float getSubStringLength(Element element, int charnum, int nchars)
Implementation of {@link org.w3c.dom.svg.SVGTextContentElement#getSubStringLength(int charnum,int nchars)}.

getTextBounds

public static Rectangle2D getTextBounds(BridgeContext ctx, Element elem, boolean checkSensitivity)

getTextEnclosureSet

public Set getTextEnclosureSet(AffineTransform at, Rectangle2D rect)

getTextIntersection

public static boolean getTextIntersection(BridgeContext ctx, Element elem, AffineTransform ati, Rectangle2D rect, boolean checkSensitivity)

getTextIntersectionSet

public Set getTextIntersectionSet(AffineTransform at, Rectangle2D rect)

getTextNode

protected TextNode getTextNode()

getTextPaintInfo

protected TextPaintInfo getTextPaintInfo(Element element, GraphicsNode node, TextPaintInfo parentTPI, BridgeContext ctx)
Constructs a TextDecoration object for the specified element. This will contain all of the decoration properties to be used when drawing the text.

getTextRuns

protected List getTextRuns(TextNode node)
Retrieve the list of layout for the text node.

handleAnimatedAttributeChanged

public void handleAnimatedAttributeChanged(AnimatedLiveAttributeValue alav)
Invoked when the animated value of an animatable attribute has changed.

handleCSSEngineEvent

public void handleCSSEngineEvent(CSSEngineEvent evt)
Invoked when CSS properties have changed on an element.

Parameters: evt the CSSEngine event that describes the update

handleCSSPropertyChanged

protected void handleCSSPropertyChanged(int property)
Invoked for each CSS property that has changed.

handleDOMCharacterDataModified

public void handleDOMCharacterDataModified(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMCharacterDataModified' is fired.

handleDOMChildNodeRemovedEvent

public void handleDOMChildNodeRemovedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired.

handleDOMNodeInsertedEvent

public void handleDOMNodeInsertedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeInserted' is fired.

handleDOMNodeRemovedEvent

public void handleDOMNodeRemovedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMNodeRemoved' is fired.

handleDOMSubtreeModifiedEvent

public void handleDOMSubtreeModifiedEvent(MutationEvent evt)
Invoked when an MutationEvent of type 'DOMSubtree' is fired.

initializeDynamicSupport

protected void initializeDynamicSupport(BridgeContext ctx, Element e, GraphicsNode node)
This method ensures that any modification to a text element and its children is going to be reflected into the GVT tree.

instantiateGraphicsNode

protected GraphicsNode instantiateGraphicsNode()
Creates the GraphicsNode depending on the GraphicsNodeBridge implementation.

isComposite

public boolean isComposite()
Returns false as text is not a container.

isParentDisplayed

protected boolean isParentDisplayed(Node childNode)
Indicate of the parent of a node is a displayed element. <title>, <desc> and <metadata> are non displayable elements.

Returns: true if the parent of the node is <text>, <tspan>, <tref>, <textPath>, <a>, <altGlyph>

isTextChild

protected boolean isTextChild(Element e)

isTextElement

protected boolean isTextElement(Element e)

isTextSensitive

public static boolean isTextSensitive(Element e)

nodeAncestorOf

protected boolean nodeAncestorOf(Node node1, Node node2)
Returns true if node1 is an ancestor of node2

normalizeString

protected String normalizeString(String s, boolean preserve, boolean stripfirst)
Normalizes the given string.

rebuildACI

protected void rebuildACI()

removeTextEventListeners

protected void removeTextEventListeners(BridgeContext ctx, NodeEventTarget e)
Removes the DOM listeners for this text bridge.

selectSubString

public void selectSubString(int charnum, int nchars)

selectSubString

protected void selectSubString(Element element, int charnum, int nchars)
Select an ensemble of characters for that element. TODO : report the selection to the selection manager in JSVGComponent.

setBaseTextPaintInfo

public void setBaseTextPaintInfo(TextPaintInfo pi, Element element, GraphicsNode node, BridgeContext ctx)

setDecorationTextPaintInfo

public void setDecorationTextPaintInfo(TextPaintInfo pi, Element element)
Copyright B) 2007 Apache Software Foundation. All Rights Reserved.