-
Notifications
You must be signed in to change notification settings - Fork 122
MGLIdeographicFontFamilyName should accept font display or PostScript name #105
Comments
@chloekraw I believe it is already implemented in Android https://github.com/mapbox/mapbox-gl-native/blob/e373d8a5924e4f4cf3904ecacbf1d1cf86a5d60f/platform/android/src/text/local_glyph_rasterizer.cpp#L79 Not implemented on iOS / macOS. Do we need to support only 'Bold' style or other font styles as well? For instance:
|
@mapbox/maps-ios there's a request to reach GL JS parity (see OP) with our implementation of font-weight in LocalGlyphRasterizer: https://github.com/mapbox/mapbox-gl-native-ios/blob/master/platform/darwin/src/local_glyph_rasterizer.mm#L29 Apparently Android APIs may prevent us from supporting cc @mapbox/maps-android |
I poked around the git commit history and it looks like we did add a I'm updating the OP of this ticket to match the actual work that would need to happen. cc @kkaefer |
fontWeight
based on text-font
in localIdeographFontFamily
LocalGlyphRasterizer
As stated in this documentation,
It would be possible to check against A more common approach to validating fonts is to create an
I don’t think A better solution would be to pass all the names into mbgl verbatim. Then, mbgl would create a font descriptor for each name interpreted as a font PostScript name, font display name, and font family name, in that order. Each of these font descriptors would go into a |
LocalGlyphRasterizer
I’m not sure why this is necessary, because the JavaScript implementation of TinySDF relies on the |
This is quite feasible as long as we rely on the system to match each The Hiragino font families have numeric weights, not keywords, in the display names. Here’s Hiragino Sans W9: Note that few CJK fonts come with an explicit “italic” style font. Instead, it’s common for a specific, cursive-like style to be distributed as the normal font in a separate font family. |
The assumption during that PR’s development was that there would be an installed font family named “PingFang” that includes a font face with the style “Bold”. In fact, Apple systems come with a font family named “PingFang HK”, “PingFang SC”, or “PingFang TC”, with the styles “Thin”, “Light”, “Ultralight”, “Regular”, “Medium”, and “Semibold”. Nothing seemed to happen, because Core Text couldn’t find a font face matching either criteria. Instead, it fell back to the first CJK font in the cascade list, which happened to be PingFang TC Regular: mapbox/mapbox-gl-native#16253 (comment). It is possible to create a font based on a font family name and a font weight, as the commented-out, since-removed |
It’s also possible to create a font based on a font family name and font style name (also known as the font face). As it happens, we can count on the font stack (a symbol layer’s
For example, given the following settings:
the font cascade list would be:
The idea is that, if the developer has uploaded a custom font to Studio, they would prefer the SDK to use an identically named font that they’ve bundled with the application or that is already installed on the system. I think these heuristics would be more intuitive and better respect Studio’s role in the design process, but we’d need to make sure it doesn’t represent a backwards-incompatible change and doesn’t put developers in a catch-22 if they also want the same style JSON to render using the same fonts on other platforms. |
I still think sniffing traits out of (freeform) font display names is an error-prone approach that will come back to haunt us when we expand local font rendering to scripts beyond CJK – at which point “Italic”, “Condensed”, “Mono”, etc. all become common enough that we’d have to detect these keywords too. (This wouldn’t be an issue if the Fontstack API could return metadata about a font instead of the font itself. Then we’d just plug that metadata into Core Text to get the best local match.) As a first step, I’m going to add font stack awareness to mapbox/mapbox-gl-native#16253 but leave out the sniffing bit:
This simpler heuristic will automatically use any installed font that happens to match one that’s available in Studio. If it’s a font that’s unlikely to be installed, the developer can bundle the font with their application, assuming they have distribution rights. This is akin to how fonts normally work in HTML and CSS. The global setting |
Developers who use
localIdeographFontFamily
and specify atext-font
with "Bold" in the name on some layers are expecting the text of those layers to show up as bolded on iOS, just like they do on Web and Android.It looks like we did add a
CoreText
-basedLocalGlyphRasterizer
implementation on darwin in mapbox/mapbox-gl-native#10572, but for some reason, passing in different font weight values doesn't actually change the font weight: mapbox/mapbox-gl-native#10572 (comment). So, this ticket tracks debugging this issue further.Note that the existing implementations are slightly different due to limitations on each platform:
To achieve this effect on Android, we use the platform API
android.graphics.Typeface
inLocalGlyphRasterizer
to draw the glyphs locally.Typeface
only supports a limited number of formatting options (bold, bold italic, italic, normal) in API 14 (our minimum deployment target) and does not support the specification of a numeric weight value until API 28.On GL-JS, we check the name of the font on each layer and change the
fontWeight
if the font's name contains the word "Bold", "Medium", or "Light":The text was updated successfully, but these errors were encountered: