Class HTMLPurifier_UnitConverter

InheritanceHTMLPurifier_UnitConverter

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

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$internalPrecision Bcmath precision for internal calculations. HTMLPurifier_UnitConverter
$outputPrecision Minimum bcmath precision for output. HTMLPurifier_UnitConverter
$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.) HTMLPurifier_UnitConverter

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__construct() HTMLPurifier_UnitConverter
convert() Converts a length object of one unit into another unit. HTMLPurifier_UnitConverter
getSigFigs() Returns the number of significant figures in a string number. HTMLPurifier_UnitConverter

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
DIGITAL 3 HTMLPurifier_UnitConverter
ENGLISH 1 HTMLPurifier_UnitConverter
METRIC 2 HTMLPurifier_UnitConverter

Property Details

$internalPrecision protected property
protected $internalPrecision null
$outputPrecision protected property
protected $outputPrecision null
$units protected static property
protected static $units = [self::ENGLISH => ['px' => 3'pt' => 4'pc' => 48'in' => 288self::METRIC => ['pt''0.352777778''mm']], self::METRIC => ['mm' => 1'cm' => 10self::ENGLISH => ['mm''2.83464567''pt']]]

Method Details

__construct() public method

public void __construct ( $output_precision 4, $internal_precision 10, $force_no_bcmath false )
$output_precision
$internal_precision
$force_no_bcmath
convert() public method

Converts a length object of one unit into another unit.

public HTMLPurifier_Length|bool convert ( $length, $to_unit )
$length HTMLPurifier_Length

Instance of HTMLPurifier_Length to convert. You must validate()

 it before passing it here!
$to_unit string

Unit to convert to.

getSigFigs() public method

Returns the number of significant figures in a string number.

public int getSigFigs ( $n )
$n string

Decimal number

return int

Number of sigfigs