org.foray.fotree.value
Class DtLength

java.lang.Object
  extended by org.foray.fotree.value.Expr
      extended by org.foray.fotree.value.ExprAdditive
          extended by org.foray.fotree.value.ExprMultiplicative
              extended by org.foray.fotree.value.ExprUnary
                  extended by org.foray.fotree.value.ExprPrimary
                      extended by org.foray.fotree.value.Datatype
                          extended by org.foray.fotree.value.DtLength
All Implemented Interfaces:
PropertyValue

public class DtLength
extends Datatype

A "length" property datatype in XSL-FO. Members of this class are immutable.


Field Summary
static String[] UNIT_ARRAY
          Array of valid string descriptions for length units.
static byte UNIT_CENTIMETERS
          Constant indicating units of "centimeters".
static byte UNIT_EMS
          Constant indicating units of "ems".
static byte UNIT_INCHES
          Constant indicating units of "inches".
static byte UNIT_MILLIMETERS
          Constant indicating units of "millimeters".
static byte UNIT_PICAS
          Constant indicating units of "picas".
static byte UNIT_PIXELS
          Constant indicating units of "pixels".
static byte UNIT_POINTS
          Constant indicating units of "points".
static DtLength ZERO_LENGTH
          A property value that evaluates to a length of zero, suitable for use as a default.
 
Fields inherited from class org.foray.fotree.value.Expr
OPERATION_ADD, OPERATION_DIVIDE, OPERATION_MOD, OPERATION_MULTIPLY, OPERATION_NEGATION, OPERATION_SUBTRACT, UNIT_POWER_AREA, UNIT_POWER_LENGTH, UNIT_POWER_NON_NUMERIC, UNIT_POWER_NUMERIC
 
Constructor Summary
DtLength(float value, String units)
          Constructor.
 
Method Summary
 boolean canEvalColor()
          Indicates whether this property value has the ability to express itself as a Color.
 boolean canEvalInteger()
          Indicates whether this property value has the ability to express itself as an integer Numeric item.
 boolean canEvalKeyword()
          Indicates whether this property value can evaluate to a keyword.
 boolean canEvalLength()
          Indicates whether this expression can be evaluated to a unit power = 1 (length) or not.
 boolean canEvalNumeric()
          Indicates whether this property value has the ability to express itself as a Numeric item.
 boolean canEvalPercentage()
          Indicates whether this property value can evaluate to a percentage.
static byte convertUnits(String units)
          Converts a String unit descriptor to its internal byte equivalent.
 Color evalColor()
          Return the color value of "this".
 int evalInteger()
          Return this value as an int.
 PvKeyword evalKeyword()
          Returns the keyword value of this property value.
 int evalLength(int pointSize)
          Evaluates the expression to a unit power of 1 (length).
 double evalNumeric()
          Return the raw numeric value of "this", without regard to unit power.
 float evalPercentage()
          Returns the percentage value of this property value.
 byte getUnitPower()
          Each numeric has a "unit power".
 int getValue(int fontSize)
          Return the value.
 boolean lengthRequiresFontSize()
          Indicates whether the computation of the length will require an accurate font-size parameter.
static DtLength makeLengthDT(String input)
          Factory method for creating a LengthDT instance from a String.
 boolean needsFontSize()
          Indicates whether this length requires a font-size to compute its value.
 
Methods inherited from class org.foray.fotree.value.Datatype
convertValueToFoValue
 
Methods inherited from class org.foray.fotree.value.Expr
evalColorException, evalIntegerException, evalKeywordException, evalLengthException, evalNumericException, evalPercentageException
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNIT_ARRAY

public static final String[] UNIT_ARRAY
Array of valid string descriptions for length units.


UNIT_INCHES

public static final byte UNIT_INCHES
Constant indicating units of "inches".

See Also:
Constant Field Values

UNIT_CENTIMETERS

public static final byte UNIT_CENTIMETERS
Constant indicating units of "centimeters".

See Also:
Constant Field Values

UNIT_MILLIMETERS

public static final byte UNIT_MILLIMETERS
Constant indicating units of "millimeters".

See Also:
Constant Field Values

UNIT_POINTS

public static final byte UNIT_POINTS
Constant indicating units of "points".

See Also:
Constant Field Values

UNIT_PICAS

public static final byte UNIT_PICAS
Constant indicating units of "picas".

See Also:
Constant Field Values

UNIT_PIXELS

public static final byte UNIT_PIXELS
Constant indicating units of "pixels".

See Also:
Constant Field Values

UNIT_EMS

public static final byte UNIT_EMS
Constant indicating units of "ems".

See Also:
Constant Field Values

ZERO_LENGTH

public static final DtLength ZERO_LENGTH
A property value that evaluates to a length of zero, suitable for use as a default.

Constructor Detail

DtLength

public DtLength(float value,
                String units)
Constructor.

Parameters:
value - The signed length value.
units - A byte representation of the unit of measure (points, inches, etc.)
Method Detail

getValue

