Enum Class SpaceUnit

java.lang.Object
java.lang.Enum<SpaceUnit>
com.teamten.typeset.SpaceUnit
All Implemented Interfaces:
Serializable, Comparable<SpaceUnit>, Constable

public enum SpaceUnit extends Enum<SpaceUnit>
Represents various units to measure 1-dimensional space.
  • Enum Constant Details

    • PT

      public static final SpaceUnit PT
      Point. This is the base PDF unit. Note that we don't use the real printer's point, which is 1/72.27 inch. Ours is equivalent to TeX's "big point (bp)".
    • PC

      public static final SpaceUnit PC
      Pica. One pica = 12 points.
    • IN

      public static final SpaceUnit IN
      Inch. 72 points in an inch, by PDF definition.
    • CM

      public static final SpaceUnit CM
      Centimeter. 2.54 cm in an inch.
    • MM

      public static final SpaceUnit MM
      Millimeter. 25.4 mm in an inch.
    • SP

      public static final SpaceUnit SP
      Scaled point, about 5 nm, or 1/100 the wavelength of visible light. We use this for all our internal calculations. A long lets us represent distances up to 49 gigameters.
  • Method Details

    • values

      public static SpaceUnit[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SpaceUnit valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • toSp

      public long toSp(double distance)
      Convert from this unit to SP.
    • fromSp

      public double fromSp(double sp)
      Convert from SP to this unit.
    • fromSpAsFloat

      public float fromSpAsFloat(double sp)
      Convert from SP to this unit. This is a convenience method because many methods in pdfbox take floats.
    • parseDistance

      public static long parseDistance(Reader r) throws IOException
      Parse a distance, such as "2in", "3.5 in", or "-2 mm". The number must be parsable as a (possibly signed) double. The unit must be one of the ones from this class, in upper or lower case, preceded by optional whitespace. Only abbreviations are permitted (e.g., "inch" is left after "in" and "centimeter" is rejected). The reader is left immediately after the unit.

      TODO merge with TexParser.parseDistance()?

      Returns:
      the distance in scaled points.
      Throws:
      IOException - from the Reader.
      NumberFormatException - if the distance cannot be parsed.
    • parseDistance

      public static long parseDistance(String s)
      Parses a distance as a string. See parseDistance(Reader) for details.
      Throws:
      NumberFormatException - if the distance cannot be parsed.