On Sun, May 05, 2024 at 08:45:25PM +0000, Thorsten Glaser wrote:
> Dixi quod…
> 
> >correct… but it only changes the metrics in the head table, not
> >in the OS/2 or hhea tables (as can be seen when loading the font
> >from the PDF in FontForge). Furthermore, the /FontBBox in the PDF
> >is constructed from the values from the original font.
> 
> And Atril uses the values from the hhea table (found by hexediting).
> 
> #define TO_TTF(x) qRound(x * 2048. / ppem)
> 
> This is used in things like…
> 
>     font.hhea.maxAdvanceWidth = TO_TTF(fontEngine->maxCharWidth());
> 
> … but not in…
> 
>     font.hhea.ascender = qRound(properties.ascent);
>     font.hhea.descender = -qRound(properties.descent);
>     font.hhea.lineGap = qRound(properties.leading);
> 
> … and of course not when the OS/2 table is copied:
> 
>     if (!noEmbed) {
>         QTtfTable os2;
>         os2.tag = MAKE_TAG('O', 'S', '/', '2');
>         os2.data = fontEngine->getSfntTable(os2.tag);
>         if (!os2.data.isEmpty())
>             tables.append(os2);
>     }
> 
> (all examples from stretch’s Qt, as the oldest I had at hand)

Actually, this code dates back to “Initial import from the monolithic Qt”
commit from 2011. The only thing that changed is that MAKE_TAG macro was
replaced with QFont::Tag class.

I checked Qt 4 history [1] and there this code dates back to “Long live Qt!”
commit from 2009. So it’s unlikely that we can find the original developer
and ask why it is like that and whether we actually need the OS/2 table.

Now that you dug so deeply, maybe you can try to replace qRound in those
three lines that you mentioned with TO_TTF, and check if it fixes the bug
(and does not break anything else)?

[1]: https://github.com/qt/qt/blame/4.8/src/gui/text/qfontsubset.cpp

--
Dmitry Shachnev

Attachment: signature.asc
Description: PGP signature

Reply via email to