de.dante.extex.interpreter.type.glue
Class GlueComponent

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

public class GlueComponent
extends java.lang.Object
implements java.io.Serializable, FixedGlueComponent

This class provides a means to store floating numbers with an order.

Examples

 123 pt
 -123 pt
 123.456 pt
 123.pt
 .465 pt
 -.456pt
 +456pt
 

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

Field Summary
static FixedGlueComponent MINUS_ONE_FIL
          The constant MINUS_ONE_FIL contains the value of -1 fil.
static long ONE
          The constant ONE contains the internal representation for 1pt.
static FixedGlueComponent ONE_FI
          The constant ONE_FI contains the value of 1 fi.
static FixedGlueComponent ONE_FIL
          The constant ONE_FIL contains the value of 1 fil.
static FixedGlueComponent ONE_FILL
          The constant ONE_FIL contains the value of 1 fill.
protected static long serialVersionUID
          The constant serialVersionUID contains the id for serialization.
static FixedGlueComponent ZERO
          The constant ZERO contains the non-stretchable and non-shrinkable value of 0 pt.
 
Constructor Summary
GlueComponent()
          Creates a new object.
GlueComponent(FixedGlueComponent component)
          Creates a new object with a fixed width.
GlueComponent(long theValue)
          Creates a new object with a fixed width.
GlueComponent(long theValue, int theOrder)
          Creates a new object with a width with a possibly higher order.
 
Method Summary
 void add(FixedGlueComponent g)
          Add another GlueCoponent g to this instance.
static GlueComponent attachUnit(long value, Context context, TokenSource source, Typesetter typesetter, boolean fixed)
          Convert a value by scanning a unit and storing its converted value in a GlueComponent.
 GlueComponent copy()
          Create a copy of this instance with the same order and value.
 boolean eq(FixedGlueComponent d)
          Compares the current instance with another GlueComponent for equality.
 boolean ge(FixedGlueComponent d)
          Compares the current instance with another GlueComponent.
protected static Localizer getMyLocalizer()
          Getter for the localizer.
 int getOrder()
          Getter for order.
 long getValue()
          Getter for the value in scaled points (sp).
 boolean gt(FixedGlueComponent d)
          Compares the current instance with another GlueComponent.
 boolean le(FixedGlueComponent d)
          Compares the current instance with another GlueComponent.
 boolean lt(FixedGlueComponent d)
          Compares the current instance with another GlueComponent.
 void multiply(long nom, long denom)
          Multiply the value by an integer fraction.
 boolean ne(FixedGlueComponent d)
          Compares the current instance with another GlueComponent for equality.
 void negate()
          Negate the value.
static GlueComponent parse(Context context, TokenSource source, Typesetter typesetter, boolean fixed)
          Creates a new object.
static GlueComponent parse(TokenSource source, Context context, Typesetter typesetter)
          Creates a new object from a TokenStream.
 void set(FixedGlueComponent d)
          Setter for the value and order.
 void set(long theValue)
          Setter for the value in terms of the internal representation.
 void setValue(long val)
          Setter for the value.
 void subtract(FixedGlueComponent g)
          Subtract a Glue component from this glue.
 java.lang.String toString()
          Determine the printable representation of the object.
 void toString(java.lang.StringBuffer sb)
          Determine the printable representation of the object and append it to the given StringBuffer.
 void toString(java.lang.StringBuffer sb, char c1, char c2)
          Determine the printable representation of the object and append it to the given StringBuffer.
 Tokens toToks(TokenFactory factory)
          Determine the printable representation of the object and return it as a list of Tokens.
 void toToks(Tokens toks, TokenFactory factory, char c1, char c2)
          Determine the printable representation of the object and return it as a list of Tokens.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE

public static final long ONE
The constant ONE contains the internal representation for 1pt.

See Also:
"TeX – The Program [101]", Constant Field Values

MINUS_ONE_FIL

public static final FixedGlueComponent MINUS_ONE_FIL
The constant MINUS_ONE_FIL contains the value of -1 fil.


ONE_FI

public static final FixedGlueComponent ONE_FI
The constant ONE_FI contains the value of 1 fi.


ONE_FIL

public static final FixedGlueComponent ONE_FIL
The constant ONE_FIL contains the value of 1 fil.


ONE_FILL

public static final FixedGlueComponent ONE_FILL
The constant ONE_FIL contains the value of 1 fill.


serialVersionUID

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

See Also:
Constant Field Values

ZERO

public static final FixedGlueComponent ZERO
The constant ZERO contains the non-stretchable and non-shrinkable value of 0 pt.

Constructor Detail

GlueComponent

public GlueComponent()
Creates a new object.


GlueComponent

public GlueComponent(FixedGlueComponent component)
Creates a new object with a fixed width.

Parameters:
component - the fixed value

GlueComponent

public GlueComponent(long theValue)
Creates a new object with a fixed width.

Parameters:
theValue - the fixed value

GlueComponent

public GlueComponent(long theValue,
                     int theOrder)
Creates a new object with a width with a possibly higher order.

Parameters:
theValue - the fixed width or the factor
theOrder - the order
Method Detail

getMyLocalizer

protected static Localizer getMyLocalizer()
Getter for the localizer. The localizer is associated with the name of the class GlueComponent.

Returns:
the localizer

parse

public static GlueComponent parse(Context context,
                                  TokenSource source,
                                  Typesetter typesetter,
                                  boolean fixed)
                           throws InterpreterException
Creates a new object.

Parameters:
context - the interpreter context
source - the source for the tokens to be read
typesetter - the typesetter
fixed - if true then no glue order is allowed
Returns:
a new instance with the value from the input stream
Throws:
InterpreterException - in case of an error

attachUnit

