de.dante.extex.interpreter.type.dimen
Class Dimen

java.lang.Object
  extended byde.dante.extex.interpreter.type.glue.GlueComponent
      extended byde.dante.extex.interpreter.type.dimen.Dimen
All Implemented Interfaces:
FixedDimen, FixedGlueComponent, java.io.Serializable
Direct Known Subclasses:
ImmutableDimen

public class Dimen
extends GlueComponent
implements java.io.Serializable, FixedDimen

This class implements the dimen value. This is a length with fixed point arithmetic.

Version:
$Revision: 1.36 $
Author:
Gerd Neugebauer, Michael Niedermair
See Also:
Serialized Form

Field Summary
static ImmutableDimen ONE_INCH
          The constant ONE_INCH contains the immutable dimen register representing the length of 1 in.
static ImmutableDimen ONE_PT
          The constant ONE_PT contains the immutable dimen register representing the length of 1 pt.
static ImmutableDimen ONE_SP
          The constant ONE_SP contains the immutable dimen register representing the length of 1 scaled point.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
static ImmutableDimen ZERO_PT
          The constant ZERO_PT contains the immutable dimen register representing the length of 0 pt.
 
Fields inherited from class de.dante.extex.interpreter.type.glue.GlueComponent
MINUS_ONE_FIL, ONE, ONE_FI, ONE_FIL, ONE_FILL, ZERO
 
Constructor Summary
Dimen()
          Creates a new object.
Dimen(FixedDimen value)
          Creates a new object.
Dimen(long value)
          Creates a new object.
 
Method Summary
 void abs(FixedDimen d)
          Set the value of this dimen to the absolute value of a given value.
 void add(FixedDimen d)
          Add the value of the argument to the current value.
 void add(long d)
          Add the value of the argument to the current value.
 void divide(long denom)
          Divide the current value with a given number.
protected  Localizer getLocalizer()
          Getter for the localizer.
 boolean isZero()
          Test for a value of zero.
 void max(FixedDimen d)
          Sets the value of the dimen to the maximum of the value already stored and a given argument.
 void min(FixedDimen d)
          Sets the value of the dimen to the minimum of the value already stored and a given argument.
 void multiply(long factor)
          Multiply the current value with a given number.
 void negate()
          Negate the value of the argument to the current value.
static Dimen parse(Context context, TokenSource source, Typesetter typesetter)
          Creates a new object from a token stream.
 void set(FixedGlueComponent d)
          Setter for the value.
 void subtract(FixedDimen d)
          Subtract the value of the argument from the current value.
 
Methods inherited from class de.dante.extex.interpreter.type.glue.GlueComponent
add, attachUnit, copy, eq, ge, getMyLocalizer, getOrder, getValue, gt, le, lt, multiply, ne, parse, parse, set, setValue, subtract, toString, toString, toString, toToks, toToks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.dante.extex.interpreter.type.glue.FixedGlueComponent
copy, eq, ge, getOrder, getValue, gt, le, lt, ne, toString, toString, toToks, toToks
 

Field Detail

ONE_INCH

public static final ImmutableDimen ONE_INCH
The constant ONE_INCH contains the immutable dimen register representing the length of 1 in.


ONE_PT

public static final ImmutableDimen ONE_PT
The constant ONE_PT contains the immutable dimen register representing the length of 1 pt.


ONE_SP

public static final ImmutableDimen ONE_SP
The constant ONE_SP contains the immutable dimen register representing the length of 1 scaled point.


serialVersionUID

protected static final long serialVersionUID
The constant serialVersionUID contains the id for serialization.

See Also:
Constant Field Values

ZERO_PT

public static final ImmutableDimen ZERO_PT
The constant ZERO_PT contains the immutable dimen register representing the length of 0 pt.

Constructor Detail

Dimen

public Dimen()
Creates a new object. The length stored in it is initialized to 0 pt.


Dimen

public Dimen(FixedDimen value)
Creates a new object. This method makes a new instance of the class with the same value as the given instance. I.e. it acts like clone().

Parameters:
value - the value to imitate

Dimen

public Dimen(long value)
Creates a new object. This method makes a new instance of the class with the given value.

Parameters:
value - the value to set
Method Detail

parse

public static Dimen parse(Context context,
                          TokenSource source,
                          Typesetter typesetter)
                   throws InterpreterException
Creates a new object from a token stream. This method parses the following syntactic entity:
    ⟨dimen⟩
      → ⟨float⟩ ⟨dimen unit⟩
       |  ⟨float⟩ true ⟨dimen unit⟩
       |  ⟨dimen variable⟩

    ⟨float⟩
      → [+-]? [0-9]+
      |  [+-]? [0-9]+[.][0-9]*
      |  [+-]? [.][0-9]+

    ⟨dimen unit⟩
      → pt | in | sp
      |  mm | cm | dm | km
      |  dd | cc | bp  

Parameters:
context - the interpreter context
source - the source for next tokens
typesetter - the typesetter
Returns:
a new instance with the value acquired
Throws:
InterpreterException - in case of an error

abs

public void abs(FixedDimen d)
Set the value of this dimen to the absolute value of a given value.

Parameters:
d - the given value

add

public void add(FixedDimen d)
Add the value of the argument to the current value. This operation modifies the instance.

|this| → |this| + |d|

Parameters:
d - the Dimen to add

add

public void add(long d)
Add the value of the argument to the current value. This operation modifies the instance.

|this| → |this| + |d|

Parameters:
d - the value to add in sp

divide

public void divide(long denom)
            throws ArithmeticOverflowException
Divide the current value with a given number. This operation modifies this instance.

|this| → |this| / denom

Parameters:
denom - denominator to divide by
Throws:
ArithmeticOverflowException - in case of a division by 0, i.e. if denom is 0.

getLocalizer

protected Localizer getLocalizer()
Getter for the localizer. The localizer is initialized from the name of the Dimen class.

Returns:
the localizer

isZero

public boolean isZero()
Test for a value of zero.

Returns:
true iff the value is 0

max

public void max(FixedDimen d)
Sets the value of the dimen to the maximum of the value already stored and a given argument. |this| = max(|this|, |d|)

Parameters:
d - the other dimen

min

public void min(FixedDimen d)
Sets the value of the dimen to the minimum of the value already stored and a given argument. |this| = min(|this|, |d|)

Parameters:
d - the other dimen

multiply

public void multiply(long factor)
Multiply the current value with a given number. This operation modifies this instance.

|this| → |this| * factor

Parameters:
factor - the factor to multiply with

negate

public void negate()
Negate the value of the argument to the current value. This operation modifies the instance.

|this| → - |this|

Overrides:
negate in class GlueComponent

set

public void set(FixedGlueComponent d)
Setter for the value. The order of the argument is ignored.

Overrides:
set in class GlueComponent
Parameters:
d - the new value

subtract

public void subtract(FixedDimen d)
Subtract the value of the argument from the current value. This operation modifies the instance.

|this| → |this| - |d|

Parameters:
d - the Dimen to subtract