org.apache.batik.bridge
Class UnitProcessor

java.lang.Object
  |
  +--org.apache.batik.bridge.UnitProcessor

public abstract class UnitProcessor
extends java.lang.Object

This class provides methods to convert SVG length and coordinate to float in user units.


Inner Class Summary
static interface UnitProcessor.Context
          Holds the informations needed to compute the units.
static class UnitProcessor.DefaultContext
          This class is the default context for a particular element.
static class UnitProcessor.UnitResolver
          A LengthHandler that convert units.
 
Field Summary
static short HORIZONTAL_LENGTH
          This constant represents horizontal lengths.
static short OTHER_LENGTH
          This constant represents other lengths.
static short VERTICAL_LENGTH
          This constant represents vertical lengths.
 
Constructor Summary
protected UnitProcessor()
          No instance of this class is required.
 
Method Summary
static UnitProcessor.Context createContext(BridgeContext ctx, Element e)
          Creates a context for the specified element.
static float cssHorizontalCoordinateToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the horizontal coordinate in user units.
static float cssHorizontalLengthToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the horizontal length in user units.
static float cssLengthToUserSpace(float v, java.lang.String prop, short type, short d, UnitProcessor.Context ctx)
          Converts the specified value of the specified type and direction to user units.
static float cssOtherCoordinateToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the other coordinate value in user units.
static float cssOtherLengthToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the other length value in user units.
static float cssToUserSpace(float v, short type, short d, UnitProcessor.Context ctx)
          Converts the specified value of the specified type and direction to user units.
static float cssVerticalCoordinateToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the vertical coordinate in user units.
static float cssVerticalLengthToUserSpace(CSSValue v, java.lang.String prop, UnitProcessor.Context ctx)
          Returns the vertical length in user units.
protected static float emsToPixels(float v, short d, UnitProcessor.Context ctx)
          Converts ems units to user units.
protected static float exsToPixels(float v, short d, UnitProcessor.Context ctx)
          Converts exs units to user units.
protected static float percentagesToPixels(float v, short d, UnitProcessor.Context ctx)
          Converts percentages to user units.
protected static float pixelsToEms(float v, short d, UnitProcessor.Context ctx)
          Converts user units to ems units.
protected static float pixelsToExs(float v, short d, UnitProcessor.Context ctx)
          Converts user units to exs units.
protected static float pixelsToPercentages(float v, short d, UnitProcessor.Context ctx)
          Converts user units to percentages relative to the viewport.
static float svgHorizontalCoordinateToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified horizontal coordinate in object bounding box coordinate system.
static float svgHorizontalCoordinateToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified horizontal coordinate in user units.
static float svgHorizontalLengthToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified horizontal length in object bounding box coordinate system.
static float svgHorizontalLengthToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified horizontal length in user units.
static float svgLengthToObjectBoundingBox(java.lang.String s, java.lang.String attr, short d, UnitProcessor.Context ctx)
          Returns the specified length with the specified direction in user units.
static float svgLengthToUserSpace(java.lang.String s, java.lang.String attr, short d, UnitProcessor.Context ctx)
          Returns the specified length with the specified direction in user units.
static float svgOtherCoordinateToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified 'other' coordinate in object bounding box coordinate system.
static float svgOtherCoordinateToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified 'other' coordinate in user units.
static float svgOtherLengthToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified 'other' length in object bounding box coordinate system.
static float svgOtherLengthToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified 'other' length in user units.
static float svgToObjectBoundingBox(float value, short type, short d, UnitProcessor.Context ctx)
          Returns the specified value with the specified direction in objectBoundingBox units.
static float svgToObjectBoundingBox(java.lang.String s, java.lang.String attr, short d, UnitProcessor.Context ctx)
          Returns the specified value with the specified direction in objectBoundingBox units.
static float svgToUserSpace(float v, short type, short d, UnitProcessor.Context ctx)
          Converts the specified value of the specified type and direction to user units.
static float svgToUserSpace(java.lang.String s, java.lang.String attr, short d, UnitProcessor.Context ctx)
          Returns the specified coordinate with the specified direction in user units.
