Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| SymbolEncoding | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
7 | |
100.00% |
1 / 1 |
| get | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
7 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | /** |
| 4 | * Pop PHP Framework (https://www.popphp.org/) |
| 5 | * |
| 6 | * @link https://github.com/popphp/popphp-framework |
| 7 | * @author Nick Sagona, III <nick@popphp.org> |
| 8 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 9 | * @license https://www.popphp.org/license New BSD License |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * @namespace |
| 14 | */ |
| 15 | namespace Pop\Pdf\Extract\Font\Encoding; |
| 16 | |
| 17 | /** |
| 18 | * Pdf extract SymbolEncoding table class |
| 19 | * |
| 20 | * Covers the well-known Symbol-font convention of mapping each Latin |
| 21 | * keyboard-position letter to the correspondingly-named Greek letter (e.g. |
| 22 | * 'p' -> pi, 'w' -> omega). The 'j' and 'v' keys and all non-Greek math/ |
| 23 | * technical symbols in the Symbol font are intentionally unmapped. |
| 24 | * |
| 25 | * @category Pop |
| 26 | * @package Pop\Pdf |
| 27 | * @author Nick Sagona, III <nick@popphp.org> |
| 28 | * @copyright Copyright (c) 2009-2026 Nick Sagona, III |
| 29 | * @license https://www.popphp.org/license New BSD License |
| 30 | * @version 6.0.0 |
| 31 | */ |
| 32 | class SymbolEncoding |
| 33 | { |
| 34 | |
| 35 | /** |
| 36 | * Lowercase Latin keyboard letter to Greek Unicode codepoint table |
| 37 | */ |
| 38 | protected const GREEK_BY_LETTER = [ |
| 39 | 'a' => 0x3B1, 'b' => 0x3B2, 'g' => 0x3B3, 'd' => 0x3B4, 'e' => 0x3B5, |
| 40 | 'z' => 0x3B6, 'h' => 0x3B7, 'q' => 0x3B8, 'i' => 0x3B9, 'k' => 0x3BA, |
| 41 | 'l' => 0x3BB, 'm' => 0x3BC, 'n' => 0x3BD, 'x' => 0x3BE, 'o' => 0x3BF, |
| 42 | 'p' => 0x3C0, 'r' => 0x3C1, 's' => 0x3C3, 't' => 0x3C4, 'u' => 0x3C5, |
| 43 | 'f' => 0x3C6, 'c' => 0x3C7, 'y' => 0x3C8, 'w' => 0x3C9, |
| 44 | ]; |
| 45 | |
| 46 | /** |
| 47 | * Get the Unicode codepoint for a Symbol-font byte |
| 48 | * |
| 49 | * @param int $byte |
| 50 | * @return ?int |
| 51 | */ |
| 52 | public static function get(int $byte): ?int |
| 53 | { |
| 54 | if ($byte === 0x20) { |
| 55 | return 0x0020; |
| 56 | } |
| 57 | |
| 58 | if (($byte >= 0x61) && ($byte <= 0x7A)) { |
| 59 | return self::GREEK_BY_LETTER[chr($byte)] ?? null; |
| 60 | } |
| 61 | |
| 62 | if (($byte >= 0x41) && ($byte <= 0x5A)) { |
| 63 | $lower = self::GREEK_BY_LETTER[strtolower(chr($byte))] ?? null; |
| 64 | |
| 65 | return ($lower !== null) ? ($lower - 0x20) : null; |
| 66 | } |
| 67 | |
| 68 | return null; |
| 69 | } |
| 70 | |
| 71 | } |