Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Allow specifying multiple fonts or font families for local font rendering #189

Merged
merged 2 commits into from
Apr 25, 2020

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Mar 1, 2020

Removed MGLIdeographicFontFamilyName validation from MGLRendererConfiguration, since mbgl::LocalGlyphRasterizer performs more robust validation. Removed C++ from MGLRendererConfiguration interface, implementation, and tests and simplified the logic.

Pass all the specified font and font family names into mbgl so that mbgl::LocalGlyphRasterizer can form a full font cascade list.

  • Plumb through font name list
  • Clean up MGLRendererConfiguration
  • Remove font family validation from MGLRendererConfiguration
  • Clean up MGLIdeographicFontFamilyName documentation
  • Plumb through an array of strings instead of a line-delimited string
  • Update submodule

Fixes #105. Depends on #280, mapbox/mapbox-gl-native#16253, and mapbox/mapbox-gl-native#16428.

/cc @mapbox/maps-ios

@1ec5
Copy link
Contributor Author

1ec5 commented Mar 1, 2020

#105 (comment) has some screenshots of boldfaced CJK.

To demonstrate per-character font substitution, I made the following modifications to specify a font cascade list and override road labels:

diff --git a/platform/macos/app/Info.plist b/platform/macos/app/Info.plist
index 21b86bfc7..6b85554dc 100644
--- a/platform/macos/app/Info.plist
+++ b/platform/macos/app/Info.plist
@@ -54,5 +54,11 @@
        <string>NSApplication</string>
        <key>NSSupportsAutomaticGraphicsSwitching</key>
        <true/>
+       <key>MGLIdeographicFontFamilyName</key>
+       <array>
+               <string>HAN NOM A</string>
+               <string>Noto Sans CJK JP Black</string>
+               <string>Hiragino Sans W5</string>
+       </array>
 </dict>
 </plist>
diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m
index 1ab8b690b..859b53aa0 100644
--- a/platform/macos/app/MapDocument.m
+++ b/platform/macos/app/MapDocument.m
@@ -496,6 +496,8 @@ NSArray<id <MGLAnnotation>> *MBXFlattenedShapes(NSArray<id <MGLAnnotation>> *sha
 
 - (void)updateLabels {
     [self.mapView.style localizeLabelsIntoLocale:_isLocalizingLabels ? nil : [NSLocale localeWithLocaleIdentifier:@"mul"]];
+    MGLSymbolStyleLayer *roadLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"road-label"];
+    roadLayer.text = [NSExpression expressionForConstantValue:@"日本語 ㋿元年 浮亭鿍"];
 }
 
 - (void)applyPendingState {

All roads are labeled with the nonsensical string “日本語 ㋿元年 浮亭鿍”. The font families were chosen to require font substitution: HAN NOM A predates Unicode 8.0 and thus lacks both (Reiwa era) and (hill), while Noto Sans CJK JP predates Unicode 11.0 and thus lacks 鿍. The font faces were chosen to differ in weights, to highlight the substitution: HAN NOM A is the faintest character, while Hiragino Sans W5 is medium and Noto Sans CJK JP Black is extra bold.

substitution

In the absence of mapbox/mapbox-gl-js#9362, I cheated a bit by enabling local font rendering for the Enclosed CJK Letters and Months block that contains ㋿.

diff --git a/src/mbgl/util/i18n.cpp b/src/mbgl/util/i18n.cpp
index 885c8ec3d..c8fd08c5a 100644
--- a/src/mbgl/util/i18n.cpp
+++ b/src/mbgl/util/i18n.cpp
@@ -418,7 +418,8 @@ bool allowsIdeographicBreaking(char16_t chr) {
 bool allowsFixedWidthGlyphGeneration(char16_t chr) {
     // Mirrors conservative set of characters used in glyph_manager.js/_tinySDF
     return isInCJKUnifiedIdeographs(chr) || isInHangulSyllables(chr)
-        || isInKatakana(chr) || isInHiragana(chr);
+        || isInKatakana(chr) || isInHiragana(chr)
+        || isInEnclosedCJKLettersandMonths(chr);
 }
 
 bool allowsVerticalWritingMode(const std::u16string& string) {

@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch from 98c7b4f to d404f5f Compare March 18, 2020 06:32
@knov knov removed this from the release-vanillashake milestone Mar 30, 2020
@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch from d404f5f to d6c4893 Compare April 14, 2020 23:14
@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch 3 times, most recently from ed3d631 to 6737341 Compare April 22, 2020 04:56
@1ec5 1ec5 marked this pull request as ready for review April 22, 2020 05:12
@1ec5 1ec5 requested a review from a team April 22, 2020 05:12
@1ec5 1ec5 removed the 🚧 WIP label Apr 22, 2020
@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch from 6737341 to 8634e51 Compare April 23, 2020 03:21
Copy link
Contributor

@julianrex julianrex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thank you!

@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch from 8634e51 to 38c38e0 Compare April 23, 2020 04:18
@1ec5
Copy link
Contributor Author

1ec5 commented Apr 24, 2020

I’ve added a snapshot test of local glyph rasterization, since mbgl’s UnitTestApp has proven so difficult to test on a device: mapbox/mapbox-gl-native#16259 (comment).

@1ec5 1ec5 force-pushed the 1ec5-local-font-names-105 branch 3 times, most recently from 176aa7b to 8ac7201 Compare April 24, 2020 19:18
…al font rendering

Removed MGLIdeographicFontFamilyName validation from MGLRendererConfiguration, since mbgl::LocalGlyphRasterizer performs more robust validation. Removed C++ from MGLRendererConfiguration interface, implementation, and tests for simplicity.

Pass all the specified font and font family names into mbgl so that mbgl::LocalGlyphRasterizer can form a full font cascade list.
Disabled on iOS for now due to actual differences in Core Text behavior. Disabled on macOS because the test is too strict without any tolerance.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file ios macOS rendering Related to rendering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MGLIdeographicFontFamilyName should accept font display or PostScript name
3 participants