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 | */ |
||
26 | public function __construct($fontsDirectory) |
||
36 | |||
37 | /** |
||
38 | * Get the calculated cell width for a given value. |
||
39 | * |
||
40 | * @param string $fontName |
||
41 | * @param int $fontSize |
||
42 | * @param mixed $value |
||
43 | * |
||
44 | * @return float|int |
||
45 | */ |
||
46 | public function getCellWidth($fontName, $fontSize, $value) |
||
55 | |||
56 | /** |
||
57 | * Get width of a single character. Calculate & cache if necessary. |
||
58 | * |
||
59 | * @param string $fontName |
||
60 | * @param int $fontSize |
||
61 | * @param string $char |
||
62 | * |
||
63 | * @return float |
||
64 | */ |
||
65 | private function getCharacterWidth($fontName, $fontSize, $char) |
||
74 | |||
75 | /** |
||
76 | * Calculate the width of a single character for the given fontname and size. |
||
77 | * Create image that contains the character 100 times to get more accurate results. |
||
78 | * |
||
79 | * @param string $fontName |
||
80 | * @param int $fontSize |
||
81 | * @param string $char |
||
82 | * |
||
83 | * @return float |
||
84 | */ |
||
85 | private function calculateCharacterWith($fontName, $fontSize, $char) |
||
95 | |||
96 | /** |
||
97 | * Split value into individual characters. |
||
98 | * |
||
99 | * @param mixed $value |
||
100 | * @return array |
||
101 | */ |
||
102 | private function getSingleCharacterArray($value) |
||
110 | |||
111 | /** |
||
112 | * Determine glob pattern by fonts directory. |
||
113 | * |
||
114 | * @param $fontsDirectory |
||
115 | * @return string |
||
116 | */ |
||
117 | private function determineFontsPattern($fontsDirectory) |
||
128 | } |
||
129 |