From bb33c1f75a94c482b78484c6426c01aadf57eac0 Mon Sep 17 00:00:00 2001 From: Andrew Kitchen Date: Thu, 30 Nov 2017 17:13:44 -0800 Subject: [ios, macos] Adds support for specifying an ideographic font family name Adding a MGLIdeographicFontFamilyName to the containing app's Info.plist will result in CJK glyphs being rasterized on demand (#10522) --- platform/ios/src/MGLMapView.mm | 18 ++++++++++++++++-- platform/macos/src/MGLMapView.mm | 20 ++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 8154525334..c197db98f8 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -188,6 +188,7 @@ public: @property (nonatomic) EAGLContext *context; @property (nonatomic) GLKView *glView; @property (nonatomic) UIImageView *glSnapshotView; + @property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *scaleBarConstraints; @property (nonatomic, readwrite) MGLScaleBar *scaleBar; @property (nonatomic, readwrite) UIImageView *compassView; @@ -196,7 +197,10 @@ public: @property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *logoViewConstraints; @property (nonatomic, readwrite) UIButton *attributionButton; @property (nonatomic) NS_MUTABLE_ARRAY_OF(NSLayoutConstraint *) *attributionButtonConstraints; + @property (nonatomic, readwrite) MGLStyle *style; +@property (nonatomic, readonly) NSString *ideographicFontFamilyName; + @property (nonatomic) UITapGestureRecognizer *singleTapGestureRecognizer; @property (nonatomic) UITapGestureRecognizer *doubleTap; @property (nonatomic) UITapGestureRecognizer *twoFingerTap; @@ -205,11 +209,14 @@ public: @property (nonatomic) UIRotationGestureRecognizer *rotate; @property (nonatomic) UILongPressGestureRecognizer *quickZoom; @property (nonatomic) UIPanGestureRecognizer *twoFingerDrag; + /// Mapping from reusable identifiers to annotation images. @property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImagesByIdentifier; + /// Currently shown popover representing the selected annotation. @property (nonatomic) UIView *calloutViewForSelectedAnnotation; @property (nonatomic) MGLUserLocationAnnotationView *userLocationAnnotationView; + /// Indicates how thoroughly the map view is tracking the user location. @property (nonatomic) MGLUserTrackingState userTrackingState; @property (nonatomic) CLLocationManager *locationManager; @@ -403,8 +410,9 @@ public: mbgl::DefaultFileSource *mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; const float scaleFactor = [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale]; _mbglThreadPool = mbgl::sharedThreadPool(); - - auto renderer = std::make_unique(*_mbglView, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique); + NSString *fontFamilyName = self.ideographicFontFamilyName; + + auto renderer = std::make_unique(*_mbglView, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional(), fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional()); _rendererFrontend = std::make_unique(std::move(renderer), self, *_mbglView); _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); @@ -3456,6 +3464,12 @@ public: [self.style removeStyleClass:styleClass]; } +#pragma mark Ideographic Font Info + +- (NSString *)ideographicFontFamilyName { + return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; +} + #pragma mark - Annotations - - (nullable NS_ARRAY_OF(id ) *)annotations diff --git a/platform/macos/src/MGLMapView.mm b/platform/macos/src/MGLMapView.mm index d5512cb6cc..8cffc62167 100644 --- a/platform/macos/src/MGLMapView.mm +++ b/platform/macos/src/MGLMapView.mm @@ -143,6 +143,8 @@ public: @property (nonatomic, readwrite) NSView *attributionView; @property (nonatomic, readwrite) MGLStyle *style; +@property (nonatomic, readonly) NSString *ideographicFontFamilyName; + /// Mapping from reusable identifiers to annotation images. @property (nonatomic) NS_MUTABLE_DICTIONARY_OF(NSString *, MGLAnnotationImage *) *annotationImagesByIdentifier; @@ -217,7 +219,7 @@ public: - (instancetype)initWithFrame:(NSRect)frameRect { if (self = [super initWithFrame:frameRect]) { - [self commonInit:nil]; + [self commonInit]; self.styleURL = nil; } return self; @@ -225,7 +227,7 @@ public: - (instancetype)initWithFrame:(NSRect)frame styleURL:(nullable NSURL *)styleURL { if (self = [super initWithFrame:frame]) { - [self commonInit:nil]; + [self commonInit]; self.styleURL = styleURL; } return self; @@ -233,7 +235,7 @@ public: - (instancetype)initWithCoder:(nonnull NSCoder *)decoder { if (self = [super initWithCoder:decoder]) { - [self commonInit:nil]; + [self commonInit]; } return self; } @@ -252,7 +254,7 @@ public: return @[@"camera", @"debugMask"]; } -- (void)commonInit:(nullable NSString*)fontFamily { +- (void)commonInit { _isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent; // Set up cross-platform controllers and resources. @@ -271,10 +273,10 @@ public: [[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL]; mbgl::DefaultFileSource* mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource; - _mbglThreadPool = mbgl::sharedThreadPool(); + NSString *fontFamilyName = self.ideographicFontFamilyName; - auto renderer = std::make_unique(*_mbglView, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional(), fontFamily ? std::string([fontFamily UTF8String]) : mbgl::optional()); + auto renderer = std::make_unique(*_mbglView, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional(), fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional()); _rendererFrontend = std::make_unique(std::move(renderer), self, *_mbglView, true); _mbglMap = new mbgl::Map(*_rendererFrontend, *_mbglView, self.size, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::MapMode::Continuous, mbgl::ConstrainMode::None, mbgl::ViewportMode::Default); @@ -652,6 +654,12 @@ public: return _rendererFrontend->getRenderer(); } +#pragma mark Ideographic Font Info + +- (NSString *)ideographicFontFamilyName { + return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"]; +} + #pragma mark View hierarchy and drawing - (void)viewWillMoveToWindow:(NSWindow *)newWindow { -- cgit v1.2.1