-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathConverter.php
62 lines (56 loc) · 1.32 KB
/
Converter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* This file is part of SetaFPDF
*
* @package setasign\SetaFpdf
* @copyright Copyright (c) 2020 Setasign GmbH & Co. KG (https://www.setasign.com)
* @license http://opensource.org/licenses/mit-license The MIT License
*/
namespace setasign\SetaFpdf\Position;
/**
* Class Converter
*
* This class converts the configured unit to pt.
*
* @see \setasign\SetaFpdf\SetaFpdf::__construct()
*/
class Converter
{
const UNIT_PT = 1;
const UNIT_MM = 72 / 25.4;
const UNIT_CM = 72 / 2.54;
const UNIT_IN = 72;
/**
* @var int|float
*/
protected $scaleFactor;
/**
* Converter constructor.
*
* @param int|float $scaleFactor
*/
public function __construct($scaleFactor)
{
$this->scaleFactor = $scaleFactor;
}
/**
* Converts the given value in the configured unit to pt.
*
* @param float|int $value Value in the configured unit
* @return float|int Value in pt
*/
public function toPt($value)
{
return ($value * $this->scaleFactor);
}
/**
* Converts the given value in pt to the configured unit.
*
* @param int|float $value Value in pt
* @return int|float Value in the configured unit
*/
public function fromPt($value)
{
return ($value / $this->scaleFactor);
}
}