public int getValue(int fontSize)
Return the value.

Parameters:
fontSize - The font-size, in millipoints. This is used for "em" computations. In environments where computing the font-size is expensive, check needsFontSize() first before computing it. If it returns false, zero or some other constant can safely be passed, as the value will not be used anyway.
Returns:
The value of this length in millipoints.

convertUnits

public static byte convertUnits(String units)
Converts a String unit descriptor to its internal byte equivalent.

Parameters:
units - The String descriptor of the units.
Returns:
The byte equivalent.

canEvalNumeric

public boolean canEvalNumeric()
Description copied from interface: PropertyValue
Indicates whether this property value has the ability to express itself as a Numeric item.

Returns:
True iff this property value is a numeric.

evalNumeric

public double evalNumeric()
Description copied from interface: PropertyValue
Return the raw numeric value of "this", without regard to unit power.

Returns:
A double representation of the value of "this". Type "double" is assumed to be the lowest-common-denominator of all numeric values.

getUnitPower

public byte getUnitPower()
Description copied from interface: PropertyValue
Each numeric has a "unit power". This number refers to the number of spatial dimensions in which the number operates. So, a number that has no relationship to space or refers to a point, has a length power of 0. A number that refers to length has a length power of 1 (1 dimension). Although there are none yet in XSL-FO, a number that referred to area (e.g. square inches) would, we suppose, have a length power of 2, and one referring to volume (e.g. cubic feet) would, we suppose have a length power of 3.

Returns:
The number of spatial dimensions in which this numeric item operates. For XSL-FO items, this should be either Expr.UNIT_POWER_NUMERIC or Expr.UNIT_POWER_LENGTH.

makeLengthDT

public static DtLength makeLengthDT(String input)
Factory method for creating a LengthDT instance from a String.

Parameters:
input - The string from which a LengthDT instance should be created.
Returns:
A LengthDT instance, or null if input is not valid.

canEvalLength

public boolean canEvalLength()
Description copied from interface: PropertyValue
Indicates whether this expression can be evaluated to a unit power = 1 (length) or not.

Returns:
True if the expression can be evaluated to a unit power of 1 (length).

evalLength

public int evalLength(int pointSize)
Description copied from interface: PropertyValue
Evaluates the expression to a unit power of 1 (length).

Parameters:
pointSize - The point size, in millipoints, of the font. This is used in calculations that are relative to the point size. In cases where the computation of the font-size is expensive, check PropertyValue.lengthRequiresFontSize() first. If that method returns false, zero or some other constant can safely be passed, as it will be ignored anyway.
Returns:
The unit power 1 value (length) of this expression if the expression can be so evaluated, or Integer.MIN_VALUE otherwise. The value is expressed in millipoints.

lengthRequiresFontSize

public boolean lengthRequiresFontSize()
Description copied from interface: PropertyValue
Indicates whether the computation of the length will require an accurate font-size parameter.

Returns:
True iff the computation of the length will require an accurate font-size parameter.

needsFontSize

public boolean needsFontSize()
Indicates whether this length requires a font-size to compute its value. In environments where computing the font-size is expensive, checking this method first can avoid that cost.

Returns:
True iff this length requires a font-size to compute its value.

canEvalColor

public boolean canEvalColor()
Description copied from interface: PropertyValue
Indicates whether this property value has the ability to express itself as a Color.

Returns:
True iff this property value is a color.

evalColor

public Color evalColor()
Description copied from interface: PropertyValue
Return the color value of "this".

Returns:
The color representation of the value of "this".

canEvalInteger

public boolean canEvalInteger()
Description copied from interface: PropertyValue
Indicates whether this property value has the ability to express itself as an integer Numeric item.

Returns:
True iff this property value is an integer.

evalInteger

public int evalInteger()
Description copied from interface: PropertyValue
Return this value as an int. This method should only be executed on instances where PropertyValue.canEvalInteger() returns true. Doing so on other instances may result in an IllegalStateException.

Returns:
This value as an int.

canEvalKeyword

public boolean canEvalKeyword()
Description copied from interface: PropertyValue
Indicates whether this property value can evaluate to a keyword.

Returns:
True iff this property value can evaluate to a keyword.

evalKeyword

public PvKeyword evalKeyword()
Description copied from interface: PropertyValue
Returns the keyword value of this property value. This method should only be executed on instances where PropertyValue.canEvalKeyword() returns true. Doing so on other instances may result in an IllegalStateException.

Returns:
The keyword value of this property value.

canEvalPercentage

public boolean canEvalPercentage()
Description copied from interface: PropertyValue
Indicates whether this property value can evaluate to a percentage.

Returns:
True iff this property value can evaluate to a percentage.

evalPercentage

public float evalPercentage()
Description copied from interface: PropertyValue
Returns the percentage value of this property value. This method should only be executed on instances where PropertyValue.canEvalPercentage() returns true. Doing so on other instances may result in an IllegalStateException.

Returns:
The percentage value of this property value.


Copyright © 2017. All rights reserved.