Length type represents length (distance) values such as mm, cm, px, in, pt, etc.
Length values are constructed by following
Constructor functions
- em
-
( v: int | float ) : length, these functions constructs length values of corresponding type.
- ex
-
( v: int | float ) : length
- pr
-
( v: int | float ) : length/percentage
- fx
-
( v: int | float ) : length
- px
-
( v: int | float ) : length
- in
-
( v: int | float ) : length
- cm
-
( v: int | float ) : length
- mm
-
( v: int | float ) : length
- pt
-
( v: int | float ) : length
- pc
-
( v: int | float ) : length
- dip
-
( v: int | float ) : length
- length
-
( v: int | float, units: symbol ) : length
Constants
- N/A
Properties
- units
- read-only, symbol, one of:
- #em - em font units;
- #ex - ex font units;
- #pr - percents '%';
- #fx - flex units (in h-smile CSS core): 1fx = '1*' or '100%%';
- #px - pixels, usually device dependent;
- #in - inches;
- #cm - centimeters;
- #mm - millimeters;
- #pt - typographical point (1/72 of inch)
- #pc - typographical pica (1/12 of point)
- #dip - device independent pixels ( 1/96 of inch )
Methods
- parse
-
( text: string [, defval: undefined ) : length | defval
static method (method of the class), parses text for the length value. In case of parsing failure returns value defined by defval.
- make
-
( v: int | float, units: symbol ) : length
static function, constructs length of correspondent value and the unit symbol (above).
- toString
-
( ) : string
Returns string representation of the value, e.g. "12.5pt", "1px", etc.
- toInteger
-
( ) : int
Converts the length to integer.
- toFloat
-
( [unit: symbol [, defvalue: any ]) : float
Converts the length to float. If unit is provided and its value is one of the units above then the result be float representation in that units. If conversion is not possible the defvalue is returned (or 0.0 if it is omitted)
- morph
-
( lengthFrom, lengthTo, ratio ) : length
Computes the average length using the formula: (lengthTo - lengthFrom) * ratio + lengthFrom;