dompdf / php-font-lib

A library to read, parse, export and make subsets of different types of font files.
GNU Lesser General Public License v2.1
1.73k stars 256 forks source link

Fix composite glyph #115

Closed ren1244 closed 8 months ago

ren1244 commented 1 year ago

Fix Composite Glyph Output

overview

Problem Reproduction

  1. download kaiu.ttf and use dompdf/utils to load font
  2. test code
    
    <?php
    require('vendor/autoload.php');

use Dompdf\Dompdf;

$dompdf = new Dompdf(); $dompdf->loadHtml('

<p class="font-zh">月落烏啼霜滿天<br>江楓漁火對愁眠<br>姑蘇城外寒山寺<br>夜半鐘聲到客船</p>

');

$dompdf->setPaper('A4', 'protrait');

$dompdf->render();

$dompdf->stream('test.pdf', [ 'Attachment' => 0 ]);


## Related Reference

1. [PDF 1.7 Reference](https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/pdfreference1.7old.pdf) page 468

> The following TrueType tables are always required: “head,” “hhea,” “loca,” “maxp,” “cvt ,” “prep,” “glyf,” “hmtx,” and “fpgm.” If used with a simple font dictionary, the font program must additionally contain a “cmap” table.

2. The C pseudo-code in [OpenType spec - glyf](https://learn.microsoft.com/en-us/typography/opentype/spec/glyf)

do { uint16 flags; uint16 glyphIndex; if ( flags & ARG_1_AND_2_ARE_WORDS) { (int16 or FWORD) argument1; (int16 or FWORD) argument2; } else { uint16 arg1and2; / (arg1 << 8) | arg2 / } if ( flags & WE_HAVE_A_SCALE ) { F2DOT14 scale; / Format 2.14 / } else if ( flags & WE_HAVE_AN_X_AND_Y_SCALE ) { F2DOT14 xscale; / Format 2.14 / F2DOT14 yscale; / Format 2.14 / } else if ( flags & WE_HAVE_A_TWO_BY_TWO ) { F2DOT14 xscale; / Format 2.14 / F2DOT14 scale01; / Format 2.14 / F2DOT14 scale10; / Format 2.14 / F2DOT14 yscale; / Format 2.14 / } } while ( flags & MORE_COMPONENTS ) if (flags & WE_HAVE_INSTR){ uint16 numInstr uint8 instr[numInstr]