org.apache.batik.dom.svg
Class UnitProcessor

java.lang.Object
  |
  +--org.apache.batik.dom.svg.UnitProcessor

public abstract class UnitProcessor
extends java.lang.Object

This class contains utility methods for processing the SVG and CSS units.


Inner Class Summary
static interface UnitProcessor.Context
          Holds the informations needed to compute the units.
static class UnitProcessor.UnitResolver
          A simple class that can 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()
          This class does not need to be instantiated.
 
Method Summary
static float cssToUserSpace(short t, float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts a SVG length value to user space.
protected static float emsToPixels(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts ems units to pixels units.
protected static float exsToPixels(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts exs units to pixels units.
static CSSPrimitiveValue getFontSize(SVGElement e, CSSStyleDeclaration d)
          An utility method to implement Context.getFontSize(SVGElement e).
protected static float percentagesToPixels(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts percentages units to pixels units.
protected static float pixelsToEms(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts pixels units to ems units.
protected static float pixelsToExs(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts pixels units to exs units.
protected static float pixelsToPercentages(float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts percentages units to pixels units.
static float svgToUserSpace(short t, float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts a SVG length value to screen pixels.
static float svgToUserSpace(java.lang.String value, SVGElement e, short d, UnitProcessor.Context c)
          Converts a SVG length value to screen pixels.
static float userSpaceToSVG(short t, float v, SVGElement e, short d, UnitProcessor.Context c)
          Converts a SVG length value to screen pixels.
 
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()
This class does not need to be instantiated.
Method Detail

cssToUserSpace

public static float cssToUserSpace(short t,
                                   float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
                            throws java.lang.RuntimeException
Converts a SVG length value to user space.
Parameters:
t - the unit type like specified in the CSSPrimitiveType interface.
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

userSpaceToSVG

public static float userSpaceToSVG(short t,
                                   float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
                            throws java.lang.RuntimeException
Converts a SVG length value to screen pixels.
Parameters:
t - the unit type like specified in the SVGLength interface.
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

svgToUserSpace

public static float svgToUserSpace(short t,
                                   float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
                            throws java.lang.RuntimeException
Converts a SVG length value to screen pixels.
Parameters:
t - the unit type like specified in the SVGLength interface.
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

pixelsToEms

protected static float pixelsToEms(float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
Converts pixels units to ems units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

emsToPixels

protected static float emsToPixels(float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
Converts ems units to pixels units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

pixelsToExs

protected static float pixelsToExs(float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
Converts pixels units to exs units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

exsToPixels

protected static float exsToPixels(float v,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
Converts exs units to pixels units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

pixelsToPercentages

protected static float pixelsToPercentages(float v,
                                           SVGElement e,
                                           short d,
                                           UnitProcessor.Context c)
Converts percentages units to pixels units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

percentagesToPixels

protected static float percentagesToPixels(float v,
                                           SVGElement e,
                                           short d,
                                           UnitProcessor.Context c)
Converts percentages units to pixels units.
Parameters:
v - the length value.
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.

getFontSize

public static CSSPrimitiveValue getFontSize(SVGElement e,
                                            CSSStyleDeclaration d)
An utility method to implement Context.getFontSize(SVGElement e).

svgToUserSpace

public static float svgToUserSpace(java.lang.String value,
                                   SVGElement e,
                                   short d,
                                   UnitProcessor.Context c)
Converts a SVG length value to screen pixels.
Parameters:
value - the length value
e - the element.
d - HORIZONTAL_LENGTH, VERTICAL_LENGTH or OTHER_LENGTH.
c - The context.
Throws:
java.lang.RuntimeException - If an invalid unit type is specified.


Copyright © 2001 Apache Software Foundation. All Rights Reserved.