HTMLPurifier 4.4.0
HTMLPurifier_UnitConverter Class Reference

Class for converting between different unit-lengths as specified by CSS. More...

List of all members.

Public Member Functions

 __construct ($output_precision=4, $internal_precision=10, $force_no_bcmath=false)
 convert ($length, $to_unit)
 Converts a length object of one unit into another unit.
 getSigFigs ($n)
 Returns the number of significant figures in a string number.
 __construct ($output_precision=4, $internal_precision=10, $force_no_bcmath=false)
 convert ($length, $to_unit)
 Converts a length object of one unit into another unit.
 getSigFigs ($n)
 Returns the number of significant figures in a string number.

Public Attributes

const ENGLISH = 1
const METRIC = 2
const DIGITAL = 3

Protected Attributes

 $outputPrecision
 Minimum bcmath precision for output.
 $internalPrecision
 Bcmath precision for internal calculations.

Static Protected Attributes

static $units
 Units information array.

Private Member Functions

 add ($s1, $s2, $scale)
 Adds two numbers, using arbitrary precision when available.
 mul ($s1, $s2, $scale)
 Multiples two numbers, using arbitrary precision when available.
 div ($s1, $s2, $scale)
 Divides two numbers, using arbitrary precision when available.
 round ($n, $sigfigs)
 Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.
 scale ($r, $scale)
 Scales a float to $scale digits right of decimal point, like BCMath.
 add ($s1, $s2, $scale)
 Adds two numbers, using arbitrary precision when available.
 mul ($s1, $s2, $scale)
 Multiples two numbers, using arbitrary precision when available.
 div ($s1, $s2, $scale)
 Divides two numbers, using arbitrary precision when available.
 round ($n, $sigfigs)
 Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.
 scale ($r, $scale)
 Scales a float to $scale digits right of decimal point, like BCMath.

Private Attributes

 $bcmath
 Whether or not BCMath is available.

Detailed Description

Class for converting between different unit-lengths as specified by CSS.

Definition at line 7 of file UnitConverter.php.


Constructor & Destructor Documentation

HTMLPurifier_UnitConverter::__construct ( output_precision = 4,
internal_precision = 10,
force_no_bcmath = false 
)

Definition at line 53 of file UnitConverter.php.

HTMLPurifier_UnitConverter::__construct ( output_precision = 4,
internal_precision = 10,
force_no_bcmath = false 
)

Definition at line 7810 of file HTMLPurifier.standalone.php.


Member Function Documentation

HTMLPurifier_UnitConverter::add ( s1,
s2,
scale 
) [private]

Adds two numbers, using arbitrary precision when available.

Definition at line 188 of file UnitConverter.php.

References scale().

HTMLPurifier_UnitConverter::add ( s1,
s2,
scale 
) [private]

Adds two numbers, using arbitrary precision when available.

Definition at line 7945 of file HTMLPurifier.standalone.php.

References scale().

HTMLPurifier_UnitConverter::convert ( length,
to_unit 
)

Converts a length object of one unit into another unit.

Parameters:
HTMLPurifier_Length$lengthInstance of HTMLPurifier_Length to convert. You must validate() it before passing it here!
string$to_unitUnit to convert to.
Note:
About precision: This conversion function pays very special attention to the incoming precision of values and attempts to maintain a number of significant figure. Results are fairly accurate up to nine digits. Some caveats:
  • If a number is zero-padded as a result of this significant figure tracking, the zeroes will be eliminated.
  • If a number contains less than four sigfigs ($outputPrecision) and this causes some decimals to be excluded, those decimals will be added on.

Definition at line 7834 of file HTMLPurifier.standalone.php.

References div(), getSigFigs(), mul(), and round().

HTMLPurifier_UnitConverter::convert ( length,
to_unit 
)

Converts a length object of one unit into another unit.

Parameters:
HTMLPurifier_Length$lengthInstance of HTMLPurifier_Length to convert. You must validate() it before passing it here!
string$to_unitUnit to convert to.
Note:
About precision: This conversion function pays very special attention to the incoming precision of values and attempts to maintain a number of significant figure. Results are fairly accurate up to nine digits. Some caveats:
  • If a number is zero-padded as a result of this significant figure tracking, the zeroes will be eliminated.
  • If a number contains less than four sigfigs ($outputPrecision) and this causes some decimals to be excluded, those decimals will be added on.

Definition at line 77 of file UnitConverter.php.

References div(), getSigFigs(), mul(), and round().

HTMLPurifier_UnitConverter::div ( s1,
s2,
scale 
) [private]

Divides two numbers, using arbitrary precision when available.

Definition at line 204 of file UnitConverter.php.

References scale().

Referenced by convert().

HTMLPurifier_UnitConverter::div ( s1,
s2,
scale 
) [private]

Divides two numbers, using arbitrary precision when available.

Definition at line 7961 of file HTMLPurifier.standalone.php.

References scale().

HTMLPurifier_UnitConverter::getSigFigs ( n)

Returns the number of significant figures in a string number.

Parameters:
string$nDecimal number
Returns:
int number of sigfigs

Definition at line 7930 of file HTMLPurifier.standalone.php.

HTMLPurifier_UnitConverter::getSigFigs ( n)

Returns the number of significant figures in a string number.

Parameters:
string$nDecimal number
Returns:
int number of sigfigs

Definition at line 173 of file UnitConverter.php.

Referenced by convert().

HTMLPurifier_UnitConverter::mul ( s1,
s2,
scale 
) [private]

Multiples two numbers, using arbitrary precision when available.

Definition at line 196 of file UnitConverter.php.

References scale().

Referenced by convert().

HTMLPurifier_UnitConverter::mul ( s1,
s2,
scale 
) [private]

Multiples two numbers, using arbitrary precision when available.

Definition at line 7953 of file HTMLPurifier.standalone.php.

References scale().

HTMLPurifier_UnitConverter::round ( n,
sigfigs 
) [private]

Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.

Definition at line 7970 of file HTMLPurifier.standalone.php.

References round(), and scale().

HTMLPurifier_UnitConverter::round ( n,
sigfigs 
) [private]

Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.

Definition at line 213 of file UnitConverter.php.

References scale().

Referenced by convert(), round(), and scale().

HTMLPurifier_UnitConverter::scale ( r,
scale 
) [private]

Scales a float to $scale digits right of decimal point, like BCMath.

Definition at line 236 of file UnitConverter.php.

References round().

Referenced by add(), div(), mul(), and round().

HTMLPurifier_UnitConverter::scale ( r,
scale 
) [private]

Scales a float to $scale digits right of decimal point, like BCMath.

Definition at line 7993 of file HTMLPurifier.standalone.php.

References round().


Member Data Documentation

HTMLPurifier_UnitConverter::$bcmath [private]

Whether or not BCMath is available.

Definition at line 51 of file UnitConverter.php.

HTMLPurifier_UnitConverter::$internalPrecision [protected]

Bcmath precision for internal calculations.

Definition at line 46 of file UnitConverter.php.

HTMLPurifier_UnitConverter::$outputPrecision [protected]

Minimum bcmath precision for output.

Definition at line 41 of file UnitConverter.php.

static HTMLPurifier_UnitConverter::$units [static, protected]
Initial value:
 array(
        self::ENGLISH => array(
            'px' => 3, 
            'pt' => 4,
            'pc' => 48,
            'in' => 288,
            self::METRIC => array('pt', '0.352777778', 'mm'),
        ),
        self::METRIC => array(
            'mm' => 1,
            'cm' => 10,
            self::ENGLISH => array('mm', '2.83464567', 'pt'),
        ),
    )

Units information array.

Units are grouped into measuring systems (English, Metric), and are assigned an integer representing the conversion factor between that unit and the smallest unit in the system. Numeric indexes are actually magical constants that encode conversion data from one system to the next, with a O(n^2) constraint on memory (this is generally not a problem, since the number of measuring systems is small.)

Definition at line 23 of file UnitConverter.php.

Definition at line 12 of file UnitConverter.php.

Definition at line 10 of file UnitConverter.php.

Definition at line 11 of file UnitConverter.php.


The documentation for this class was generated from the following files: