|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * SubsetTest.php |
| 5 | + * |
| 6 | + * @since 2026-05-01 |
| 7 | + * @category Library |
| 8 | + * @package PdfFont |
| 9 | + * @author Nicola Asuni <info@tecnick.com> |
| 10 | + * @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD |
| 11 | + * @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) |
| 12 | + * @link https://github.com/tecnickcom/tc-lib-pdf-font |
| 13 | + * |
| 14 | + * This file is part of tc-lib-pdf-font software library. |
| 15 | + */ |
| 16 | + |
| 17 | +namespace Test; |
| 18 | + |
| 19 | +/** |
| 20 | + * Subset Test |
| 21 | + * |
| 22 | + * @since 2026-05-01 |
| 23 | + * @category Library |
| 24 | + * @package PdfFont |
| 25 | + * @author Nicola Asuni <info@tecnick.com> |
| 26 | + * @copyright 2011-2026 Nicola Asuni - Tecnick.com LTD |
| 27 | + * @license https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) |
| 28 | + * @link https://github.com/tecnickcom/tc-lib-pdf-font |
| 29 | + */ |
| 30 | +class SubsetTest extends TestUtil |
| 31 | +{ |
| 32 | + public function testTableChecksumPadsTrailingBytes(): void |
| 33 | + { |
| 34 | + $subset = new class () extends \Com\Tecnick\Pdf\Font\Subset { |
| 35 | + public function __construct() |
| 36 | + { |
| 37 | + } |
| 38 | + |
| 39 | + public function checksum(string $table, int $length): int |
| 40 | + { |
| 41 | + return $this->getTableChecksum($table, $length); |
| 42 | + } |
| 43 | + }; |
| 44 | + |
| 45 | + // 3-byte table must be zero-padded to a 4-byte word before summing. |
| 46 | + $this->assertSame(0x01020300, $subset->checksum("\x01\x02\x03", 3)); |
| 47 | + } |
| 48 | + |
| 49 | + public function testTableChecksumHandlesMixedFullAndPartialWords(): void |
| 50 | + { |
| 51 | + $subset = new class () extends \Com\Tecnick\Pdf\Font\Subset { |
| 52 | + public function __construct() |
| 53 | + { |
| 54 | + } |
| 55 | + |
| 56 | + public function checksum(string $table, int $length): int |
| 57 | + { |
| 58 | + return $this->getTableChecksum($table, $length); |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + $table = "\x11\x22\x33\x44\x55\x66\x77"; |
| 63 | + // 0x11223344 + 0x55667700, modulo 2^32 |
| 64 | + $this->assertSame(0x6688AA44, $subset->checksum($table, 7)); |
| 65 | + } |
| 66 | +} |
0 commit comments