Class SVGUtilities

    • Field Detail

      • USER_SPACE_ON_USE

        public static final short USER_SPACE_ON_USE
        The userSpaceOnUse coordinate system constants.
        See Also:
        Constant Field Values
      • OBJECT_BOUNDING_BOX

        public static final short OBJECT_BOUNDING_BOX
        The objectBoundingBox coordinate system constants.
        See Also:
        Constant Field Values
      • STROKE_WIDTH

        public static final short STROKE_WIDTH
        The strokeWidth coordinate system constants.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SVGUtilities

        protected SVGUtilities()
        No instance of this class is required.
    • Method Detail

      • getParentElement

        public static org.w3c.dom.Element getParentElement​(org.w3c.dom.Element elt)
        Returns the logical parent element of the given element. The parent element of a used element is the <use> element which reference it.
      • convertSVGNumberList

        public static float[] convertSVGNumberList​(org.w3c.dom.svg.SVGNumberList l)
        Converts an SVGNumberList into a float array.
        Parameters:
        l - the list to convert
      • convertSVGNumber

        public static float convertSVGNumber​(java.lang.String s)
        Converts a string into a float.
        Parameters:
        s - the float representation to convert
      • convertSVGInteger

        public static int convertSVGInteger​(java.lang.String s)
        Converts a string into an integer.
        Parameters:
        s - the integer representation to convert
      • convertRatio

        public static float convertRatio​(java.lang.String v)
        Converts the specified ratio to float number.
        Parameters:
        v - the ratio value to convert
        Throws:
        java.lang.NumberFormatException - if the ratio is not a valid number or percentage
      • getDescription

        public static java.lang.String getDescription​(org.w3c.dom.svg.SVGElement elt)
        Returns the content of the 'desc' child of the given element.
      • matchUserAgent

        public static boolean matchUserAgent​(org.w3c.dom.Element elt,
                                             UserAgent ua)
        Tests whether or not the given element match a specified user agent.
        Parameters:
        elt - the element to check
        ua - the user agent
      • matchUserLanguage

        protected static boolean matchUserLanguage​(java.lang.String s,
                                                   java.lang.String userLanguages)
        Tests whether or not the specified language specification matches the user preferences.
        Parameters:
        s - the langage to check
        userLanguages - the user langages
      • getChainableAttributeNS

        public static java.lang.String getChainableAttributeNS​(org.w3c.dom.Element element,
                                                               java.lang.String namespaceURI,
                                                               java.lang.String attrName,
                                                               BridgeContext ctx)
        Returns the value of the specified attribute specified on the specified element or one of its ancestor. Ancestors are found using the xlink:href attribute.
        Parameters:
        element - the element to start with
        namespaceURI - the namespace URI of the attribute to return
        attrName - the name of the attribute to search
        ctx - the bridge context
        Returns:
        the value of the attribute or an empty string if not defined
      • convertPoint

        public static java.awt.geom.Point2D convertPoint​(java.lang.String xStr,
                                                         java.lang.String xAttr,
                                                         java.lang.String yStr,
                                                         java.lang.String yAttr,
                                                         short unitsType,
                                                         UnitProcessor.Context uctx)
        Returns a Point2D in user units according to the specified parameters.
        Parameters:
        xStr - the x coordinate
        xAttr - the name of the attribute that represents the x coordinate
        yStr - the y coordinate
        yAttr - the name of the attribute that represents the y coordinate
        unitsType - the coordinate system (OBJECT_BOUNDING_BOX | USER_SPACE_ON_USE)
        uctx - the unit processor context
      • convertLength

        public static float convertLength​(java.lang.String length,
                                          java.lang.String attr,
                                          short unitsType,
                                          UnitProcessor.Context uctx)
        Returns a float in user units according to the specified parameters.
        Parameters:
        length - the length
        attr - the name of the attribute that represents the length
        unitsType - the coordinate system (OBJECT_BOUNDING_BOX | USER_SPACE_ON_USE)
        uctx - the unit processor context
      • convertMaskRegion

        public static java.awt.geom.Rectangle2D convertMaskRegion​(org.w3c.dom.Element maskElement,
                                                                  org.w3c.dom.Element maskedElement,
                                                                  GraphicsNode maskedNode,
                                                                  BridgeContext ctx)
        Returns the mask region according to the x, y, width, height, and maskUnits attributes.
        Parameters:
        maskElement - the mask element that defines the various attributes
        maskedElement - the element referencing the mask
        maskedNode - the graphics node to mask (objectBoundingBox)
        ctx - the bridge context
      • convertPatternRegion

        public static java.awt.geom.Rectangle2D convertPatternRegion​(org.w3c.dom.Element patternElement,
                                                                     org.w3c.dom.Element paintedElement,
                                                                     GraphicsNode paintedNode,
                                                                     BridgeContext ctx)
        Returns the pattern region according to the x, y, width, height, and patternUnits attributes.
        Parameters:
        patternElement - the pattern element that defines the attributes
        paintedElement - the element referencing the pattern
        paintedNode - the graphics node to paint (objectBoundingBox)
        ctx - the bridge context
      • convertFilterRes

        public static float[] convertFilterRes​(org.w3c.dom.Element filterElement,
                                               BridgeContext ctx)
        Returns an array of 2 float numbers that describes the filter resolution of the specified filter element.
        Parameters:
        filterElement - the filter element
        ctx - the bridge context
      • convertSVGNumberOptionalNumber

        public static java.lang.Float[] convertSVGNumberOptionalNumber​(org.w3c.dom.Element elem,
                                                                       java.lang.String attrName,
                                                                       java.lang.String attrValue,
                                                                       BridgeContext ctx)
        This function parses attrValue for a number followed by an optional second Number. It always returns an array of two Floats. If either or both values are not provided the entries are set to null
      • convertFilterChainRegion

        public static java.awt.geom.Rectangle2D convertFilterChainRegion​(org.w3c.dom.Element filterElement,
                                                                         org.w3c.dom.Element filteredElement,
                                                                         GraphicsNode filteredNode,
                                                                         BridgeContext ctx)
        Returns the filter region according to the x, y, width, height, dx, dy, dw, dh and filterUnits attributes.
        Parameters:
        filterElement - the filter element that defines the attributes
        filteredElement - the element referencing the filter
        filteredNode - the graphics node to filter (objectBoundingBox)
        ctx - the bridge context
      • extendRegion

        protected static java.awt.geom.Rectangle2D extendRegion​(java.lang.String dxStr,
                                                                java.lang.String dyStr,
                                                                java.lang.String dwStr,
                                                                java.lang.String dhStr,
                                                                short unitsType,
                                                                GraphicsNode filteredNode,
                                                                java.awt.geom.Rectangle2D region,
                                                                UnitProcessor.Context uctx)
        Returns a rectangle that represents the region extended by the specified differential coordinates.
        Parameters:
        dxStr - the differential x coordinate of the region
        dyStr - the differential y coordinate of the region
        dwStr - the differential width of the region
        dhStr - the differential height of the region
        unitsType - specifies whether the values are in userSpaceOnUse or objectBoundingBox space
        region - the region to extend
        uctx - the unit processor context (needed for userSpaceOnUse)
      • getBaseFilterPrimitiveRegion

        public static java.awt.geom.Rectangle2D getBaseFilterPrimitiveRegion​(org.w3c.dom.Element filterPrimitiveElement,
                                                                             org.w3c.dom.Element filteredElement,
                                                                             GraphicsNode filteredNode,
                                                                             java.awt.geom.Rectangle2D defaultRegion,
                                                                             BridgeContext ctx)
      • convertFilterPrimitiveRegion

        public static java.awt.geom.Rectangle2D convertFilterPrimitiveRegion​(org.w3c.dom.Element filterPrimitiveElement,
                                                                             org.w3c.dom.Element filterElement,
                                                                             org.w3c.dom.Element filteredElement,
                                                                             GraphicsNode filteredNode,
                                                                             java.awt.geom.Rectangle2D defaultRegion,
                                                                             java.awt.geom.Rectangle2D filterRegion,
                                                                             BridgeContext ctx)
        Returns the filter primitive region according to the x, y, width, height, and filterUnits attributes. Processing the element as the top one in the filter chain.
        Parameters:
        filterPrimitiveElement - the filter primitive element
        filterElement - the filter element
        filteredElement - the element referencing the filter
        filteredNode - the graphics node to use (objectBoundingBox)
        defaultRegion - the default region to filter
        filterRegion - the filter chain region
        ctx - the bridge context
      • convertFilterPrimitiveRegion

        public static java.awt.geom.Rectangle2D convertFilterPrimitiveRegion​(org.w3c.dom.Element filterPrimitiveElement,
                                                                             org.w3c.dom.Element filteredElement,
                                                                             GraphicsNode filteredNode,
                                                                             java.awt.geom.Rectangle2D defaultRegion,
                                                                             java.awt.geom.Rectangle2D filterRegion,
                                                                             BridgeContext ctx)
        Returns the filter primitive region according to the x, y, width, height, and filterUnits attributes. Processing the element as the top one in the filter chain.
        Parameters:
        filterPrimitiveElement - the filter primitive element
        filteredElement - the element referencing the filter
        filteredNode - the graphics node to use (objectBoundingBox)
        defaultRegion - the default region to filter
        filterRegion - the filter chain region
        ctx - the bridge context
      • parseCoordinateSystem

        public static short parseCoordinateSystem​(org.w3c.dom.Element e,
                                                  java.lang.String attr,
                                                  java.lang.String coordinateSystem,
                                                  BridgeContext ctx)
        Parses the specified coordinate system defined by the specified element.
        Parameters:
        e - the element that defines the coordinate system
        attr - the attribute which contains the coordinate system
        coordinateSystem - the coordinate system to parse
        ctx - the BridgeContext to use for error information
        Returns:
        OBJECT_BOUNDING_BOX | USER_SPACE_ON_USE
      • parseMarkerCoordinateSystem

        public static short parseMarkerCoordinateSystem​(org.w3c.dom.Element e,
                                                        java.lang.String attr,
                                                        java.lang.String coordinateSystem,
                                                        BridgeContext ctx)
        Parses the specified coordinate system defined by the specified marker element.
        Parameters:
        e - the element that defines the coordinate system
        attr - the attribute which contains the coordinate system
        coordinateSystem - the coordinate system to parse
        ctx - the BridgeContext to use for error information
        Returns:
        STROKE_WIDTH | USER_SPACE_ON_USE
      • convertRegion

        protected static java.awt.geom.Rectangle2D convertRegion​(java.lang.String xStr,
                                                                 java.lang.String yStr,
                                                                 java.lang.String wStr,
                                                                 java.lang.String hStr,
                                                                 short unitsType,
                                                                 GraphicsNode targetNode,
                                                                 UnitProcessor.Context uctx)
        Returns a rectangle that represents the region defined by the specified coordinates.
        Parameters:
        xStr - the x coordinate of the region
        yStr - the y coordinate of the region
        wStr - the width of the region
        hStr - the height of the region
        targetNode - the graphics node (needed for objectBoundingBox)
        uctx - the unit processor context (needed for userSpaceOnUse)
      • convertTransform

        public static java.awt.geom.AffineTransform convertTransform​(org.w3c.dom.Element e,
                                                                     java.lang.String attr,
                                                                     java.lang.String transform,
                                                                     BridgeContext ctx)
        Returns an AffineTransform according to the specified parameters.
        Parameters:
        e - the element that defines the transform
        attr - the name of the attribute that represents the transform
        transform - the transform to parse
        ctx - the BridgeContext to use for error information
      • toObjectBBox

        public static java.awt.geom.AffineTransform toObjectBBox​(java.awt.geom.AffineTransform Tx,
                                                                 GraphicsNode node)
        Returns an AffineTransform to move to the objectBoundingBox coordinate system.
        Parameters:
        Tx - the original transformation
        node - the graphics node that defines the coordinate system to move into
      • toObjectBBox

        public static java.awt.geom.Rectangle2D toObjectBBox​(java.awt.geom.Rectangle2D r,
                                                             GraphicsNode node)
        Returns the specified a Rectangle2D move to the objectBoundingBox coordinate system of the specified graphics node.
        Parameters:
        r - the original Rectangle2D
        node - the graphics node that defines the coordinate system to move into
      • convertSnapshotTime

        public static float convertSnapshotTime​(org.w3c.dom.Element e,
                                                BridgeContext ctx)
        Returns the value of the 'snapshotTime' attribute on the specified element as a float, or 0f if the attribute is missing or given as "none".
        Parameters:
        e - the element from which to retrieve the 'snapshotTime' attribute
        ctx - the BridgeContext to use for error information