Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
InitialText | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
render | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * Initial cover text layer |
5 | * |
6 | * PHP version 8 |
7 | * |
8 | * Copyright (C) Villanova University 2018. |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License version 2, |
12 | * as published by the Free Software Foundation. |
13 | * |
14 | * This program is distributed in the hope that it will be useful, |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | * GNU General Public License for more details. |
18 | * |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | * |
23 | * @category VuFind |
24 | * @package Cover_Generator |
25 | * @author Demian Katz <demian.katz@villanova.edu> |
26 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
27 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
28 | */ |
29 | |
30 | namespace VuFind\Cover\Layer; |
31 | |
32 | /** |
33 | * Initial cover text layer |
34 | * |
35 | * @category VuFind |
36 | * @package Cover_Generator |
37 | * @author Demian Katz <demian.katz@villanova.edu> |
38 | * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License |
39 | * @link https://vufind.org/wiki/development:plugins:hierarchy_components Wiki |
40 | */ |
41 | class InitialText extends AbstractTextLayer |
42 | { |
43 | /** |
44 | * Render the layer |
45 | * |
46 | * @param resource $im Image resource to draw on |
47 | * @param array $details Cover details array (with title/author/call_number) |
48 | * @param object $settings Settings object |
49 | * |
50 | * @return void |
51 | */ |
52 | public function render($im, $details, $settings) |
53 | { |
54 | // Get the first letter of title or author... |
55 | $initial = mb_substr($details['title'] . $details['author'], 0, 1, 'UTF-8'); |
56 | |
57 | // Get the height of a character with no descenders: |
58 | $heightWithoutDescenders |
59 | = $this->textHeight('O', $settings->titleFont, $settings->titleFontSize); |
60 | |
61 | // Get the height of the currently selected character: |
62 | $textHeight = $this |
63 | ->textHeight($initial, $settings->titleFont, $settings->titleFontSize); |
64 | |
65 | // Draw the letter... Note that the way we are using $textHeight and |
66 | // $heightWithoutDescenders is something of a fudge driven by the fact |
67 | // that PHP measures text in total pixels, but positions text using the |
68 | // baseline (thus not accounting for descenders). To truly vertically |
69 | // center something, we need more information than we can get without |
70 | // using an extension or library to read more information from the font |
71 | // file. The formula here is not particularly well-informed but seems |
72 | // to produce acceptable results for many scenarios. |
73 | $this->drawText( |
74 | $im, |
75 | $settings, |
76 | $initial, |
77 | $heightWithoutDescenders + ($settings->height - $textHeight) / 2, |
78 | $settings->titleFont, |
79 | $settings->titleFontSize, |
80 | $this->getColor($im, $settings->titleFillColor), |
81 | $this->getColor($im, $settings->titleBorderColor), |
82 | $settings->textAlign |
83 | ); |
84 | } |
85 | } |