public static GlueComponent attachUnit(long value,
                                       Context context,
                                       TokenSource source,
                                       Typesetter typesetter,
                                       boolean fixed)
                                throws InterpreterException
Convert a value by scanning a unit and storing its converted value in a GlueComponent.

Parameters:
context - the interpreter context
source - the source for the tokens to be read
typesetter - the typesetter
fixed - if true then no glue order is allowed
value - the value to encapsulate
Returns:
the value converted into a GlueComponent or null if no suitable unit could be found
Throws:
InterpreterException - in case of an error

parse

public static GlueComponent parse(TokenSource source,
                                  Context context,
                                  Typesetter typesetter)
                           throws InterpreterException
Creates a new object from a TokenStream.

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

add

public void add(FixedGlueComponent g)
Add another GlueCoponent g to this instance. If the order of g is greater than the order of this instance then this operation does not change the value or order at all. If the order of g is less than the order of this instance then the value and order of g are stored in this instance. If the orders agree then the sum of both values is stored in this instance.

Parameters:
g - the GlueCoponent to add

copy

public GlueComponent copy()
Create a copy of this instance with the same order and value.

Specified by:
copy in interface FixedGlueComponent
Returns:
a new copy of this instance

eq

public boolean eq(FixedGlueComponent d)
Compares the current instance with another GlueComponent for equality.

Specified by:
eq in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to. If this parameter is null then the comparison fails.
Returns:
true iff |this| == |d| and ord(this) == ord(d)

ge

public boolean ge(FixedGlueComponent d)
Compares the current instance with another GlueComponent.

Specified by:
ge in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to
Returns:
true iff this is greater or equal to d

getOrder

public int getOrder()
Description copied from interface: FixedGlueComponent
Getter for order.

Specified by:
getOrder in interface FixedGlueComponent
Returns:
the order.
See Also:
FixedGlueComponent.getOrder()

getValue

public long getValue()
Getter for the value in scaled points (sp).

Specified by:
getValue in interface FixedGlueComponent
Returns:
the value in internal units of scaled points (sp)

gt

public boolean gt(FixedGlueComponent d)
Compares the current instance with another GlueComponent.

Specified by:
gt in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to
Returns:
true iff ord(this) == ord(d) && |this| > |d| or ord(this) > ord(d)

le

public boolean le(FixedGlueComponent d)
Compares the current instance with another GlueComponent.

Specified by:
le in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to
Returns:
true iff this is less or equal to d

lt

public boolean lt(FixedGlueComponent d)
Compares the current instance with another GlueComponent.

Specified by:
lt in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to
Returns:
true iff ord(this) == ord(d) && |this| < |d| or ord(this) < ord(d)

multiply

public void multiply(long nom,
                     long denom)
Multiply the value by an integer fraction.

length = length * nom / denom

Parameters:
nom - nominator
denom - denominator

negate

public void negate()
Negate the value. This is the same as multiplying with -1.


ne

public boolean ne(FixedGlueComponent d)
Compares the current instance with another GlueComponent for equality.

Specified by:
ne in interface FixedGlueComponent
Parameters:
d - the other GlueComponent to compare to. If this parameter is null then the comparison fails.
Returns:
false iff |this| == |d| and ord(this) == ord(d)

set

public void set(FixedGlueComponent d)
Setter for the value and order.

Parameters:
d - the new value

set

public void set(long theValue)
Setter for the value in terms of the internal representation. The order is reset to 0.

Parameters:
theValue - the new value

setValue

public void setValue(long val)
Setter for the value.

Parameters:
val - the new value

subtract

public void subtract(FixedGlueComponent g)
Subtract a Glue component from this glue. If the order of the other glue component is the same as the current one then the values are subtracted. Otherwise the greater order determines which glue to use.

Parameters:
g - the GlueCoponent to subtract

toString

public java.lang.String toString()
Determine the printable representation of the object.

Specified by:
toString in interface FixedGlueComponent
Returns:
the printable representation
See Also:
toString(StringBuffer), toToks(TokenFactory)

toString

public void toString(java.lang.StringBuffer sb)
Determine the printable representation of the object and append it to the given StringBuffer.

Specified by:
toString in interface FixedGlueComponent
Parameters:
sb - the output string buffer
See Also:
toString()

toString

public void toString(java.lang.StringBuffer sb,
                     char c1,
                     char c2)
Determine the printable representation of the object and append it to the given StringBuffer.

Parameters:
sb - the output string buffer
c1 - the first character for the length of order 0
c2 - the second character for the length of order 0
See Also:
toString(StringBuffer)

toToks

public Tokens toToks(TokenFactory factory)
              throws CatcodeException
Determine the printable representation of the object and return it as a list of Tokens. The value returned is exactly the string which would be produced by TeX to print the Dimen. This means the result is expressed in pt and properly rounded to be read back in again without loss of information.

Specified by:
toToks in interface FixedGlueComponent
Parameters:
factory - the token factory to get the required tokens from
Returns:
the printable representation
Throws:
CatcodeException - in case of an error
See Also:
"TeX – The Program [103]", toToks(TokenFactory), toString(), toString(StringBuffer)

toToks

public void toToks(Tokens toks,
                   TokenFactory factory,
                   char c1,
                   char c2)
            throws CatcodeException
Determine the printable representation of the object and return it as a list of Tokens. The value returned is exactly the string which would be produced by TeX to print the Dimen. This means the result is expressed in pt and properly rounded to be read back in again without loss of information.

Specified by:
toToks in interface FixedGlueComponent
Parameters:
toks - the tokens to append to
factory - the token factory to get the required tokens from
c1 - the first character of the unit
c2 - the second character of the unit
Throws:
CatcodeException - in case of an error
See Also:
"TeX – The Program [103]", toToks(TokenFactory), toString(), toString(StringBuffer)