summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLRendererConfiguration.mm
diff options
context:
space:
mode:
authorm-stephen <truestyle2005@163.com>2019-07-10 10:00:35 +0800
committerGitHub <noreply@github.com>2019-07-10 10:00:35 +0800
commit6b59db8fb0118633e354b4fff5d615a0f095faa7 (patch)
tree3765e70808d7167c22ded18b48c014c4b9a94fb7 /platform/darwin/src/MGLRendererConfiguration.mm
parent18f7e4b84d761623a825498398ef58b79ee39ecd (diff)
downloadqtlocation-mapboxgl-6b59db8fb0118633e354b4fff5d615a0f095faa7.tar.gz
[ios, macos] Default to local rendering of CJK characters, using system font (#14862)
* Change default CJK font from "PingFang" to "Helvetica" * Add CHANGELOG. * Update CHANGELOG. * [ios] Enable client-side rendering and use `Helvetica` by default. Set `MGLIdeographicFontFamilyName` to `NULL` for using your custom remote font. * [ios] Update change log * [ios] Change default CJK configuration in `iosapp` project * [ios] Update comment * [ios] return local font name using default system font. * [ios] Update changelog * [ios] update changelogs & comments * [iOS, macOS]Support mac os * [iOS, macOS] fix bug * [iOS, macOS] update change log * [iOS, macOS] fix nit. * [iOS, macOS] Ability to specify an array of fonts for fallbacks for `localIdeographicFontFamily` * [iOS, macOS] Update comments * [iOS, macOS] Update change log * [iOS, macOS] update for mac OS font family names * Fix nit. * Update platform/ios/CHANGELOG.md Co-Authored-By: Minh Nguyễn <mxn@1ec5.org> * [iOS, macOS] Set `MGLIdeographicFontFamilyName` to a Boolean value `NO` for using your custom remote font. * [iOS, macOS] remove `MGLIdeographicFontFamilyName` from info.plist & update Info.plist Keys.md * [iOS, macOS] remove `MGLIdeographicFontFamilyName` from macOS demo app project and update info.plist Keys.md * [iOS, macOS] update macOS changelog * [iOS, macOS] Change docs * Update Change log * [iOS, macOS] Test case * Update platform/macos/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/macos/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/ios/CHANGELOG.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/darwin/src/MGLRendererConfiguration.mm Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/darwin/test/MGLRendererConfigurationTests.mm Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/macos/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/macos/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/macos/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * [iOS, macOS] update comments * [iOS, macOS] add plist value test && filter for invalid string * [iOS, macOS] fix nit * Update platform/ios/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/ios/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/ios/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/macos/CHANGELOG.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/ios/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * Update platform/ios/docs/guides/Info.plist Keys.md Co-Authored-By: Jason Wray <friedbunny@users.noreply.github.com> * [iOS, macOS] add invalid value type test * Apply own suggestions from code review
Diffstat (limited to 'platform/darwin/src/MGLRendererConfiguration.mm')
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.mm51
1 files changed, 48 insertions, 3 deletions
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm
index d616e93eb2..54bdcaa691 100644
--- a/platform/darwin/src/MGLRendererConfiguration.mm
+++ b/platform/darwin/src/MGLRendererConfiguration.mm
@@ -9,6 +9,7 @@
#endif
static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPre4_0";
+static NSString * const MGLIdeographicFontFamilyNameKey = @"MGLIdeographicFontFamilyName";
@interface MGLRendererConfiguration ()
@property (nonatomic, readwrite) BOOL perSourceCollisions;
@@ -69,10 +70,54 @@ static NSString * const MGLCollisionBehaviorPre4_0Key = @"MGLCollisionBehaviorPr
return mbgl::optional<std::string>();
}
-- (std::string)localFontFamilyName {
- NSString *fontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"];
+- (mbgl::optional<std::string>)localFontFamilyName {
+ return [self _localFontFamilyNameWithPropertyDictionary:[[NSBundle mainBundle] infoDictionary]];
+}
- return fontFamilyName ? std::string([fontFamilyName UTF8String]) : std::string("PingFang");
+- (mbgl::optional<std::string>)_localFontFamilyNameWithPropertyDictionary:(nonnull NSDictionary *)properties {
+
+ std::string systemFontFamilyName;
+#if TARGET_OS_IPHONE
+ systemFontFamilyName = std::string([[UIFont systemFontOfSize:0 weight:UIFontWeightRegular].familyName UTF8String]);
+#else
+ systemFontFamilyName = std::string([[NSFont systemFontOfSize:0 weight:NSFontWeightRegular].familyName UTF8String]);
+#endif
+
+ id fontFamilyName = properties[MGLIdeographicFontFamilyNameKey];
+
+ if([fontFamilyName isKindOfClass:[NSNumber class]] && ![fontFamilyName boolValue])
+ {
+ return mbgl::optional<std::string>();
+ }
+ else if([fontFamilyName isKindOfClass:[NSString class]])
+ {
+ BOOL isValidFont = NO;
+#if TARGET_OS_IPHONE
+ if([[UIFont familyNames] containsObject:fontFamilyName]){
+ isValidFont = YES;
+ }
+#else
+ if([[[NSFontManager sharedFontManager] availableFontFamilies] containsObject:fontFamilyName]){
+ isValidFont = YES;
+ }
+#endif
+ return (fontFamilyName && isValidFont) ? std::string([fontFamilyName UTF8String]) : systemFontFamilyName;
+ }
+ // Ability to specify an array of fonts for fallbacks for `localIdeographicFontFamily`
+ else if ([fontFamilyName isKindOfClass:[NSArray class]]){
+ for(NSString *name in fontFamilyName){
+#if TARGET_OS_IPHONE
+ if([[UIFont familyNames] containsObject:name]){
+ return std::string([name UTF8String]);
+ }
+#else
+ if([[[NSFontManager sharedFontManager] availableFontFamilies] containsObject:name]){
+ return std::string([name UTF8String]);
+ }
+#endif
+ }
+ }
+ return systemFontFamilyName;
}
@end