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 reading left side bearings #122

Closed ren1244 closed 8 months ago

ren1244 commented 9 months ago

Some character render wrong position.

The image shows text rendering before fixing and after fixing.

before fixing and after fixing

Related specification documents

https://learn.microsoft.com/en-us/typography/opentype/spec/hmtx

If numberOfHMetrics is less than the total number of glyphs, then the hMetrics array is followed by an array for the left side bearing values of the remaining glyphs.

Testing code

using font:fonts.zip

<?php

require(__DIR__ . '/vendor/autoload.php');

use Dompdf\Dompdf;

$html = <<<EOT
<style>
    @font-face {
        font-family: "noto";
        src: url("fonts/NotoSerifTC-Regular.ttf") format('truetype');
        font-weight: normal;
        font-style: normal;
    }
    body{
        font-family: 'noto';
    }
</style>
<p>當一個有趣的人</p>
EOT;

$dompdf = new Dompdf([
    'chroot' => __DIR__
]);
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream('demo.pdf', [
    'Attachment' => 0
]);