HTMLPurifier_UnitConverter
in package
Class for converting between different unit-lengths as specified by CSS.
Table of Contents
Constants
Properties
- $internalPrecision : mixed
- Bcmath precision for internal calculations.
- $outputPrecision : mixed
- Minimum bcmath precision for output.
- $units : mixed
- 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.)
- $bcmath : mixed
- Whether or not BCMath is available.
Methods
- __construct() : mixed
- convert() : HTMLPurifier_Length|bool
- Converts a length object of one unit into another unit.
- getSigFigs() : int
- Returns the number of significant figures in a string number.
- add() : string
- Adds two numbers, using arbitrary precision when available.
- div() : string
- Divides two numbers, using arbitrary precision when available.
- mul() : string
- Multiples two numbers, using arbitrary precision when available.
- round() : string
- Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.
- scale() : string
- Scales a float to $scale digits right of decimal point, like BCMath.
Constants
DIGITAL
public
mixed
DIGITAL
= 3
ENGLISH
public
mixed
ENGLISH
= 1
METRIC
public
mixed
METRIC
= 2
Properties
$internalPrecision
Bcmath precision for internal calculations.
protected
mixed
$internalPrecision
Tags
$outputPrecision
Minimum bcmath precision for output.
protected
mixed
$outputPrecision
Tags
$units
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.)
protected
static mixed
$units
= array(self::ENGLISH => array(
'px' => 3,
// This is as per CSS 2.1 and Firefox. Your mileage may vary
'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')))
$bcmath
Whether or not BCMath is available.
private
mixed
$bcmath
Tags
Methods
__construct()
public
__construct([mixed $output_precision = 4 ][, mixed $internal_precision = 10 ][, mixed $force_no_bcmath = false ]) : mixed
Parameters
- $output_precision : mixed = 4
- $internal_precision : mixed = 10
- $force_no_bcmath : mixed = false
convert()
Converts a length object of one unit into another unit.
public
convert(HTMLPurifier_Length $length, string $to_unit) : HTMLPurifier_Length|bool
Parameters
- $length : HTMLPurifier_Length
-
Instance of HTMLPurifier_Length to convert. You must validate() it before passing it here!
- $to_unit : string
-
Unit to convert to.
Tags
Return values
HTMLPurifier_Length|boolgetSigFigs()
Returns the number of significant figures in a string number.
public
getSigFigs(string $n) : int
Parameters
- $n : string
-
Decimal number
Return values
int —number of sigfigs
add()
Adds two numbers, using arbitrary precision when available.
private
add(string $s1, string $s2, int $scale) : string
Parameters
- $s1 : string
- $s2 : string
- $scale : int
Return values
stringdiv()
Divides two numbers, using arbitrary precision when available.
private
div(string $s1, string $s2, int $scale) : string
Parameters
- $s1 : string
- $s2 : string
- $scale : int
Return values
stringmul()
Multiples two numbers, using arbitrary precision when available.
private
mul(string $s1, string $s2, int $scale) : string
Parameters
- $s1 : string
- $s2 : string
- $scale : int
Return values
stringround()
Rounds a number according to the number of sigfigs it should have, using arbitrary precision when available.
private
round(float $n, int $sigfigs) : string
Parameters
- $n : float
- $sigfigs : int
Return values
stringscale()
Scales a float to $scale digits right of decimal point, like BCMath.
private
scale(float $r, int $scale) : string
Parameters
- $r : float
- $scale : int