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

Commit

Permalink
[ios, macos] Adds support for specifying an ideographic font family name
Browse files Browse the repository at this point in the history
Adding a MGLIdeographicFontFamilyName to the containing app's Info.plist
will result in CJK glyphs being rasterized on demand (#10522)
  • Loading branch information
Andrew Kitchen authored and ChrisLoer committed Dec 1, 2017
1 parent 1fa0a39 commit a648a9b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
18 changes: 16 additions & 2 deletions platform/ios/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ @interface MGLMapView () <UIGestureRecognizerDelegate,
@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;
Expand All @@ -196,7 +197,10 @@ @interface MGLMapView () <UIGestureRecognizerDelegate,
@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;
Expand All @@ -205,11 +209,14 @@ @interface MGLMapView () <UIGestureRecognizerDelegate,
@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<MGLCalloutView> *calloutViewForSelectedAnnotation;
@property (nonatomic) MGLUserLocationAnnotationView *userLocationAnnotationView;

/// Indicates how thoroughly the map view is tracking the user location.
@property (nonatomic) MGLUserTrackingState userTrackingState;
@property (nonatomic) CLLocationManager *locationManager;
Expand Down Expand Up @@ -403,8 +410,9 @@ - (void)commonInit
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<mbgl::Renderer>(*_mbglView, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique);
NSString *fontFamilyName = self.ideographicFontFamilyName;

auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, scaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional<std::string>(), fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>());
_rendererFrontend = std::make_unique<MGLRenderFrontend>(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);

Expand Down Expand Up @@ -3456,6 +3464,12 @@ - (void)removeStyleClass:(NSString *)styleClass
[self.style removeStyleClass:styleClass];
}

#pragma mark Ideographic Font Info

- (NSString *)ideographicFontFamilyName {
return [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"];
}

#pragma mark - Annotations -

- (nullable NS_ARRAY_OF(id <MGLAnnotation>) *)annotations
Expand Down
20 changes: 14 additions & 6 deletions platform/macos/src/MGLMapView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ @interface MGLMapView () <NSPopoverDelegate, MGLMultiPointDelegate, NSGestureRec
@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;
Expand Down Expand Up @@ -217,23 +219,23 @@ + (void)initialize {

- (instancetype)initWithFrame:(NSRect)frameRect {
if (self = [super initWithFrame:frameRect]) {
[self commonInit:nil];
[self commonInit];
self.styleURL = nil;
}
return self;
}

- (instancetype)initWithFrame:(NSRect)frame styleURL:(nullable NSURL *)styleURL {
if (self = [super initWithFrame:frame]) {
[self commonInit:nil];
[self commonInit];
self.styleURL = styleURL;
}
return self;
}

- (instancetype)initWithCoder:(nonnull NSCoder *)decoder {
if (self = [super initWithCoder:decoder]) {
[self commonInit:nil];
[self commonInit];
}
return self;
}
Expand All @@ -252,7 +254,7 @@ + (NSArray *)restorableStateKeyPaths {
return @[@"camera", @"debugMask"];
}

- (void)commonInit:(nullable NSString*)fontFamily {
- (void)commonInit {
_isTargetingInterfaceBuilder = NSProcessInfo.processInfo.mgl_isInterfaceBuilderDesignablesAgent;

// Set up cross-platform controllers and resources.
Expand All @@ -271,10 +273,10 @@ - (void)commonInit:(nullable NSString*)fontFamily {
[[NSFileManager defaultManager] removeItemAtURL:legacyCacheURL error:NULL];

mbgl::DefaultFileSource* mbglFileSource = [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;

_mbglThreadPool = mbgl::sharedThreadPool();
NSString *fontFamilyName = self.ideographicFontFamilyName;

auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional<std::string>(), fontFamily ? std::string([fontFamily UTF8String]) : mbgl::optional<std::string>());
auto renderer = std::make_unique<mbgl::Renderer>(*_mbglView, [NSScreen mainScreen].backingScaleFactor, *mbglFileSource, *_mbglThreadPool, mbgl::GLContextMode::Unique, mbgl::optional<std::string>(), fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>());
_rendererFrontend = std::make_unique<MGLRenderFrontend>(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);

Expand Down Expand Up @@ -652,6 +654,12 @@ - (IBAction)reloadStyle:(__unused id)sender {
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 {
Expand Down

0 comments on commit a648a9b

Please sign in to comment.