|
16 | 16 |
|
17 | 17 | namespace Test; |
18 | 18 |
|
| 19 | +/** |
| 20 | + * @phpstan-import-type TFontDataCidInfo from \Com\Tecnick\Pdf\Font\Load |
| 21 | + * @phpstan-import-type TFontDataDesc from \Com\Tecnick\Pdf\Font\Load |
| 22 | + * @phpstan-type TUniToCidFont array{ |
| 23 | + * cidinfo: TFontDataCidInfo, |
| 24 | + * cw: array<int, int>, |
| 25 | + * desc: TFontDataDesc, |
| 26 | + * dw: int, |
| 27 | + * enc: string, |
| 28 | + * i: int, |
| 29 | + * n: int, |
| 30 | + * name: string, |
| 31 | + * subset: bool, |
| 32 | + * subsetchars: array<int, bool> |
| 33 | + * } |
| 34 | + */ |
| 35 | +class OutputTestOutFont extends \Com\Tecnick\Pdf\Font\OutFont |
| 36 | +{ |
| 37 | + /** |
| 38 | + * @param TUniToCidFont $font |
| 39 | + */ |
| 40 | + public function runUniToCid(array &$font, int $cidoffset): void |
| 41 | + { |
| 42 | + $this->uniToCid($font, $cidoffset); |
| 43 | + } |
| 44 | +} |
| 45 | + |
19 | 46 | /** |
20 | 47 | * Output Test |
21 | 48 | * |
|
28 | 55 | * @link https://github.com/tecnickcom/tc-lib-pdf-font |
29 | 56 | * |
30 | 57 | * @SuppressWarnings("PHPMD.LongVariable") |
| 58 | + * |
| 59 | + * @phpstan-import-type TFontData from \Com\Tecnick\Pdf\Font\Load |
31 | 60 | */ |
32 | 61 | class OutputTest extends TestUtil |
33 | 62 | { |
@@ -180,4 +209,79 @@ public function testSubsetTrueTypeUnicodeOutputUsesValidCidSystemInfoAndFontStre |
180 | 209 | $this->assertNotEmpty($lengths); |
181 | 210 | $this->assertGreaterThan(1000, \max($lengths)); |
182 | 211 | } |
| 212 | + |
| 213 | + public function testSubsetCharMergePreservesUnicodeKeys(): void |
| 214 | + { |
| 215 | + $this->setupTest(); |
| 216 | + $indir = \dirname(__DIR__) . '/util/vendor/tecnickcom/tc-font-mirror/'; |
| 217 | + |
| 218 | + $objnum = 1; |
| 219 | + $stack = new \Com\Tecnick\Pdf\Font\Stack(1); |
| 220 | + new \Com\Tecnick\Pdf\Font\Import($indir . 'freefont/FreeSans.ttf'); |
| 221 | + $stack->add($objnum, 'freesans', '', '', true); |
| 222 | + |
| 223 | + $fonts = $stack->getFonts(); |
| 224 | + /** @var TFontData $base */ |
| 225 | + $base = $fonts['freesans']; |
| 226 | + $base['key'] = 'freesans_dup'; |
| 227 | + $base['i'] = $base['i'] + 1000; |
| 228 | + $base['n'] = $base['n'] + 1000; |
| 229 | + $base['subsetchars'] = [8776 => true]; |
| 230 | + /** @var TFontData $primary */ |
| 231 | + $primary = $fonts['freesans']; |
| 232 | + $primary['subsetchars'] = [960 => true]; |
| 233 | + |
| 234 | + /** @var array<string, TFontData> $fonts */ |
| 235 | + $fonts = |
| 236 | + \array_replace( |
| 237 | + $fonts, |
| 238 | + [ |
| 239 | + 'freesans' => $primary, |
| 240 | + 'freesans_dup' => $base, |
| 241 | + ] |
| 242 | + ); |
| 243 | + |
| 244 | + $encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(); |
| 245 | + $output = new \Com\Tecnick\Pdf\Font\Output($fonts, $objnum, $encrypt); |
| 246 | + |
| 247 | + $ref = new \ReflectionClass($output); |
| 248 | + $prop = $ref->getProperty('subchars'); |
| 249 | + $prop->setAccessible(true); |
| 250 | + $subchars = $prop->getValue($output); |
| 251 | + |
| 252 | + $this->assertIsArray($subchars); |
| 253 | + $this->assertNotEmpty($subchars); |
| 254 | + $first = \array_values($subchars)[0]; |
| 255 | + $this->assertArrayHasKey(960, $first); |
| 256 | + $this->assertArrayHasKey(8776, $first); |
| 257 | + } |
| 258 | + |
| 259 | + public function testUniToCidPreservesNumericCidKeys(): void |
| 260 | + { |
| 261 | + $outfont = new OutputTestOutFont(); |
| 262 | + |
| 263 | + $font = [ |
| 264 | + 'cidinfo' => ['Ordering' => 'Identity', 'Registry' => 'Adobe', 'Supplement' => 0, 'uni2cid' => [960 => 853, 8776 => 3283]], |
| 265 | + 'cw' => [32 => 250, 960 => 500, 8776 => 600], |
| 266 | + 'desc' => [ |
| 267 | + 'Ascent' => 0, 'AvgWidth' => 0, 'CapHeight' => 0, 'Descent' => 0, |
| 268 | + 'Flags' => 0, 'FontBBox' => '', 'ItalicAngle' => 0, 'Leading' => 0, |
| 269 | + 'MaxWidth' => 0, 'MissingWidth' => 0, 'StemH' => 0, 'StemV' => 0, 'XHeight' => 0, |
| 270 | + ], |
| 271 | + 'dw' => 0, |
| 272 | + 'enc' => '', |
| 273 | + 'i' => 1, |
| 274 | + 'n' => 1, |
| 275 | + 'name' => 'test', |
| 276 | + 'subset' => true, |
| 277 | + 'subsetchars' => [], |
| 278 | + ]; |
| 279 | + |
| 280 | + $outfont->runUniToCid($font, 0); |
| 281 | + |
| 282 | + $this->assertArrayHasKey(853, $font['cw']); |
| 283 | + $this->assertArrayHasKey(3283, $font['cw']); |
| 284 | + $this->assertSame(500, $font['cw'][853]); |
| 285 | + $this->assertSame(600, $font['cw'][3283]); |
| 286 | + } |
183 | 287 | } |
0 commit comments