Closed Bug 1558375 Opened 5 years ago Closed 5 years ago

Some fonts render incorrectly on Android

Categories

(Core :: Graphics: Text, defect, P3)

Unspecified
Android
defect

Tracking

()

RESOLVED FIXED
mozilla69
Tracking Status
firefox69 --- fixed

People

(Reporter: v+mozbug, Assigned: jfkthame)

References

Details

Attachments

(7 files, 1 obsolete file)

Attached file test-font-lines.html

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0

Steps to reproduce:

Referenced a font in my .html file. (Dump the two .ttf and the .html attachments in a test directory, open the .html file)

Actual results:

Rendered incorrectly. Both lines should look similar; and do on Windows (but not identical, they are different fonts). But on Android Firefox, the DFKai-SB font is goofy looking.

Expected results:

Should have rendered correctly. Works on Android Chrome, Windows Firefox.

Two different font files are supplied, with a similar style of Chinese fonts (Both are "Kai Ti" fonts: sort of like Roman and Times-Roman, versus Helvetica being quite different). The one font renders fine everywhere I've tried it, and the DFKai-SB font renders on Windows in all browsers, and on Android Chrome, but not on Android Firefox. A year ago, it didn't render properly on Android Chrome, either, but it does now, so maybe there was a platform enhancement that Chrome jumped on and Firefox hasn't yet? Or maybe Chrome got enhanced, meanwhile? I can't tell.

I''m not sure how to tell what version of FF is on Android, but it is ever-fresh, released version.

Attached file kaiu.ttf
Attached file KaiTi.zip

Have to decompress this one before testing

Component: General → Layout: Text and Fonts
OS: Unspecified → Android
Product: Firefox for Android → Core

Could you attach a screenshot showing the broken rendering you see? Thanks.

Flags: needinfo?(v+mozbug)
Flags: needinfo?(v+mozbug)

That looks like a font that's doing weird things with TrueType instructions. I believe FreeType has some kind of special handling for this, but it may depend on build settings of some kind.... I don't recall details exactly.

Ah, yes... see tt_check_trickyness_family() in freetype2/src/truetype/ttobjs.c. It may be that we're not using the right FreeType options to allow its "trickiness" handling to work; there's some interaction with hinting etc, iirc.

Component: Layout: Text and Fonts → Graphics: Text

Not familiar with FreeType, but I agree that the font is somewhat different than most fonts. Most of the font subset tools online produce garbage with this font, so I had to use Python fonttools module to make subset fonts from it. I was glad to learn about fonttools, and that it did the job, looks like a comprehensive package, but that probably won't help Firefox if it uses FreeType.

On the other hand, you make it sound like FreeType can handle the font, if the settings are checked/used properly, which might be a relatively easy fix? Mostly in testing, to be sure existing cases continue to work?

Attachment #9072125 - Attachment mime type: text/plain → text/html
Attachment #9072125 - Attachment is obsolete: true
Attachment #9072126 - Attachment mime type: text/plain → text/html
Attachment #9072126 - Attachment is obsolete: true
Attachment #9072126 - Attachment is obsolete: false

One point to note for testing this is that the kaiu.ttf font will not load via @font-face in Nightly builds unless the gfx.downloadable_fonts.otl_validation pref is toggled to false, because of issues with its OpenType layout tables.

Looking at the FT2 font backend, I think the problem occurs because we disable hinting on Android (for smoother pinch-zoom etc), but using the FT_LOAD_NO_AUTOHINT flag in particular breaks the rendering of "tricky" faces like this where the "hinting" instructions are required not just for better grid alignment but for basic rendering of the glyph components.

We probably need to ensure we avoid setting that load flag for fonts with the TRICKY face flag. There are a bunch of places where we set up loadFlags for FreeType; I'm not sure how many of these are strictly necessary to patch, but it's probably best to keep them all consistent.

Priority: -- → P3
Pushed by jkew@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/6153e6bb58e1
Don't set the FT_LOAD_NO_AUTOHINT flag for fonts that have FT_FACE_FLAG_TRICKY, to avoid broken rendering. r=lsalzman

Looks like CairoLockedFTFace() in SkFontHost_cairo can fail, so we need to null-check the face before using it.

https://treeherder.mozilla.org/#/jobs?repo=try&tier=1&revision=b9355c948961ed38e2a74fb5ccebd50f77bc55ee

Flags: needinfo?(jfkthame)
Pushed by jkew@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7d79dcab14bd
Don't set the FT_LOAD_NO_AUTOHINT flag for fonts that have FT_FACE_FLAG_TRICKY, to avoid broken rendering. r=lsalzman
Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla69
Assignee: nobody → jfkthame
See Also: → 1615195
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: