1 | <?php |
||
14 | class FontsFactory |
||
15 | { |
||
16 | /** @var array */ |
||
17 | protected $fonts = array(); |
||
18 | |||
19 | /** |
||
20 | * @param string|array $fontsPath |
||
21 | */ |
||
22 | 12 | protected function __construct($fontsPath) |
|
23 | { |
||
24 | 12 | if (is_array($fontsPath)) { |
|
25 | foreach ($fontsPath as $filename) { |
||
26 | Assert::fileExists($filename, 'The fonts path must exist'); |
||
27 | $name = basename($filename); |
||
28 | $this->fonts[$name] = new Font($name, realpath($filename)); |
||
29 | } |
||
30 | } else { |
||
31 | 12 | Assert::fileExists($fontsPath, 'The fonts path must exist'); |
|
32 | 12 | foreach (glob($fontsPath . "/*.ttf") as $filename) { |
|
33 | 12 | $name = basename($filename); |
|
34 | 12 | $this->fonts[$name] = new Font($name, realpath($filename)); |
|
35 | } |
||
36 | } |
||
37 | 12 | } |
|
38 | |||
39 | /** |
||
40 | * @param string $fontsPath |
||
41 | * @return FontsFactory |
||
42 | */ |
||
43 | 12 | public static function create($fontsPath) |
|
44 | { |
||
45 | 12 | return new self($fontsPath); |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * @param string $name |
||
50 | * @return Font |
||
51 | * @throws \InvalidArgumentException |
||
52 | */ |
||
53 | 11 | public function getFont($name) |
|
58 | |||
59 | /** |
||
60 | * @param string $name |
||
61 | * @param int $size |
||
62 | * @param string $color |
||
63 | * @return ImagineFont |
||
64 | */ |
||
65 | 11 | public function getImagineFont($name, $size, $color = '#000000') |
|
70 | |||
71 | /** |
||
72 | * @return array |
||
73 | */ |
||
74 | public function getFonts() |
||
78 | } |
||
79 |