Closed Bug 1371386 Opened 7 years ago Closed 4 years ago

Firefox does not always prefer `font.name-list.emoji` when showing emojis

Categories

(Core :: Layout: Text and Fonts, enhancement, P3)

53 Branch
enhancement

Tracking

()

RESOLVED FIXED
82 Branch
Webcompat Priority P3
Tracking Status
firefox82 --- fixed

People

(Reporter: wisniewskit, Assigned: jfkthame)

References

Details

(Whiteboard: [webcompat])

Attachments

(12 files, 1 obsolete file)

297 bytes, text/html
Details
10.40 KB, patch
Details | Diff | Splinter Review
1.55 KB, text/html
Details
155.72 KB, image/png
Details
194.35 KB, image/png
Details
192.58 KB, image/png
Details
38.80 KB, image/png
Details
1.45 KB, text/html
Details
85.75 KB, image/png
Details
47 bytes, text/x-phabricator-request
Details | Review
66.85 KB, image/png
Details
153.45 KB, image/png
Details
Attached file testcase.html
Given the attached test-case (reduced from webcompat.com issues #6001 and #6915), Chrome and Safari render both lines with all of the glyphs taken from the Apple Color Emoji font. Firefox prefers the glyphs from Times New Roman instead. On my MacBook, I can get Firefox to prefer Apple Color Emoji when there is no CSS font-family specified by the web page, by changing the about:config value font.name-list.serif.x-western font-list to have Apple Color Emoji as its first value. However, if CSS specifies the font (even sans-serif or not including Times New Roman) then Firefox will still prefer the Times New Roman glyphs. By contrast, Chrome and Safari seem to always prefer Apple Color Emoji glyphs, even the CSS specifies the font-family to be Times or Times New Roman as per the test-case. Of course I would suggest that if we change to match the behavior of Chrome/Safari in either case, that we don't limit this glyph-preference to just Apple Color Emoji, but whatever emoji font Firefox preferes on the system (be it Apple Color Emoji to EmojiOne).
Flags: webcompat?
Jonathan, is there something specific I should CC on this bug?
Flags: needinfo?(jfkthame)
So the main issue here, I think, is that our font selection process doesn't recognize the presence of VS16 (U+FE0F) to request "emoji-style" presentation and use that to force a search for a font with color emoji glyphs, it just runs the standard font matching algorithm and takes the first match that supports the given codepoint. If we did font matching on a per-cluster basis (as per bug 543200) instead of largely per-codepoint, that would tend to help, but we probably also need special handling for the emoji presentation sequences. The font-fallback code does some of this, but that doesn't help if the default font for the element already supports the base character in question (such as the old smiley-face symbol, or the digits). cc'ing m_kato, who I'm guessing might be interested in this.
Flags: needinfo?(jfkthame)
Priority: -- → P3
Any update on the progress of this? Also is this behavior spec-able at all? On Edge as well the emojis are rendered but they are different looking emojis.
See Also: → 1430591
See Also: 1430591
Assignee: nobody → m_kato
Hey Makato, is there an update on the progress of this?
Adding a ni? for good measure for comment 4.
Flags: needinfo?(m_kato)
(In reply to Jonathon Kereliuk from comment #4) > Hey Makato, is there an update on the progress of this? I have WIP, but no time to review & land for 60 cycle. So I will work this for 61 cycle.
Flags: needinfo?(m_kato)
Comment on attachment 8981084 [details] [diff] [review] Use emoji font for keycap number character (0-9) is possible emoji presentation. Gecko doesn't select emoji font for these characters with variation selector-16 because it doesn't check whether selected font is color/emoji font. Normally, number character is included in normal font, so it usually select first font even if next is VS16. So if next character is VS16, we should try color font if there is in font list. Android 4.3 doesn't have emoji font, so it should skip reftest.
Attachment #8981084 - Flags: review?(jfkthame)
Comment on attachment 8981084 [details] [diff] [review] Use emoji font for keycap Review of attachment 8981084 [details] [diff] [review]: ----------------------------------------------------------------- Although the original example was about keycaps, this change could affect font selection for any character with a possible emoji presentation; as such, the commit message should reflect that rather than being so specific. Something more like "Make font selection try to find a color font for characters where emoji presentation is requested, even if this means ignoring fonts in the specified font-family list" would be clearer, I think. Clearing review? for now, pending consideration of the question re gfxFontGroup::FindFontForChar behavior. ::: gfx/thebes/gfxFontEntry.h @@ +485,5 @@ > bool mGrFaceInitialized : 1; > bool mCheckedForColorGlyph : 1; > bool mCheckedForVariationAxes : 1; > + bool mCheckedForSomeColorTables : 1; > + bool mHasSomeColorTables : 1; I believe adding flags here will increase the size of gfxFontEntry by 8 bytes (assuming a 64-bit build), because of alignment (note the comment at the top of the group of bit flags); that seems a bit unfortunate, but if we need the flags I guess we'll have to accept it. I wonder, though, if we can re-engineer something so as to eliminate or merge a couple of the already-existing flags, so as to stay within a total of 24 bits? AFAICT, the mFixedPitch flag is only relevant on macOS, so we could move it to the platform subclass; if we could save another flag as well, we'd avoid the size increase here. ::: gfx/thebes/gfxTextRun.cpp @@ +2952,5 @@ > + if (aNextCh == kVariationSelector16 && isPossibleEmojiPresentation) { > + gfxFontEntry *fe = ff.FontEntry(); > + if (!fe->HasSomeColorTables(font)) { > + // No color font. Try next > + continue; If I'm following the logic correctly, I think this will be a problem for the case where aCh has a possible emoji presentation, but is not actually supported by any available color font. In that case, we should still be using the first font from the list that supports aCh by itself; but this code will have caused us to ignore it, and we'll end up with whatever fallback happens to pick. So for example on Android, <div style="font-family: foo, bar, serif">1&#xfe0f;</div> will look for a color glyph for "1", but not finding one, it will have ignored the "foo" and "bar" fonts that were specified, and probably end up using Roboto. Am I reasoning correctly here? If so, I think this is an issue we need to handle better: if we don't actually find a color glyph, we should end up with the same font as we'd have used in the absence of the VS16 selector.
Attachment #8981084 - Flags: review?(jfkthame)
(In reply to Jonathan Kew (:jfkthame) from comment #10) > Comment on attachment 8981084 [details] [diff] [review] > Use emoji font for keycap > > Review of attachment 8981084 [details] [diff] [review]: > ----------------------------------------------------------------- > > Although the original example was about keycaps, this change could affect > font selection for any character with a possible emoji presentation; as > such, the commit message should reflect that rather than being so specific. > Something more like "Make font selection try to find a color font for > characters where emoji presentation is requested, even if this means > ignoring fonts in the specified font-family list" would be clearer, I think. > > Clearing review? for now, pending consideration of the question re > gfxFontGroup::FindFontForChar behavior. > > ::: gfx/thebes/gfxFontEntry.h > @@ +485,5 @@ > > bool mGrFaceInitialized : 1; > > bool mCheckedForColorGlyph : 1; > > bool mCheckedForVariationAxes : 1; > > + bool mCheckedForSomeColorTables : 1; > > + bool mHasSomeColorTables : 1; > > I believe adding flags here will increase the size of gfxFontEntry by 8 > bytes (assuming a 64-bit build), because of alignment (note the comment at > the top of the group of bit flags); that seems a bit unfortunate, but if we > need the flags I guess we'll have to accept it. Hmm, it might be unnecessary to use bool flag for checked or not. Because I only check whether font has tables for color font. > I wonder, though, if we can re-engineer something so as to eliminate or > merge a couple of the already-existing flags, so as to stay within a total > of 24 bits? AFAICT, the mFixedPitch flag is only relevant on macOS, so we > could move it to the platform subclass; if we could save another flag as > well, we'd avoid the size increase here. > > ::: gfx/thebes/gfxTextRun.cpp > @@ +2952,5 @@ > > + if (aNextCh == kVariationSelector16 && isPossibleEmojiPresentation) { > > + gfxFontEntry *fe = ff.FontEntry(); > > + if (!fe->HasSomeColorTables(font)) { > > + // No color font. Try next > > + continue; > > If I'm following the logic correctly, I think this will be a problem for the > case where aCh has a possible emoji presentation, but is not actually > supported by any available color font. In that case, we should still be > using the first font from the list that supports aCh by itself; but this > code will have caused us to ignore it, and we'll end up with whatever > fallback happens to pick. > > So for example on Android, > > <div style="font-family: foo, bar, serif">1&#xfe0f;</div> > > will look for a color glyph for "1", but not finding one, it will have > ignored the "foo" and "bar" fonts that were specified, and probably end up > using Roboto. > > Am I reasoning correctly here? If so, I think this is an issue we need to > handle better: if we don't actually find a color glyph, we should end up > with the same font as we'd have used in the absence of the VS16 selector. Android 4.3 case should select serif, but if using macOS, we should select Apple's color font that is in preference because that is emoji presentation. After looking for preferences font, if there is no font for color, I should select first selected font that is monochrome. I will try it.

Migrating Webcompat whiteboard priorities to project flags. See bug 1547409.

Webcompat Priority: --- → ?

See bug 1547409. Migrating whiteboard priority tags to program flags.

Webcompat Priority: ? → P3
Flags: webcompat?

Here's a testcase I've just been using to compare our behavior (without / with the patch here) to Safari's on macOS for various font-family settings. This testcase assumes the DejaVu Sans font (which has b/w versions of some of the U+1Fxxx characters whose default rendering should be emoji style) is installed.

I'll also attach screenshots showing the rendering I get.

Regarding the above testcase: I think Safari's default rendering (the initial column) is correct, with U+2601 defaulting to text-style and U+1F603 defaulting to emoji-style, and the variation selectors providing the ability to override this.

When DejaVu Sans is listed as the first font in font-family, I think Safari is wrong to ignore the U+FE0F variation selector and render the text-style glyphs in all cases; on the rows with explicit U+FE0F it should search for a color-emoji font, either later in the font-family list or via a fallback search.

Interestingly, when Apple Color Emoji is listed as the first font, Safari correctly (IMO) ignores it when U+FE0E is present, and falls back to a text-style rendering from a different font (either DejaVu Sans, if listed in font-family, or a default symbol font from the system if it supports the character).

The last screenshot shows that while some of the cases are improved compared to current Nightly, not all of them are handled correctly yet.

Blocks: 1567178
See Also: → 1610391
OS: Unspecified → All
Hardware: Unspecified → All
Summary: Firefox does not prefer Apple Color Emoji to Times New Roman on OSX, but Chrome/Safari do. → Firefox does not always prefer `font.name-list.emoji` when showing emojis
Attached image testcase on Windows

Changing the title as this also affects Windows.

This is a version of attachment 9073332 [details] that is better suited to testing on Windows, using font names available there.

Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0cad1ef724ee Take account of requirements for emoji-style or text-style presentation during font selection & fallback. r=m_kato
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f8cda577ac2f Take account of requirements for emoji-style or text-style presentation during font selection & fallback. r=m_kato
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 82 Branch
Regressions: 1661570
Assignee: m_kato → jfkthame
Blocks: 1661621
Regressions: 1661677
No longer regressions: 1661677
Regressions: 1661677
Flags: needinfo?(jfkthame)
Regressions: 1667974
Attachment #9057853 - Attachment is obsolete: true
Regressions: 1674228
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: