Closed Bug 1781022 Opened 2 years ago Closed 2 years ago

pdfs with sans serif fonts and Identity-H encoding are displayed badly (with inconsistent/wobbly glyph height and position)

Categories

(Core :: Layout: Text and Fonts, defect)

Firefox 91
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: juh+bugzilla, Unassigned)

Details

Attachments

(3 files)

Attached file test.zip

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0

Steps to reproduce:

I create a pdf with a sans serif font where fonts are included with

type: CID Type 0C
encoding: Identity-H

The file is displayed fine in many pdf viewers.
But not in the pdf viewer of firefox.

I tried this with two different font families from different sources, so I guess it is not a font problem.

If I use another tool to create a pdf with embedded fonts as Type 1 and with the encoding "Builtin", the pdf is displayed fine.

A screenshot and the displayed file are attached.

Actual results:

The letters seems to jump up and down up until a magnification of 300% where the effect goes away. The pdf prints fine

Expected results:

The letters of the fonts should be displayed just fine even when the fonts are embedded as CID Type 0C with encoding: Identity-H.

The Bugbug bot thinks this bug should belong to the 'Core::Layout: Text and Fonts' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Layout: Text and Fonts
Product: Firefox → Core

I think this is a font issue, or more specifically an issue with the font as embedded by LuaMetaTeX in this PDF -- it may have lost or disrupted the hinting from the original font in some way. Viewing the PDF in Adobe Reader, I can see some similar irregularity -- not as extreme as in your screenshot, but it's definitely not good. See for example the final line "eu lacus", where the "u" glyphs seem to be smaller and slightly raised compared to the surrounding text.

It's probably especially bad on Linux because of interactions between the font resource's hinting (or lack of it) and particular FreeType rasterization settings. You might find that changing the hinting level and/or antialiasing mode can improve the result.

Only a guess, but it may be that (a) LuaMetaTeX is stripping the original hinting from the font (assuming it was hinted originally -- if you use that same font directly in HTML, how does it look?), and (b) the use of Identity-H encoding may prevent the FreeType autohinter working well with the resulting font as it depends on the encoding to understand how glyphs should be harmonized across the alphabet.

This is definitely a hinting issue. I'm using Gnome on Wayland, and if I set "None" hinting and "None" AA, all of the PDFs look the same (and terrible). But if I set "Slight" hinting and "Grayscale" AA (the defaut values), the LMTX PDF looks different than the other 4. The glyphs in the LMTX PDF are all slightly taller, which makes the PDF look slightly worse to me. If I set "Full" hinting and "Subpixel" AA in Gnome Tweaks, I get the same results as with slight/grayscale.

On my Windows computer, all 4 of the "other" PDFs look the same, but the LMTX PDF also looks different. Here, the glyphs are quite a bit darker, which makes the document look quite a bit worse. I don't think that the Windows version of Firefox includes FreeType, so this probably isn't a FreeType bug.

When I open lmtx.pdf and luahbtex.pdf in Font Forge, I'm seeing identical hints on all of the characters. Perhaps Firefox isn't able to decode Identity-H fonts? Or perhaps LMTX is corrupting the hints, but FontForge has a more lenient parser? Or something else altogether?

The LuaMetaTeX engine isn't open source quite yet, but all of the font code is done in Lua (I think?) which is should be in files named like font-???.lmt at https://source.contextgarden.net/ or https://github.com/contextgarden/context-mirror/. This is also being discussed on the ConTeXt mailing list.

assuming it was hinted originally

Yes, the TeX Gyre fonts are all professionally/manually hinted.

Also, please let me know if you want me to send screenshots of any specific examples.

System Information

Linux

Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Gnome on Fedora 36, with MOZ_ENABLE_WAYLAND=1 set
Display: 2560x1440

Windows

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:103.0) Gecko/20100101 Firefox/103.0
Windows 10 Education, Build 10.0.19044
Display: 1920x1080

Summary: pdfs with sans serif fonts are displayed badly → pdfs with sans serif fonts and Identity-H encoding are displayed badly (with inconsistent/wobbly glyph height and position)
Severity: -- → S3

it may have lost or disrupted the hinting from the original font in some way.

Yes, this guess was correct: ConTeXt was stripping all of the hinting from the embedded fonts.

This issue is now resolved in ConTeXt (1, 2) so I think that this issue can be closed.

Thanks!

Thanks! Closing as not-a-Firefox-bug, then, given comment 5's indication that this was a (now-fixed) bug in LuaMetaTeX / ConTeXt.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: