Class SVGTextElementBridge

All Implemented Interfaces:
SVGAnimationTargetContext, Bridge, BridgeUpdateHandler, ErrorConstants, GraphicsNodeBridge, XMLConstants, SVGContext, SVGTextContent, CSSConstants, SVGConstants
Direct Known Subclasses:
BatikFlowTextElementBridge, SVG12TextElementBridge

public class SVGTextElementBridge extends AbstractGraphicsNodeBridge implements SVGTextContent
Bridge class for the <text> element.
  • Field Details

  • Constructor Details

    • SVGTextElementBridge

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

    • getLocalName

      public String getLocalName()
      Returns 'text'.
      Specified by:
      getLocalName in interface Bridge
    • getInstance

      public Bridge getInstance()
      Returns a new instance of this bridge.
      Specified by:
      getInstance in interface Bridge
      Specified by:
      getInstance in interface GraphicsNodeBridge
      Overrides:
      getInstance in class AbstractSVGBridge
    • getTextNode

      protected TextNode getTextNode()
    • createGraphicsNode

      public GraphicsNode createGraphicsNode(BridgeContext ctx, Element e)
      Creates a GraphicsNode according to the specified parameters.
      Specified by:
      createGraphicsNode in interface GraphicsNodeBridge
      Overrides:
      createGraphicsNode in class AbstractGraphicsNodeBridge
      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
    • instantiateGraphicsNode

      protected GraphicsNode instantiateGraphicsNode()
      Creates the GraphicsNode depending on the GraphicsNodeBridge implementation.
      Specified by:
      instantiateGraphicsNode in class AbstractGraphicsNodeBridge
    • 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
    • isTextElement

      protected boolean isTextElement(Element e)
    • isTextChild

      protected boolean isTextChild(Element e)
    • buildGraphicsNode

      public void buildGraphicsNode(BridgeContext ctx, Element e, GraphicsNode node)
      Builds using the specified BridgeContext and element, the specified graphics node.
      Specified by:
      buildGraphicsNode in interface GraphicsNodeBridge
      Overrides:
      buildGraphicsNode in class AbstractGraphicsNodeBridge
      Parameters:
      ctx - the bridge context to use
      e - the element that describes the graphics node to build
      node - the graphics node to build
    • isComposite

      public boolean isComposite()
      Returns false as text is not a container.
      Specified by:
      isComposite in interface GraphicsNodeBridge
    • getFirstChild

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

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

      protected Node getParentNode(Node n)
      Returns the parent node of the given node that should be processed by the text bridge.
    • 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.
      Overrides:
      initializeDynamicSupport in class AbstractGraphicsNodeBridge
    • addTextEventListeners

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

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

      public void dispose()
      Disposes this text element bridge by removing the text event listeners that were added in initializeDynamicSupport(org.apache.batik.bridge.BridgeContext, org.w3c.dom.Element, org.apache.batik.gvt.GraphicsNode).
      Specified by:
      dispose in interface BridgeUpdateHandler
      Overrides:
      dispose in class AbstractGraphicsNodeBridge
    • addContextToChild

      protected void addContextToChild(BridgeContext ctx, Element e)
      Add to the element children of the node, an 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:
    • removeContextFromChild

      protected void removeContextFromChild(BridgeContext ctx, Element e)
      From the SVGContext from the element children of the node.
      Parameters:
      ctx - the BridgeContext for the document
      e - the Element whose subtree's elements will have threir SVGContexts removed
      See Also:
    • handleDOMNodeInsertedEvent

      public void handleDOMNodeInsertedEvent(MutationEvent evt)
      Invoked when an MutationEvent of type 'DOMNodeInserted' is fired.
      Specified by:
      handleDOMNodeInsertedEvent in interface BridgeUpdateHandler
      Overrides:
      handleDOMNodeInsertedEvent in class AbstractGraphicsNodeBridge
    • handleDOMChildNodeRemovedEvent

      public void handleDOMChildNodeRemovedEvent(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.
    • handleDOMCharacterDataModified

      public void handleDOMCharacterDataModified(MutationEvent evt)
      Invoked when an MutationEvent of type 'DOMCharacterDataModified' is fired.
      Specified by:
      handleDOMCharacterDataModified in interface BridgeUpdateHandler
      Overrides:
      handleDOMCharacterDataModified in class AbstractGraphicsNodeBridge
    • 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>
    • 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.
    • handleAnimatedAttributeChanged

      public void handleAnimatedAttributeChanged(AnimatedLiveAttributeValue alav)
      Invoked when the animated value of an animatable attribute has changed.
      Specified by:
      handleAnimatedAttributeChanged in interface BridgeUpdateHandler
      Overrides:
      handleAnimatedAttributeChanged in class AbstractGraphicsNodeBridge
    • handleCSSEngineEvent

      public void handleCSSEngineEvent(CSSEngineEvent evt)
      Invoked when CSS properties have changed on an element.
      Specified by:
      handleCSSEngineEvent in interface BridgeUpdateHandler
      Overrides:
      handleCSSEngineEvent in class AbstractGraphicsNodeBridge
      Parameters:
      evt - the CSSEngine event that describes the update
    • handleCSSPropertyChanged

      protected void handleCSSPropertyChanged(int property)
      Invoked for each CSS property that has changed.
      Overrides:
      handleCSSPropertyChanged in class AbstractGraphicsNodeBridge
    • rebuildACI

      protected void rebuildACI()
    • 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
    • fillAttributedStringBuffer

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

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

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

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

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

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

      protected void addChildPaintAttributes(AttributedString as, Element element, TextNode node, TextPaintInfo parentPI, BridgeContext ctx)
    • 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.
    • getAttributeMap

      protected Map getAttributeMap(BridgeContext ctx, Element element, TextPath textPath, Integer bidiLevel, Map result)
      Returns the map to pass to the current characters.
      Parameters:
      ctx - the BridgeContext to use for throwing exceptions
      element - the text element whose attributes are being collected
      textPath - the text path that the characters of element will be placed along
      bidiLevel - the bidi level of element
      result - a Map into which the attributes of element's characters will be stored
      Returns:
      a new Map that contains the attributes that must be inherited into a child element if the given element has no characters before the child element
    • 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
    • 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.
    • setBaseTextPaintInfo

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

      public void setDecorationTextPaintInfo(TextPaintInfo pi, Element element)
    • getNumberOfChars

      public int getNumberOfChars()
      Description copied from interface: SVGTextContent
      Returns the total number of characters to be rendered within the current element. Includes characters which are included via a <tref> reference.
      Specified by:
      getNumberOfChars in interface SVGTextContent
      Returns:
      Total number of characters.
    • getExtentOfChar

      public Rectangle2D getExtentOfChar(int charnum)
      Description copied from interface: SVGTextContent
      Returns a tightest rectangle which defines the minimum and maximum X and Y values in the user coordinate system for rendering the glyph(s) that correspond to the specified character. The calculations assume that all glyphs occupy the full standard glyph cell for the font. If multiple consecutive characters are rendered inseparably (e.g., as a single glyph or a sequence of glyphs), then each of the inseparable characters will return the same extent.
      Specified by:
      getExtentOfChar in interface SVGTextContent
      Parameters:
      charnum - The index of the character, where the first character has an index of 0.
      Returns:
      The rectangle which encloses all of the rendered glyph(s).
    • getStartPositionOfChar

      public Point2D getStartPositionOfChar(int charnum)
      Description copied from interface: SVGTextContent
      Returns the current text position before rendering the character in the user coordinate system for rendering the glyph(s) that correspond to the specified character. The current text position has already taken into account the effects of any inter- character adjustments due to properties 'kerning', 'letter-spacing' and 'word-spacing' and adjustments due to attributes x, y, dx and dy. If multiple consecutive characters are rendered inseparably (e.g., as a single glyph or a sequence of glyphs), then each of the inseparable characters will return the start position for the first glyph.
      Specified by:
      getStartPositionOfChar in interface SVGTextContent
      Parameters:
      charnum - The index of the character, where the first character has an index of 0.
      Returns:
      The character's start position.
    • getEndPositionOfChar

      public Point2D getEndPositionOfChar(int charnum)
      Description copied from interface: SVGTextContent
      Returns the current text position after rendering the character in the user coordinate system for rendering the glyph(s) that correspond to the specified character. This current text position does not take into account the effects of any inter- character adjustments to prepare for the next character, such as properties 'kerning', 'letter-spacing' and 'word-spacing' and adjustments due to attributes x, y, dx and dy. If multiple consecutive characters are rendered inseparably (e.g., as a single glyph or a sequence of glyphs), then each of the inseparable characters will return the end position for the last glyph.
      Specified by:
      getEndPositionOfChar in interface SVGTextContent
      Parameters:
      charnum - The index of the character, where the first character has an index of 0.
      Returns:
      The character's end position.
    • selectSubString

      public void selectSubString(int charnum, int nchars)
      Description copied from interface: SVGTextContent
      Causes the specified substring to be selected just as if the user selected the substring interactively.
      Specified by:
      selectSubString in interface SVGTextContent
      Parameters:
      charnum - : The index of the start character which is at the given point, where the first character has an index of 0.
      nchars - : The number of characters in the substring. If nchars specifies more characters than are available, then the substring will consist of all characters starting with charnum until the end of the list of characters.
    • getRotationOfChar

      public float getRotationOfChar(int charnum)
      Description copied from interface: SVGTextContent
      Returns the rotation value relative to the current user coordinate system used to render the glyph(s) corresponding to the specified character. If multiple glyph(s) are used to render the given character and the glyphs each have different rotations (e.g., due to text-on-a-path), the user agent shall return an average value (e.g., the rotation angle at the midpoint along the path for all glyphs used to render this character). The rotation value represents the rotation that is supplemental to any rotation due to properties 'glyph-orientation-horizontal' and 'glyph-orientation-vertical'; thus, any glyph rotations due to these properties are not included into the returned rotation value. If multiple consecutive characters are rendered inseparably (e.g., as a single glyph or a sequence of glyphs), then each of the inseparable characters will return the same rotation value.
      Specified by:
      getRotationOfChar in interface SVGTextContent
      Parameters:
      charnum - The index of the character, where the first character has an index of 0.
      Returns:
      The character's rotation angle.
    • getComputedTextLength

      public float getComputedTextLength()
      Specified by:
      getComputedTextLength in interface SVGTextContent
    • getSubStringLength

      public float getSubStringLength(int charnum, int nchars)
      Specified by:
      getSubStringLength in interface SVGTextContent
    • getCharNumAtPosition

      public int getCharNumAtPosition(float x, float y)
      Specified by:
      getCharNumAtPosition in interface SVGTextContent
    • getNumberOfChars

      protected int getNumberOfChars(Element element)
      Implementation of SVGTextContentElement.getNumberOfChars().
    • getExtentOfChar

      protected Rectangle2D getExtentOfChar(Element element, int charnum)
      Implementation of SVGTextContentElement.getExtentOfChar(int charnum).
    • getStartPositionOfChar

      protected Point2D getStartPositionOfChar(Element element, int charnum)
      Implementation of SVGTextContentElement.getStartPositionOfChar(int charnum).
    • getStartPoint

      protected Point2D getStartPoint(SVGTextElementBridge.CharacterInformation info)
    • getEndPositionOfChar

      protected Point2D getEndPositionOfChar(Element element, int charnum)
      Implementation of SVGTextContentElement.getEndPositionOfChar(int charnum).
    • getEndPoint

      protected Point2D getEndPoint(SVGTextElementBridge.CharacterInformation info)
    • getRotationOfChar

      protected float getRotationOfChar(Element element, int charnum)
      Implementation of SVGTextContentElement.getRotationOfChar(int charnum).
    • getComputedTextLength

      protected float getComputedTextLength(Element e)
      Implementation of SVGTextContentElement.getComputedTextLength().
    • getSubStringLength

      protected float getSubStringLength(Element element, int charnum, int nchars)
      Implementation of SVGTextContentElement.getSubStringLength(int charnum,int nchars).
    • distanceFirstLastCharacterInRun

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

    • 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.
    • getCharNumAtPosition

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

      protected List getTextRuns(TextNode node)
      Retrieve the list of layout for the text node.
    • 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
    • getTextIntersectionSet

      public Set getTextIntersectionSet(AffineTransform at, Rectangle2D rect)
    • getTextEnclosureSet

      public Set getTextEnclosureSet(AffineTransform at, Rectangle2D rect)
    • getTextIntersection

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

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

      public static boolean isTextSensitive(Element e)