Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
181 / 181
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
GlyphList
100.00% covered (success)
100.00%
181 / 181
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
1 / 1
 getList
100.00% covered (success)
100.00%
175 / 175
100.00% covered (success)
100.00%
1 / 1
1
 glyphToUnicode
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 unicodeToGlyph
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Encoding;
6
7final class GlyphList
8{
9    /** @return array<string, int> glyph name => Unicode codepoint */
10    public static function getList(): array
11    {
12        return [
13            'A' => 65, 'B' => 66, 'C' => 67, 'D' => 68, 'E' => 69,
14            'F' => 70, 'G' => 71, 'H' => 72, 'I' => 73, 'J' => 74,
15            'K' => 75, 'L' => 76, 'M' => 77, 'N' => 78, 'O' => 79,
16            'P' => 80, 'Q' => 81, 'R' => 82, 'S' => 83, 'T' => 84,
17            'U' => 85, 'V' => 86, 'W' => 87, 'X' => 88, 'Y' => 89,
18            'Z' => 90,
19            'a' => 97,  'b' => 98,  'c' => 99,  'd' => 100, 'e' => 101,
20            'f' => 102, 'g' => 103, 'h' => 104, 'i' => 105, 'j' => 106,
21            'k' => 107, 'l' => 108, 'm' => 109, 'n' => 110, 'o' => 111,
22            'p' => 112, 'q' => 113, 'r' => 114, 's' => 115, 't' => 116,
23            'u' => 117, 'v' => 118, 'w' => 119, 'x' => 120, 'y' => 121,
24            'z' => 122,
25            'zero'  => 48, 'one'  => 49, 'two'   => 50, 'three' => 51,
26            'four'  => 52, 'five' => 53, 'six'   => 54, 'seven' => 55,
27            'eight' => 56, 'nine' => 57,
28            'space'        => 32,
29            'exclam'       => 33,
30            'quotedbl'     => 34,
31            'numbersign'   => 35,
32            'dollar'       => 36,
33            'percent'      => 37,
34            'ampersand'    => 38,
35            'quotesingle'  => 39,
36            'parenleft'    => 40,
37            'parenright'   => 41,
38            'asterisk'     => 42,
39            'plus'         => 43,
40            'comma'        => 44,
41            'hyphen'       => 45,
42            'period'       => 46,
43            'slash'        => 47,
44            'colon'        => 58,
45            'semicolon'    => 59,
46            'less'         => 60,
47            'equal'        => 61,
48            'greater'      => 62,
49            'question'     => 63,
50            'at'           => 64,
51            'bracketleft'  => 91,
52            'backslash'    => 92,
53            'bracketright' => 93,
54            'asciicircum'  => 94,
55            'underscore'   => 95,
56            'grave'        => 96,
57            'braceleft'    => 123,
58            'bar'          => 124,
59            'braceright'   => 125,
60            'asciitilde'   => 126,
61            'exclamdown'   => 161,
62            'cent'         => 162,
63            'sterling'     => 163,
64            'currency'     => 164,
65            'yen'          => 165,
66            'brokenbar'    => 166,
67            'section'      => 167,
68            'dieresis'     => 168,
69            'copyright'    => 169,
70            'ordfeminine'  => 170,
71            'guillemotleft' => 171,
72            'logicalnot'   => 172,
73            'registered'   => 174,
74            'macron'       => 175,
75            'degree'       => 176,
76            'plusminus'    => 177,
77            'twosuperior'  => 178,
78            'threesuperior' => 179,
79            'acute'        => 180,
80            'mu'           => 181,
81            'paragraph'    => 182,
82            'periodcentered' => 183,
83            'cedilla'      => 184,
84            'onesuperior'  => 185,
85            'ordmasculine' => 186,
86            'guillemotright' => 187,
87            'onequarter'   => 188,
88            'onehalf'      => 189,
89            'threequarters' => 190,
90            'questiondown' => 191,
91            'Agrave'       => 192,
92            'Aacute'       => 193,
93            'Acircumflex'  => 194,
94            'Atilde'       => 195,
95            'Adieresis'    => 196,
96            'Aring'        => 197,
97            'AE'           => 198,
98            'Ccedilla'     => 199,
99            'Egrave'       => 200,
100            'Eacute'       => 201,
101            'Ecircumflex'  => 202,
102            'Edieresis'    => 203,
103            'Igrave'       => 204,
104            'Iacute'       => 205,
105            'Icircumflex'  => 206,
106            'Idieresis'    => 207,
107            'Eth'          => 208,
108            'Ntilde'       => 209,
109            'Ograve'       => 210,
110            'Oacute'       => 211,
111            'Ocircumflex'  => 212,
112            'Otilde'       => 213,
113            'Odieresis'    => 214,
114            'multiply'     => 215,
115            'Oslash'       => 216,
116            'Ugrave'       => 217,
117            'Uacute'       => 218,
118            'Ucircumflex'  => 219,
119            'Udieresis'    => 220,
120            'Yacute'       => 221,
121            'Thorn'        => 222,
122            'germandbls'   => 223,
123            'agrave'       => 224,
124            'aacute'       => 225,
125            'acircumflex'  => 226,
126            'atilde'       => 227,
127            'adieresis'    => 228,
128            'aring'        => 229,
129            'ae'           => 230,
130            'ccedilla'     => 231,
131            'egrave'       => 232,
132            'eacute'       => 233,
133            'ecircumflex'  => 234,
134            'edieresis'    => 235,
135            'igrave'       => 236,
136            'iacute'       => 237,
137            'icircumflex'  => 238,
138            'idieresis'    => 239,
139            'eth'          => 240,
140            'ntilde'       => 241,
141            'ograve'       => 242,
142            'oacute'       => 243,
143            'ocircumflex'  => 244,
144            'otilde'       => 245,
145            'odieresis'    => 246,
146            'divide'       => 247,
147            'oslash'       => 248,
148            'ugrave'       => 249,
149            'uacute'       => 250,
150            'ucircumflex'  => 251,
151            'udieresis'    => 252,
152            'yacute'       => 253,
153            'thorn'        => 254,
154            'ydieresis'    => 255,
155            'Euro'         => 8364,
156            'trademark'    => 8482,
157            'bullet'       => 8226,
158            'endash'       => 8211,
159            'emdash'       => 8212,
160            'quotedblleft' => 8220,
161            'quotedblright' => 8221,
162            'quoteleft'    => 8216,
163            'quoteright'   => 8217,
164            'quotesinglbase' => 8218,
165            'quotedblbase' => 8222,
166            'ellipsis'     => 8230,
167            'dagger'       => 8224,
168            'daggerdbl'    => 8225,
169            'perthousand'  => 8240,
170            'Scaron'       => 352,
171            'scaron'       => 353,
172            'OE'           => 338,
173            'oe'           => 339,
174            'Zcaron'       => 381,
175            'zcaron'       => 382,
176            'Ydieresis'    => 376,
177            'fi'           => 64257,
178            'fl'           => 64258,
179            'florin'       => 402,
180            'circumflex'   => 710,
181            'tilde'        => 732,
182            'dotlessi'     => 305,
183            'guilsinglleft' => 8249,
184            'guilsinglright' => 8250,
185            '.notdef'      => 0,
186        ];
187    }
188
189    public static function glyphToUnicode(string $glyphName): ?int
190    {
191        $list = self::getList();
192        return $list[$glyphName] ?? null;
193    }
194
195    public static function unicodeToGlyph(int $codepoint): ?string
196    {
197        foreach (self::getList() as $glyph => $cp) {
198            if ($cp === $codepoint && $glyph !== '.notdef') {
199                return $glyph;
200            }
201        }
202        return null;
203    }
204}