1 | <?php |
||
11 | class SizeCalculator |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $fonts = []; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $sizes = []; |
||
22 | |||
23 | /** |
||
24 | * @param string|null $fontsDirectory |
||
25 | * @throws \Exception |
||
26 | */ |
||
27 | 19 | public function __construct($fontsDirectory = null) |
|
33 | |||
34 | /** |
||
35 | * Find fonts/paths in a given directory recursively. |
||
36 | * |
||
37 | * @param string|null $path |
||
38 | * @return string|null |
||
39 | * @throws \Exception |
||
40 | */ |
||
41 | 1 | public function findFonts($path = null) |
|
56 | |||
57 | /** |
||
58 | * Return array of available font names and paths. |
||
59 | * |
||
60 | * @return array |
||
61 | */ |
||
62 | 2 | public function getFonts() |
|
66 | |||
67 | /** |
||
68 | * Get the calculated cell width for a given value. |
||
69 | * |
||
70 | * @param string $fontName |
||
71 | * @param int $fontSize |
||
72 | * @param mixed $value |
||
73 | * |
||
74 | * @return float|int |
||
75 | */ |
||
76 | 6 | public function getCellWidth($fontName, $fontSize, $value) |
|
85 | |||
86 | /** |
||
87 | * Get width of a single character. Calculate & cache if necessary. |
||
88 | * |
||
89 | * @param string $fontName |
||
90 | * @param int $fontSize |
||
91 | * @param string $char |
||
92 | * |
||
93 | * @return float |
||
94 | */ |
||
95 | 6 | private function getCharacterWidth($fontName, $fontSize, $char) |
|
104 | |||
105 | /** |
||
106 | * Calculate the width of a single character for the given fontname and size. |
||
107 | * Create image that contains the character 100 times to get more accurate results. |
||
108 | * |
||
109 | * @param string $fontName |
||
110 | * @param int $fontSize |
||
111 | * @param string $char |
||
112 | * |
||
113 | * @return float |
||
114 | */ |
||
115 | 6 | private function calculateCharacterWith($fontName, $fontSize, $char) |
|
125 | |||
126 | /** |
||
127 | * Split value into individual characters. |
||
128 | * |
||
129 | * @param mixed $value |
||
130 | * @return array |
||
131 | */ |
||
132 | 6 | private function getSingleCharacterArray($value) |
|
140 | } |
||
141 |