-
Notifications
You must be signed in to change notification settings - Fork 122
Allow specifying multiple fonts or font families for local font rendering #189
Conversation
fae2de7
to
98c7b4f
Compare
#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. 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) { |
98c7b4f
to
d404f5f
Compare
d404f5f
to
d6c4893
Compare
ed3d631
to
6737341
Compare
6737341
to
8634e51
Compare
There was a problem hiding this 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!
8634e51
to
38c38e0
Compare
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). |
176aa7b
to
8ac7201
Compare
…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.
8ac7201
to
288194c
Compare
Removed
MGLIdeographicFontFamilyName
validation from MGLRendererConfiguration, sincembgl::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.MGLIdeographicFontFamilyName
documentationFixes #105. Depends on #280, mapbox/mapbox-gl-native#16253, and mapbox/mapbox-gl-native#16428.
/cc @mapbox/maps-ios