Class CSSUtilities

  • All Implemented Interfaces:
    ErrorConstants, XMLConstants, CSSConstants

    public abstract class CSSUtilities
    extends java.lang.Object
    implements CSSConstants, ErrorConstants, XMLConstants
    A collection of utility method involving CSS property. The listed methods bellow could be used as convenient methods to create concrete objects regarding to CSS properties.
    Version:
    $Id: CSSUtilities.java 1851346 2019-01-15 13:41:00Z ssteiner $
    • Field Detail

      • TRANSPARENT

        public static final java.awt.Composite TRANSPARENT
    • Constructor Detail

      • CSSUtilities

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

      • getCSSEngine

        public static CSSEngine getCSSEngine​(org.w3c.dom.Element e)
        Returns CSSEngine associated to the specified element.
        Parameters:
        e - the element
      • getComputedStyle

        public static Value getComputedStyle​(org.w3c.dom.Element e,
                                             int property)
        Returns the computed style of the given property.
      • convertPointerEvents

        public static int convertPointerEvents​(org.w3c.dom.Element e)
        Returns the type that describes how this graphics node reacts to events.
        Returns:
        GraphicsNode.VISIBLE_PAINTED | GraphicsNode.VISIBLE_FILL | GraphicsNode.VISIBLE_STROKE | GraphicsNode.VISIBLE | GraphicsNode.PAINTED | GraphicsNode.FILL | GraphicsNode.STROKE | GraphicsNode.ALL | GraphicsNode.NONE
      • convertEnableBackground

        public static java.awt.geom.Rectangle2D convertEnableBackground​(org.w3c.dom.Element e)
        Returns the subregion of user space where access to the background image is allowed to happen.
        Parameters:
        e - the container element
      • convertColorInterpolationFilters

        public static boolean convertColorInterpolationFilters​(org.w3c.dom.Element e)
        Returns the color space for the specified filter element. Checks the 'color-interpolation-filters' property.
        Parameters:
        e - the element
        Returns:
        true if the color space is linear, false otherwise (sRGB).
      • convertColorInterpolation

        public static MultipleGradientPaint.ColorSpaceEnum convertColorInterpolation​(org.w3c.dom.Element e)
        Returns the color space for the specified element. Checks the 'color-interpolation' property
        Parameters:
        e - the element
      • isAutoCursor

        public static boolean isAutoCursor​(org.w3c.dom.Element e)
        Checks if the cursor property on the input element is set to auto
      • convertCursor

        public static java.awt.Cursor convertCursor​(org.w3c.dom.Element e,
                                                    BridgeContext ctx)
        Returns the Cursor corresponding to the input element's cursor property
        Parameters:
        e - the element
      • convertShapeRendering

        public static java.awt.RenderingHints convertShapeRendering​(org.w3c.dom.Element e,
                                                                    java.awt.RenderingHints hints)
        Fills the rendering hints for the specified shape element or do nothing none has been specified. Checks the 'shape-rendering' property. If the given RenderingHints is null, a new RenderingHints is created.

        Here is how the mapping between SVG rendering hints and the Java2D rendering hints is done:

        'optimizeSpeed':
        • KEY_RENDERING=VALUE_RENDER_SPEED
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_OFF
        'crispEdges':
        • KEY_RENDERING=VALUE_RENDER_DEFAULT
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_OFF
        'geometricPrecision':
        • KEY_RENDERING=VALUE_RENDER_QUALITY
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_ON
        Parameters:
        e - the element
        hints - a RenderingHints to fill, or null.
      • convertTextRendering

        public static java.awt.RenderingHints convertTextRendering​(org.w3c.dom.Element e,
                                                                   java.awt.RenderingHints hints)
        Fills the rendering hints for the specified text element or do nothing if none has been specified. If the given RenderingHints is null, a new one is created. Checks the 'text-rendering' property.

        Here is how the mapping between SVG rendering hints and the Java2D rendering hints is done:

        'optimizeSpeed':
        • KEY_RENDERING=VALUE_RENDER_SPEED
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_OFF
        • KEY_TEXT_ANTIALIASING=VALUE_TEXT_ANTIALIAS_OFF
        • KEY_FRACTIONALMETRICS=VALUE_FRACTIONALMETRICS_OFF
        'optimizeLegibility':
        • KEY_RENDERING=VALUE_RENDER_QUALITY
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_ON
        • KEY_TEXT_ANTIALIASING=VALUE_TEXT_ANTIALIAS_ON
        • KEY_FRACTIONALMETRICS=VALUE_FRACTIONALMETRICS_OFF
        'geometricPrecision':
        • KEY_RENDERING=VALUE_RENDER_QUALITY
        • KEY_ANTIALIASING=VALUE_ANTIALIAS_DEFAULT
        • KEY_TEXT_ANTIALIASING=VALUE_TEXT_ANTIALIAS_DEFAULT
        • KEY_FRACTIONALMETRICS=VALUE_FRACTIONALMETRICS_ON

        Note that for text both KEY_TEXT_ANTIALIASING and KEY_ANTIALIASING are set as there is no guarantee that a Java2D text rendering primitive will be used to draw text (eg. SVG Font...).

        Parameters:
        e - the element
        hints - a RenderingHints to fill, or null.
      • convertImageRendering

        public static java.awt.RenderingHints convertImageRendering​(org.w3c.dom.Element e,
                                                                    java.awt.RenderingHints hints)
        Fills the rendering hints for the specified image element or do nothing if none has been specified. If the given RenderingHints is null, a new one is created. Checks the 'image-rendering' property.

        Here is how the mapping between SVG rendering hints and the Java2D rendering hints is done:

        'optimizeSpeed':
        • KEY_RENDERING=VALUE_RENDER_SPEED
        • KEY_INTERPOLATION=VALUE_INTERPOLATION_NEAREST_NEIGHBOR
        'optimizeQuality':
        • KEY_RENDERING=VALUE_RENDER_QUALITY
        • KEY_INTERPOLATION=VALUE_INTERPOLATION_BICUBIC
        Parameters:
        e - the element
        hints - a RenderingHints to fill, or null.
      • convertColorRendering

        public static java.awt.RenderingHints convertColorRendering​(org.w3c.dom.Element e,
                                                                    java.awt.RenderingHints hints)
        Fills the rendering hints for the specified element or do nothing if none has been specified. If the given RenderingHints is null, a new one is created. Checks the 'color-rendering' property.

        Here is how the mapping between SVG rendering hints and the Java2D rendering hints is done:

        'optimizeSpeed':
        • KEY_COLOR_RENDERING=VALUE_COLOR_RENDER_SPEED
        • KEY_ALPHA_INTERPOLATION=VALUE_ALPHA_INTERPOLATION_SPEED
        'optimizeQuality':
        • KEY_COLOR_RENDERING=VALUE_COLOR_RENDER_QUALITY
        • KEY_ALPHA_INTERPOLATION=VALUE_ALPHA_INTERPOLATION_QUALITY
        Parameters:
        e - the element
        hints - a RenderingHints to fill, or null.
      • convertDisplay

        public static boolean convertDisplay​(org.w3c.dom.Element e)
        Returns true if the specified element has to be displayed, false otherwise. Checks the 'display' property.
        Parameters:
        e - the element
      • convertVisibility

        public static boolean convertVisibility​(org.w3c.dom.Element e)
        Returns true if the specified element is visible, false otherwise. Checks the 'visibility' property.
        Parameters:
        e - the element
      • convertOpacity

        public static java.awt.Composite convertOpacity​(org.w3c.dom.Element e)
        Returns a composite object that represents the 'opacity' of the specified element.
        Parameters:
        e - the element
      • convertOverflow

        public static boolean convertOverflow​(org.w3c.dom.Element e)
        Returns true if the 'overflow' property indicates that an additional clip is required, false otherwise. An additional clip is needed if the 'overflow' property is 'scroll' or 'hidden'.
        Parameters:
        e - the element with the 'overflow' property
      • convertClip

        public static float[] convertClip​(org.w3c.dom.Element e)
        Returns an array of floating offsets representing the 'clip' property or null if 'auto'. The offsets are specified in the order top, right, bottom, left.
        Parameters:
        e - the element with the 'clip' property
      • convertFilter

        public static Filter convertFilter​(org.w3c.dom.Element filteredElement,
                                           GraphicsNode filteredNode,
                                           BridgeContext ctx)
        Returns a Filter referenced by the specified element and which applies on the specified graphics node. Handle the 'filter' property.
        Parameters:
        filteredElement - the element that references the filter
        filteredNode - the graphics node associated to the element to filter.
        ctx - the bridge context
      • convertClipPath

        public static ClipRable convertClipPath​(org.w3c.dom.Element clippedElement,
                                                GraphicsNode clippedNode,
                                                BridgeContext ctx)
        Returns a Clip referenced by the specified element and which applies on the specified graphics node. Handle the 'clip-path' property.
        Parameters:
        clippedElement - the element that references the clip
        clippedNode - the graphics node associated to the element to clip
        ctx - the bridge context
      • convertClipRule

        public static int convertClipRule​(org.w3c.dom.Element e)
        Returns the 'clip-rule' for the specified element.
        Parameters:
        e - the element interested in its a 'clip-rule'
        Returns:
        GeneralPath.WIND_NON_ZERO | GeneralPath.WIND_EVEN_ODD
      • convertMask

        public static Mask convertMask​(org.w3c.dom.Element maskedElement,
                                       GraphicsNode maskedNode,
                                       BridgeContext ctx)
        Returns a Mask referenced by the specified element and which applies on the specified graphics node. Handle the 'mask' property.
        Parameters:
        maskedElement - the element that references the mask
        maskedNode - the graphics node associated to the element to mask
        ctx - the bridge context
      • convertFillRule

        public static int convertFillRule​(org.w3c.dom.Element e)
        Returns the 'fill-rule' for the specified element.
        Parameters:
        e - the element interested in its a 'fill-rule'
        Returns:
        GeneralPath.WIND_NON_ZERO | GeneralPath.WIND_EVEN_ODD
      • convertLightingColor

        public static java.awt.Color convertLightingColor​(org.w3c.dom.Element e,
                                                          BridgeContext ctx)
        Converts the color defined on the specified lighting filter element to a Color.
        Parameters:
        e - the lighting filter element
        ctx - the bridge context
      • convertFloodColor

        public static java.awt.Color convertFloodColor​(org.w3c.dom.Element e,
                                                       BridgeContext ctx)
        Converts the color defined on the specified <feFlood> element to a Color.
        Parameters:
        e - the feFlood element
        ctx - the bridge context
      • convertStopColor

        public static java.awt.Color convertStopColor​(org.w3c.dom.Element e,
                                                      float opacity,
                                                      BridgeContext ctx)
        Converts the color defined on the specified <stop> element to a Color.
        Parameters:
        e - the stop element
        opacity - the paint opacity
        ctx - the bridge context to use
      • computeStyleAndURIs

        public static void computeStyleAndURIs​(org.w3c.dom.Element refElement,
                                               org.w3c.dom.Element localRefElement,
                                               java.lang.String uri)
        Partially computes the style in the 'def' tree and set it in the 'use' tree.

        Note: This method must be called only when 'use' has been added to the DOM tree.

        Parameters:
        refElement - the referenced element
        localRefElement - the referenced element in the current document
      • rule

        protected static int rule​(org.w3c.dom.css.CSSValue v)
        Returns the winding rule represented by the specified CSSValue.
        Parameters:
        v - the value that represents the rule
        Returns:
        GeneralPath.WIND_NON_ZERO | GeneralPath.WIND_EVEN_ODD