static float svgVerticalCoordinateToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified vertical coordinate in object bounding box coordinate system.
static float svgVerticalCoordinateToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified vertical coordinate in user units.
static float svgVerticalLengthToObjectBoundingBox(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified vertical length in object bounding box coordinate system.
static float svgVerticalLengthToUserSpace(java.lang.String s, java.lang.String attr, UnitProcessor.Context ctx)
          Returns the specified vertical length in user units.
static float userSpaceToSVG(float v, short type, short d, UnitProcessor.Context ctx)
          Converts the specified value of the specified type and direction to SVG units.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HORIZONTAL_LENGTH

public static final short HORIZONTAL_LENGTH
This constant represents horizontal lengths.

VERTICAL_LENGTH

public static final short VERTICAL_LENGTH
This constant represents vertical lengths.

OTHER_LENGTH

public static final short OTHER_LENGTH
This constant represents other lengths.
Constructor Detail

UnitProcessor

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

createContext

public static UnitProcessor.Context createContext(BridgeContext ctx,
                                                  Element e)
Creates a context for the specified element.
Parameters:
ctx - the bridge context that contains the user agent and viewport definition
e - the element interested in its context

svgHorizontalCoordinateToObjectBoundingBox

public static float svgHorizontalCoordinateToObjectBoundingBox(java.lang.String s,
                                                               java.lang.String attr,
                                                               UnitProcessor.Context ctx)
Returns the specified horizontal coordinate in object bounding box coordinate system.
Parameters:
s - the horizontal coordinate
attr - the attribute name that represents the coordinate
ctx - the context used to resolve relative value

svgVerticalCoordinateToObjectBoundingBox

public static float svgVerticalCoordinateToObjectBoundingBox(java.lang.String s,
                                                             java.lang.String attr,
                                                             UnitProcessor.Context ctx)
Returns the specified vertical coordinate in object bounding box coordinate system.
Parameters:
s - the vertical coordinate
attr - the attribute name that represents the coordinate
ctx - the context used to resolve relative value

svgOtherCoordinateToObjectBoundingBox

public static float svgOtherCoordinateToObjectBoundingBox(java.lang.String s,
                                                          java.lang.String attr,
                                                          UnitProcessor.Context ctx)
Returns the specified 'other' coordinate in object bounding box coordinate system.
Parameters:
s - the 'other' coordinate
attr - the attribute name that represents the coordinate
ctx - the context used to resolve relative value

svgHorizontalLengthToObjectBoundingBox

public static float svgHorizontalLengthToObjectBoundingBox(java.lang.String s,
                                                           java.lang.String attr,
                                                           UnitProcessor.Context ctx)
Returns the specified horizontal length in object bounding box coordinate system. A length must be greater than 0.
Parameters:
s - the 'other' length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgVerticalLengthToObjectBoundingBox

public static float svgVerticalLengthToObjectBoundingBox(java.lang.String s,
                                                         java.lang.String attr,
                                                         UnitProcessor.Context ctx)
Returns the specified vertical length in object bounding box coordinate system. A length must be greater than 0.
Parameters:
s - the vertical length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgOtherLengthToObjectBoundingBox

public static float svgOtherLengthToObjectBoundingBox(java.lang.String s,
                                                      java.lang.String attr,
                                                      UnitProcessor.Context ctx)
Returns the specified 'other' length in object bounding box coordinate system. A length must be greater than 0.
Parameters:
s - the 'other' length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgLengthToObjectBoundingBox

public static float svgLengthToObjectBoundingBox(java.lang.String s,
                                                 java.lang.String attr,
                                                 short d,
                                                 UnitProcessor.Context ctx)
Returns the specified length with the specified direction in user units. A length must be greater than 0.
Parameters:
s - the length
attr - the attribute name that represents the length
d - the direction of the length
ctx - the context used to resolve relative value

svgToObjectBoundingBox

public static float svgToObjectBoundingBox(java.lang.String s,
                                           java.lang.String attr,
                                           short d,
                                           UnitProcessor.Context ctx)
Returns the specified value with the specified direction in objectBoundingBox units.
Parameters:
s - the value
attr - the attribute name that represents the value
d - the direction of the value
ctx - the context used to resolve relative value

svgToObjectBoundingBox

public static float svgToObjectBoundingBox(float value,
                                           short type,
                                           short d,
                                           UnitProcessor.Context ctx)
Returns the specified value with the specified direction in objectBoundingBox units.
Parameters:
s - the value
type - the type of the value
d - the direction of the value
ctx - the context used to resolve relative value

svgHorizontalLengthToUserSpace

public static float svgHorizontalLengthToUserSpace(java.lang.String s,
                                                   java.lang.String attr,
                                                   UnitProcessor.Context ctx)
Returns the specified horizontal length in user units. A length must be greater than 0.
Parameters:
s - the horizontal length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgVerticalLengthToUserSpace

public static float svgVerticalLengthToUserSpace(java.lang.String s,
                                                 java.lang.String attr,
                                                 UnitProcessor.Context ctx)
Returns the specified vertical length in user units. A length must be greater than 0.
Parameters:
s - the vertical length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgOtherLengthToUserSpace

public static float svgOtherLengthToUserSpace(java.lang.String s,
                                              java.lang.String attr,
                                              UnitProcessor.Context ctx)
Returns the specified 'other' length in user units. A length must be greater than 0.
Parameters:
s - the 'other' length
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgHorizontalCoordinateToUserSpace

public static float svgHorizontalCoordinateToUserSpace(java.lang.String s,
                                                       java.lang.String attr,
                                                       UnitProcessor.Context ctx)
Returns the specified horizontal coordinate in user units.
Parameters:
s - the horizontal coordinate
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgVerticalCoordinateToUserSpace

public static float svgVerticalCoordinateToUserSpace(java.lang.String s,
                                                     java.lang.String attr,
                                                     UnitProcessor.Context ctx)
Returns the specified vertical coordinate in user units.
Parameters:
s - the vertical coordinate
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgOtherCoordinateToUserSpace

public static float svgOtherCoordinateToUserSpace(java.lang.String s,
                                                  java.lang.String attr,
                                                  UnitProcessor.Context ctx)
Returns the specified 'other' coordinate in user units.
Parameters:
s - the 'other' coordinate
attr - the attribute name that represents the length
ctx - the context used to resolve relative value

svgLengthToUserSpace

public static float svgLengthToUserSpace(java.lang.String s,
                                         java.lang.String attr,
                                         short d,
                                         UnitProcessor.Context ctx)
Returns the specified length with the specified direction in user units. A length must be greater than 0.
Parameters:
s - the 'other' coordinate
attr - the attribute name that represents the length
d - the direction of the length
ctx - the context used to resolve relative value

svgToUserSpace

public static float svgToUserSpace(java.lang.String s,
                                   java.lang.String attr,
                                   short d,
                                   UnitProcessor.Context ctx)
Returns the specified coordinate with the specified direction in user units.
Parameters:
s - the 'other' coordinate
attr - the attribute name that represents the length
d - the direction of the coordinate
ctx - the context used to resolve relative value

svgToUserSpace

public static float svgToUserSpace(float v,
                                   short type,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts the specified value of the specified type and direction to user units.
Parameters:
v - the value to convert
type - the type of the value
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context used to resolve relative value

userSpaceToSVG

public static float userSpaceToSVG(float v,
                                   short type,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts the specified value of the specified type and direction to SVG units.
Parameters:
v - the value to convert
type - the type of the value
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context used to resolve relative value

cssOtherCoordinateToUserSpace

public static float cssOtherCoordinateToUserSpace(CSSValue v,
                                                  java.lang.String prop,
                                                  UnitProcessor.Context ctx)
Returns the other coordinate value in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssHorizontalCoordinateToUserSpace

public static float cssHorizontalCoordinateToUserSpace(CSSValue v,
                                                       java.lang.String prop,
                                                       UnitProcessor.Context ctx)
Returns the horizontal coordinate in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssVerticalCoordinateToUserSpace

public static float cssVerticalCoordinateToUserSpace(CSSValue v,
                                                     java.lang.String prop,
                                                     UnitProcessor.Context ctx)
Returns the vertical coordinate in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssOtherLengthToUserSpace

public static float cssOtherLengthToUserSpace(CSSValue v,
                                              java.lang.String prop,
                                              UnitProcessor.Context ctx)
Returns the other length value in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssHorizontalLengthToUserSpace

public static float cssHorizontalLengthToUserSpace(CSSValue v,
                                                   java.lang.String prop,
                                                   UnitProcessor.Context ctx)
Returns the horizontal length in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssVerticalLengthToUserSpace

public static float cssVerticalLengthToUserSpace(CSSValue v,
                                                 java.lang.String prop,
                                                 UnitProcessor.Context ctx)
Returns the vertical length in user units. The value must be a CSSPrimitiveValue and the type of the value will be the one defined in the CSSPrimitiveValue.
Parameters:
v - the value to convert
prop - the CSS property
ctx - the context used to resolve relative value

cssLengthToUserSpace

public static float cssLengthToUserSpace(float v,
                                         java.lang.String prop,
                                         short type,
                                         short d,
                                         UnitProcessor.Context ctx)
Converts the specified value of the specified type and direction to user units.
Parameters:
v - the value to convert
prop - the CSS property
type - the type of the value
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context used to resolve relative value

cssToUserSpace

public static float cssToUserSpace(float v,
                                   short type,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts the specified value of the specified type and direction to user units.
Parameters:
v - the value to convert
type - the type of the value
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context used to resolve relative value

percentagesToPixels

protected static float percentagesToPixels(float v,
                                           short d,
                                           UnitProcessor.Context ctx)
Converts percentages to user units.
Parameters:
v - the percentage to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context

pixelsToPercentages

protected static float pixelsToPercentages(float v,
                                           short d,
                                           UnitProcessor.Context ctx)
Converts user units to percentages relative to the viewport.
Parameters:
v - the value to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context

pixelsToEms

protected static float pixelsToEms(float v,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts user units to ems units.
Parameters:
v - the value to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context

emsToPixels

protected static float emsToPixels(float v,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts ems units to user units.
Parameters:
v - the value to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context

pixelsToExs

protected static float pixelsToExs(float v,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts user units to exs units.
Parameters:
v - the value to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context

exsToPixels

protected static float exsToPixels(float v,
                                   short d,
                                   UnitProcessor.Context ctx)
Converts exs units to user units.
Parameters:
v - the value to convert
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH, or OTHER_LENGTH
ctx - the context


Copyright © 2001 Apache Software Foundation. All Rights Reserved.