dimension
classThe dimension
class is used extensively by the printing classes
to specify physical dimensions on the page. The class has three public
data members and one public enumerated type:
class dimension { public: enum units { points, inches, cm, mm }; int n, d; units u; }
The integers n
and d
hold the numerator and denominator
respectively of the dimension. The member u
defines which units
the dimension is given in. For example, a dimension
object
representing three quarters of an inch would have n
equal to 3,
d
equal to 4, and u
equal to dimension::inches
.
Points here are PostScript points, which are equal to 1/72 of an inch.
The dimension
class has several member functions.
This constructs a dimension equal to the fraction i/j in units u.
This operator returns the negation of the dimension.
These operators multiply the dimension by the integer i.
These operators divide the dimension by the integer i.
These operators are only useful for comparing a dimension to 0.
This returns a floating point numbers representing the dimension in points.
This function sets the dimension to an approximation of the given floating-point number value. Specifically, the denominator is set to denom, and the numerator is set to the integer closest to the product of value and denom.
These functions read a dimension from a string. The string should contain following parts:
- An optional minus sign;
- a number, in either decimal format or as a fraction;
- the units.
For example, the following strings would all be recognised: 0.4 cm; 1 1/2", 56 pt. The allowed unit names are pt, points, point, in, inch, inches, ", cm, mm.