-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Allow using system fonts or fonts bundled in the app #7862
Comments
Agreed. From the perspective of an iOS developer, specifying custom fonts in Studio is more of a bug than a feature; they’d expect the SDK to use system or locally bundled fonts for any custom font styling.
mbgl uses SDF glyphs rather than a standard font format, so one idea for #7774 and #7528 would be to use a system text layout/rendering library like Core Text (via HarfBuzz) that could use local fonts out of the box. /cc @ChrisLoer |
That should be pretty easy once HarfBuzz is in place. We'd also have to include FreeType to do the Glyph->SDF rendering on the client side instead of in node-fontnik. After talking with @yhahn, I've actually been thinking about starting the HarfBuzz implementation this way so we can get a working client implementation before we start trying to define a new font server API. |
I've got a crude version of this working for iOS on the |
PR #10522 is motivated by the narrower goal of making CJK glyphs load faster, but if we end up with Android/iOS implementations that can extract glyph metrics, it could turn into a complete solution for this issue, if not #7774. Freetype
TinySDF
/cc @mourner |
@ChrisLoer and I paired on the coretext-hack branch to achieve the same functionality as the cloer_harfbuzz branch mentioned in #7862 (comment), but using TinySDF and Core Text instead of Harfbuzz and FreeType to perform complex text shaping using system fonts: |
As of e3645ec on that branch, If a font bundled with the application is specified in |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This should still happen. |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
By way of an update, #10572 long ago added the ability to render glyphs from local or system fonts, but it was enabled only for a limited range of Chinese and Japanese (and later Korean) characters, which we could reasonably expect to be monospaced. This was largely because the approach we took required hard-coding glyph metrics instead of getting them from the font. #16253 overhauls the local glyph rendering code on iOS and macOS, giving developers more flexibility in specifying local fonts but also trying harder to match the intended fonts by default. mapbox/mapbox-gl-native-ios#105 (comment) has some screenshots of local font selection in action. There’s still code in Existing remote glyph rasterization (note missing Amharic in Ethiopia but intact Bengali in Bangledesh): #16253 rigged for local glyph rasterization of all scripts (note dotted circle ◌ on combining characters): |
More discussion specific to iOS and macOS regarding the existing Core Text/TinySDF approach: The gist of the coretext-hack branch in #7862 (comment) is that the following code in mapbox-gl-native/src/mbgl/layout/symbol_layout.cpp Lines 179 to 182 in 66ac554
mapbox-gl-native/src/mbgl/text/shaping.cpp Lines 425 to 428 in 4da54d6
This mapping needs to take place when gathering glyph dependencies, not later when rasterizing glyphs as LocalGlyphRasterizer currently does. At that early stage, the font descriptor can be created and resolved just once for an entire run of text instead of per-glyph. This not only improves performance but also respects ligatures and other complex text. Since glyph IDs differ from one font to the next, the font information needs to be stored alongside each glyph ID. The good news is that glyph dependencies are already bucketed by font stack as of #12624. So instead of adding to the glyph dependencies of the font stack as specified by the style, Going beyond the basic requirements, Core Text provides a number of text layout functionality that would be useful as overrides to mbgl’s built-in shaping code. For example:
We could move the homegrown code into platform/default/ implementations and omit them from iOS and macOS builds, reducing the binary size. The 1ec5-coretext-shaping-7862 has some hacky code that revives and modernizes the old coretext-hack branch based on the approach outlined here. Instead of redefining glyph dependencies across the board, it completely circumvents mbgl’s text shaping in favor of a new Core Text–based implementation, with an eye toward eliminating the need for a local glyph rasterizer. This branch currently renders the wrong glyphs, making a mess of things, because each feature’s |
Is this gonna be ever possible? |
This topic was discussed back in 2014 (#260) and ought to be revisited now that we've expanded the SDK.
In many cases, developers who implement custom styles or change fonts via runtime-styling are going to want to use the same fonts in their maps as they do in the UI of their app, whether that's using the system fonts or bundling in their own.
Currently, fonts/glyphs are downloaded by Mapbox even if they might already exist on the device. This is particularly heavyweight for offline: #4069.
Additionally, instead of relying on a version of Arial Unicode MS to be downloaded with the style for fallback glyph rendering, we should consider falling back to the default system font instead. I'm not sure what the implications are here for complex text rendering: #7774
The text was updated successfully, but these errors were encountered: