Unified Typesetting API M1-20040817

de.inghuimische.uta.util
Class UnitConverter

java.lang.Object
  extended byde.inghuimische.uta.util.UnitConverter

public class UnitConverter
extends Object

This class is able to convert directly between the following units: scaled point (sp), point (pt), pica (pc), inch (in), big point (bp), didot point (dd), cicero (cc), centimeter (cm), millimeter (mm), meter (m).

The terms used for the units are equal to those used by Knuth in The TeXbook, chapter 12.

Author:
Christian Ziesemer

Field Summary
static int BIG_POINT
          72 big points make one inch.
static int CENTIMETER
          100 centimeter are one meter.
static int CICERO
          12 didot points are one cicero.
static int DIDOT_POINT
          1157 didot points make 1238 points.
static int INCH
          2.54cm are one inch.
static int METER
          meter
static int MILLIMETER
          1000 millimeter are one meter.
static int PICA
          12 points are one pica.
static int POINT
          72.27 points are one INCH.
static int SCALED_POINT
          A 65536 scaled points make one POINT.
 
Constructor Summary
UnitConverter()
          Creates a new unit converter.
 
Method Summary
 double convert(int sourceUnit, int destUnit, double value)
          Convert the given value from sourceUnit to destUnit.
 String getUnitAbbreviation(int unit)
          Returns the abbreviation for the given unit.
 String printMatrix()
          Utility method generating and returning the matrix as string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SCALED_POINT

public static final int SCALED_POINT
A 65536 scaled points make one POINT. This unit is used by UTA and TeX.

See Also:
Constant Field Values

POINT

public static final int POINT
72.27 points are one INCH.

See Also:
Constant Field Values

PICA

public static final int PICA
12 points are one pica.

See Also:
Constant Field Values

INCH

public static final int INCH
2.54cm are one inch.

See Also:
Constant Field Values

BIG_POINT

public static final int BIG_POINT
72 big points make one inch.

See Also:
Constant Field Values

DIDOT_POINT

public static final int DIDOT_POINT
1157 didot points make 1238 points.

See Also:
Constant Field Values

CICERO

public static final int CICERO
12 didot points are one cicero.

See Also:
Constant Field Values

CENTIMETER

public static final int CENTIMETER
100 centimeter are one meter.

See Also:
Constant Field Values

MILLIMETER

public static final int MILLIMETER
1000 millimeter are one meter.

See Also:
Constant Field Values

METER

public static final int METER
meter

See Also:
Constant Field Values
Constructor Detail

UnitConverter

public UnitConverter()
Creates a new unit converter.

Method Detail

convert

public double convert(int sourceUnit,
                      int destUnit,
                      double value)
Convert the given value from sourceUnit to destUnit.

Parameters:
sourceUnit - The source unit.
destUnit - The destination unit.
value - The value to convert.
Returns:
The converted value or 0 if no conversion was possible (what should never happen) or value is 0.
Throws:
IllegalArgumentException - if unit is not a valid unit.

getUnitAbbreviation

public String getUnitAbbreviation(int unit)
Returns the abbreviation for the given unit.

Parameters:
unit - One of the constants defined in this class.
Returns:
The abbreviation for the given unit.
Throws:
IllegalArgumentException - if unit is not a valid unit.

printMatrix

public String printMatrix()
Utility method generating and returning the matrix as string. This method is for testing purposes only.


Unified Typesetting API M1-20040817


An inghuimische.de project.
Copyright (C) 2004 Christian Ziesemer; See the Mozilla Public License for more details.