ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 21 forks source link

Underlinethickness and position are incorrect for most fonts. #79

Open sciurius opened 7 months ago

sciurius commented 7 months ago

In PDF/API2/Resource/CIDFont/TrueType/FontFile.pm, font metrics are scaled to 1000/upem. However, underlineposition and underlinethickness are not scaled.

PDF/API2/Content.pm, lines 2043-2044 seem to assume 1000, not upem:

    my $underlineposition = (-$self->{' font'}->underlineposition() * $self->{' fontsize'} / 1000 || 1);
    my $underlinethickness = ($self->{' font'}->underlinethickness() * $self->{' fontsize'} / 1000 || 1);

This affects all fonts with a design size not equal to 1000, which includes all modern TTF/OTF fonts that have a design size 2048.

The result can be seen in the attached image: left is LibreOffice, right is PDF::API2. The font is DejaVuSerif.

scrot20240410121629

It is probably too late to change but it should at least be documented somewhere.