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 | 17 | public function __construct($fontsDirectory) |
|
30 | |||
31 | /** |
||
32 | * Find fonts/paths in a given directory recursively. |
||
33 | * |
||
34 | * @param string|null $path |
||
35 | * @return string|null |
||
36 | */ |
||
37 | 17 | public function findFonts($path = null) |
|
52 | |||
53 | /** |
||
54 | * Return array of available font names and paths. |
||
55 | * |
||
56 | * @return array |
||
57 | */ |
||
58 | 1 | public function getFonts() |
|
62 | |||
63 | /** |
||
64 | * Get the calculated cell width for a given value. |
||
65 | * |
||
66 | * @param string $fontName |
||
67 | * @param int $fontSize |
||
68 | * @param mixed $value |
||
69 | * |
||
70 | * @return float|int |
||
71 | */ |
||
72 | 6 | public function getCellWidth($fontName, $fontSize, $value) |
|
81 | |||
82 | /** |
||
83 | * Get width of a single character. Calculate & cache if necessary. |
||
84 | * |
||
85 | * @param string $fontName |
||
86 | * @param int $fontSize |
||
87 | * @param string $char |
||
88 | * |
||
89 | * @return float |
||
90 | */ |
||
91 | 6 | private function getCharacterWidth($fontName, $fontSize, $char) |
|
100 | |||
101 | /** |
||
102 | * Calculate the width of a single character for the given fontname and size. |
||
103 | * Create image that contains the character 100 times to get more accurate results. |
||
104 | * |
||
105 | * @param string $fontName |
||
106 | * @param int $fontSize |
||
107 | * @param string $char |
||
108 | * |
||
109 | * @return float |
||
110 | */ |
||
111 | 6 | private function calculateCharacterWith($fontName, $fontSize, $char) |
|
121 | |||
122 | /** |
||
123 | * Split value into individual characters. |
||
124 | * |
||
125 | * @param mixed $value |
||
126 | * @return array |
||
127 | */ |
||
128 | 6 | private function getSingleCharacterArray($value) |
|
136 | |||
137 | /** |
||
138 | * Determine glob pattern by fonts directory. |
||
139 | * |
||
140 | * @param $fontsDirectory |
||
141 | * @return string |
||
142 | */ |
||
143 | 17 | private function determineFontsDir($fontsDirectory) |
|
154 | } |
||
155 |