Package com.teamten.typeset
Enum Class SpaceUnit
- All Implemented Interfaces:
Serializable
,Comparable<SpaceUnit>
,Constable
Represents various units to measure 1-dimensional space.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptiondouble
fromSp
(double sp) Convert from SP to this unit.float
fromSpAsFloat
(double sp) Convert from SP to this unit.static long
Parse a distance, such as "2in", "3.5 in", or "-2 mm".static long
Parses a distance as a string.long
toSp
(double distance) Convert from this unit to SP.static SpaceUnit
Returns the enum constant of this class with the specified name.static SpaceUnit[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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
Pica. One pica = 12 points. -
IN
Inch. 72 points in an inch, by PDF definition. -
CM
Centimeter. 2.54 cm in an inch. -
MM
Millimeter. 25.4 mm in an inch. -
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
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
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 nameNullPointerException
- 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
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
Parses a distance as a string. SeeparseDistance(Reader)
for details.- Throws:
NumberFormatException
- if the distance cannot be parsed.
-