Closed Bug 1980258 Opened 7 months ago Closed 7 months ago

Forbid use of Cutive Mono as a fallback font

Categories

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

Unspecified
Android
defect

Tracking

()

RESOLVED FIXED
143 Branch
Tracking Status
firefox143 --- fixed

People

(Reporter: dholbert, Assigned: jfkthame)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Android devices[1] seem to have a system font called "Cutive Mono" preinstalled that Firefox will use if asked (via font-family) and will also use as a fallback in some cases to fill in missing glyphs in other fonts. Unfortunately this font promises support for certain glyphs (e.g. the "ff" ligature) which in fact it just has a transparent glyph for, so it's not a good fallback.

In contrast, Chrome doesn't use this font at all, even when it's explicitly requested via font-family, so they don't run into this problem.

We should probably refuse to use this font, as a system-font at least (particularly as a fallback, but also we're probably fine to refuse it in general, if that's easier, given that Chrome seems to do that).

(More details in bug 1978248.)

Searching for the word "block" in files that have "Font" in the name, I found one possibly-relevant snippet to draw inspiration from perhaps:
https://searchfox.org/mozilla-central/rev/ab26427a8d31be475be11bbae0e04c84cc7f20ef/gfx/thebes/CoreTextFontList.cpp#318-330

// Bug 1360309, 1393624: several of Apple's Chinese fonts have spurious
// blank glyphs for obscure Tibetan and Arabic-script codepoints.
// Blocklist these so that font fallback will not use them.
if (mRequiresAAT &&
    (FamilyName().EqualsLiteral("Songti SC") ||
     FamilyName().EqualsLiteral("Songti TC") ||
     FamilyName().EqualsLiteral("STSong") ||
     // Bug 1390980: on 10.11, the Kaiti fonts are also affected.
     FamilyName().EqualsLiteral("Kaiti SC") ||
     FamilyName().EqualsLiteral("Kaiti TC") ||
     FamilyName().EqualsLiteral("STKaiti"))) {
  charmap->ClearRange(0x0f6b, 0x0f70);
  charmap->ClearRange(0x0f8c, 0x0f8f);

Maybe we want something like that -- though that's in our macOS backend ("CoreText" in the name), so really we want to target our Android font backend (https://searchfox.org/mozilla-central/source/gfx/thebes/AndroidSystemFontIterator.cpp). Presumably we want to clear the range for the known-broken glyphs for this font, like that CoreTextFontList snippet does -- or just skip the font altogether, whatever's easier.

Yeah, we could do something along those lines, to mask out the offending spuriously-blank codepoints; or alternatively we could skip the font entirely (which in effect seems to be what Chrome does, according to your testing). Either way, adding code to work around specific broken fonts makes me sad, but sometimes it has to be done.

Looking through Cutive Mono, there are a number of characters that are present in the 'cmap' but map to blank glyphs (other than "expected" ones like nonmarkingreturn and space):

U+0091, 0092, 0093, 0094, 009A, 009B, 009D

  • these are C1 control codes that are not expected to be printable characters, but nevertheless it seems like bad form to implement them as blank glyphs that will be indistinguishable from space

U+2074

  • this is SUPERSCRIPT FOUR; no idea how that ended up in there

U+FB00, FB03, FB04

  • these are the presentation-form ligature codepoints we've been concerned with

So if we mask all these codepoints in Cutive Mono, we should avoid the bad-fallback problem (while still allowing the font to be used if explicitly requested).

I'm attaching a WIP patch that I think should work here (not flagging for review as I haven't actually built or tested it yet). For now, I've pushed it to try (https://treeherder.mozilla.org/jobs?repo=try&revision=01751e91b7e04093302c237635196fe350d10713) to check that it didn't totally break things.

Confirmed that the Fenix build from tryserver refuses to use the blank ligature character from Cutive Mono, as expected. So in https://dholbert.org/tests/1978248/test-cutive.html, the falls back to a different font (and remains visible).

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Pushed by jkew@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/e7b4decd6df6 https://hg.mozilla.org/integration/autoland/rev/ee7042db2b93 Mask out spuriously-blank codepoints in Cutive Mono font on Android. r=layout-reviewers,emilio
Status: ASSIGNED → RESOLVED
Closed: 7 months ago
Resolution: --- → FIXED
Target Milestone: --- → 143 Branch
QA Whiteboard: [qa-triage-done-c144/b143]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: