org.apache.batik.bridge

Class CSSUtilities

public abstract class CSSUtilities extends 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.
Field Summary
static CompositeTRANSPARENT
Constructor Summary
protected CSSUtilities()
No instance of this class is required.
Method Summary
static voidcomputeStyleAndURIs(Element refElement, Element localRefElement, String uri)
Partially computes the style in the 'def' tree and set it in the 'use' tree.
static float[]convertClip(Element e)
Returns an array of floating offsets representing the 'clip' property or null if 'auto'.
static ClipRableconvertClipPath(Element clippedElement, GraphicsNode clippedNode, BridgeContext ctx)
Returns a Clip referenced by the specified element and which applies on the specified graphics node.
static intconvertClipRule(Element e)
Returns the 'clip-rule' for the specified element.
static MultipleGradientPaint.ColorSpaceEnumconvertColorInterpolation(Element e)
Returns the color space for the specified element.
static booleanconvertColorInterpolationFilters(Element e)
Returns the color space for the specified filter element.
static RenderingHintsconvertColorRendering(Element e, RenderingHints hints)
Fills the rendering hints for the specified element or do nothing if none has been specified.
static CursorconvertCursor(Element e, BridgeContext ctx)
Returns the Cursor corresponding to the input element's cursor property
static booleanconvertDisplay(Element e)
Returns true if the specified element has to be displayed, false otherwise.
static Rectangle2DconvertEnableBackground(Element e)
Returns the subregion of user space where access to the background image is allowed to happen.
static intconvertFillRule(Element e)
Returns the 'fill-rule' for the specified element.
static FilterconvertFilter(Element filteredElement, GraphicsNode filteredNode, BridgeContext ctx)
Returns a Filter referenced by the specified element and which applies on the specified graphics node.
static ColorconvertFloodColor(Element e, BridgeContext ctx)
Converts the color defined on the specified <feFlood> element to a Color.
static RenderingHintsconvertImageRendering(Element e, RenderingHints hints)
Fills the rendering hints for the specified image element or do nothing if none has been specified.
static ColorconvertLightingColor(Element e, BridgeContext ctx)
Converts the color defined on the specified lighting filter element to a Color.
static MaskconvertMask(Element maskedElement, GraphicsNode maskedNode, BridgeContext ctx)
Returns a Mask referenced by the specified element and which applies on the specified graphics node.
static CompositeconvertOpacity(Element e)
Returns a composite object that represents the 'opacity' of the specified element.
static booleanconvertOverflow(Element e)
Returns true if the 'overflow' property indicates that an additional clip is required, false otherwise.
static intconvertPointerEvents(Element e)
Returns the type that describes how this graphics node reacts to events.
static RenderingHintsconvertShapeRendering(Element e, RenderingHints hints)
Fills the rendering hints for the specified shape element or do nothing none has been specified.
static ColorconvertStopColor(Element e, float opacity, BridgeContext ctx)
Converts the color defined on the specified <stop> element to a Color.
static RenderingHintsconvertTextRendering(Element e, RenderingHints hints)
Fills the rendering hints for the specified text element or do nothing if none has been specified.
static booleanconvertVisibility(Element e)
Returns true if the specified element is visible, false otherwise.
static ValuegetComputedStyle(Element e, int property)
Returns the computed style of the given property.
static CSSEnginegetCSSEngine(Element e)
Returns CSSEngine associated to the specified element.
static booleanisAutoCursor(Element e)
Checks if the cursor property on the input element is set to auto
protected static intrule(CSSValue v)
Returns the winding rule represented by the specified CSSValue.

Field Detail

TRANSPARENT

public static final Composite TRANSPARENT

Constructor Detail

CSSUtilities

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

Method Detail

computeStyleAndURIs

public static void computeStyleAndURIs(Element refElement, Element localRefElement, 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

convertClip

public static float[] convertClip(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

convertClipPath

public static ClipRable convertClipPath(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(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

convertColorInterpolation

public static MultipleGradientPaint.ColorSpaceEnum convertColorInterpolation(Element e)
Returns the color space for the specified element. Checks the 'color-interpolation' property

Parameters: e the element

convertColorInterpolationFilters

public static boolean convertColorInterpolationFilters(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).

convertColorRendering

public static RenderingHints convertColorRendering(Element e, 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.

convertCursor

public static Cursor convertCursor(Element e, BridgeContext ctx)
Returns the Cursor corresponding to the input element's cursor property

Parameters: e the element

convertDisplay

public static boolean convertDisplay(Element e)
Returns true if the specified element has to be displayed, false otherwise. Checks the 'display' property.

Parameters: e the element

convertEnableBackground

public static Rectangle2D convertEnableBackground(Element e)
Returns the subregion of user space where access to the background image is allowed to happen.

Parameters: e the container element

convertFillRule

public static int convertFillRule(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

convertFilter

public static Filter convertFilter(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

convertFloodColor

public static Color convertFloodColor(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

convertImageRendering

public static RenderingHints convertImageRendering(Element e, 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.

convertLightingColor

public static Color convertLightingColor(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

convertMask

public static Mask convertMask(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

convertOpacity

public static Composite convertOpacity(Element e)
Returns a composite object that represents the 'opacity' of the specified element.

Parameters: e the element

convertOverflow

public static boolean convertOverflow(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

convertPointerEvents

public static int convertPointerEvents(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

convertShapeRendering

public static RenderingHints convertShapeRendering(Element e, 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.

convertStopColor

public static Color convertStopColor(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

convertTextRendering

public static RenderingHints convertTextRendering(Element e, 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.

convertVisibility

public static boolean convertVisibility(Element e)
Returns true if the specified element is visible, false otherwise. Checks the 'visibility' property.

Parameters: e the element

getComputedStyle

public static Value getComputedStyle(Element e, int property)
Returns the computed style of the given property.

getCSSEngine

public static CSSEngine getCSSEngine(Element e)
Returns CSSEngine associated to the specified element.

Parameters: e the element

isAutoCursor

public static boolean isAutoCursor(Element e)
Checks if the cursor property on the input element is set to auto

rule

protected static int rule(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

Copyright B) 2007 Apache Software Foundation. All Rights Reserved.