Closed Bug 1331859 Opened 4 years ago Closed 4 years ago

Use CoreFoundation on macOS to decode legacy Mac-platform font names that are not supported by the web Encoding Standard

Categories

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

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: hsivonen, Unassigned)

References

Details

Attachments

(1 file)

In order to help avoid having to support non-Encoding Standard encodings (bug 1261841) for system font names only when rewriting the converter infrastructure, let's remove support for non-Encoding Standard system font names. This means legacy single-byte Mac encodings except Roman and Cyrillic.

Based on telemetry, Gecko sees these very rarely except for MacHebrew on Mac, which is due to the set of system-bundled fonts containing a font, Raanana, that declares one of its names in MacHebrew, and Firefox enumerates all system fonts. This is not telemetry of the font getting used but the decoder getting instantiated. 

It also happens that Raanana doesn't declare its Hebrew name in another way (Unicode or windows-1255), so removing support for non-Encoding Standard font names has the effect of removing the ability to specify Raanana by its Hebrew name in CSS. (I'm not actually sure if Raanana is the only one, but I think the conclusions here hold anyway.)

https://hsivonen.com/test/moz/raanana.html indicates that Safari supports specifying Raanana by its Hebrew name but Chrome doesn't. That is, by making this change we'd end up with Chrome parity but would break Safari parity. Sites that have been tested in Chrome can already be expected to refer to Raanana at least by its Romanized name.

Alternatives:

 * Including a MacHebrew decoder in Gecko outside the normal converter infrastructure only for the purpose of decoding system font names.

 * Decoding MacHebrew font names on macOS only by calling the system converter API for MacHebrew only.

 * Including a special-case check for the name Raanana when enumerating the system fonts and adding a synthetic entry for the Hebrew name in Gecko's data structures when the Romanized name is seen (and doing the same for other macOS-bundled Hebrew fonts that have a Hebrew name in MacHebrew only if other such fonts exist). (This is my preference for an alternative to outright removal of the ability to specify Raanana by its Hebrew name.)

(Previously: https://groups.google.com/d/msg/mozilla.dev.platform/FDmmJvj8t64/gQfpXEPlBgAJ )
(In reply to Henri Sivonen (:hsivonen) from comment #0)
>  * Decoding MacHebrew font names on macOS only by calling the system
> converter API for MacHebrew only.

This is what I'd suggest we do. It's really trivial to implement: we can just call CFStringCreateWithBytes(..., kCFStringEncodingMacHebrew), passing in the name data from the font, and then CFStringGetCharacters to get the Unicode out.

I confirmed locally on macOS 10.12 that disabling the use of the x-mac-hebrew converter in gfxFontUtils::DecodeFontName breaks support for the name "רעננה" on your test page, and then adding the suggested code based on CFStringCreateWithBytes restores it.

Happy to provide a patch if we agree to go this way.
(In reply to Jonathan Kew (:jfkthame) from comment #1)
> (In reply to Henri Sivonen (:hsivonen) from comment #0)
> >  * Decoding MacHebrew font names on macOS only by calling the system
> > converter API for MacHebrew only.
> 
> This is what I'd suggest we do. It's really trivial to implement: we can
> just call CFStringCreateWithBytes(..., kCFStringEncodingMacHebrew), passing
> in the name data from the font, and then CFStringGetCharacters to get the
> Unicode out.
> 
> I confirmed locally on macOS 10.12 that disabling the use of the
> x-mac-hebrew converter in gfxFontUtils::DecodeFontName breaks support for
> the name "רעננה" on your test page, and then adding the suggested code based
> on CFStringCreateWithBytes restores it.
> 
> Happy to provide a patch if we agree to go this way.

OK. Let's do that.
Updating the bug summary to reflect the decision to use CoreFoundation to handle the decoding for us.
Summary: Remove support for system font names in legacy single-byte Mac encodings except Roman and Cyrillic → Use CoreFoundation on macOS to decode legacy Mac-platform font names that are not supported by the web Encoding Standard
This implements the decoding using CFString as a helper, as above. Currently, no standard font that I'm aware of will hit this codepath, but it can be tested by removing the ENCODING_ID_MAC_HEBREW entries from gfxFontUtils::gMacFontNameCharsets; then the Hebrew name of Raanana will be handled here instead.
Attachment #8828427 - Flags: review?(jmuizelaar)
Attachment #8828427 - Flags: review?(jmuizelaar) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/9280d791dff29720d5a78b80da04c32be40bf5bf
Bug 1331859 - For legacy Mac-platform font names that our standard decoders don't handle, try using CoreFoundation to convert to Unicode. r=jrmuizel
https://hg.mozilla.org/mozilla-central/rev/9280d791dff2
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
You need to log in before you can comment on or make changes to this bug.