summaryrefslogtreecommitdiff
path: root/platform/darwin
diff options
context:
space:
mode:
authorAndrew Kitchen <andrew.kitchen@mapbox.com>2017-12-04 13:29:16 -0800
committerChris Loer <chris.loer@mapbox.com>2017-12-11 10:43:00 -0800
commitb2f06677a787fe7b9b08608e5a55aaedbe50ed3a (patch)
tree6ee6e3687aa8c7f68e8a75354d8c57f0f0be70a5 /platform/darwin
parent00ed34f7d700ae255eae1af1ca46b939ffee219d (diff)
downloadqtlocation-mapboxgl-b2f06677a787fe7b9b08608e5a55aaedbe50ed3a.tar.gz
[darwin, ios, macos] Introduces an MGLRendererConfiguration class
Instructions for enabling client-side rendering of CJK glyphs live in this header, and this class provides the rest of the values needed for instantiating the renderer on iOS and macOS.
Diffstat (limited to 'platform/darwin')
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.h40
-rw-r--r--platform/darwin/src/MGLRendererConfiguration.mm43
2 files changed, 83 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLRendererConfiguration.h b/platform/darwin/src/MGLRendererConfiguration.h
new file mode 100644
index 0000000000..35cf828536
--- /dev/null
+++ b/platform/darwin/src/MGLRendererConfiguration.h
@@ -0,0 +1,40 @@
+#import <Foundation/Foundation.h>
+#import <mbgl/storage/default_file_source.hpp>
+#import <mbgl/renderer/mode.hpp>
+
+NS_ASSUME_NONNULL_BEGIN
+
+/**
+ The MGLRendererConfiguration object represents configuration values for the
+ renderer.
+ */
+@interface MGLRendererConfiguration : NSObject
+
+/** Returns an instance of the current renderer configuration. */
++ (instancetype)currentConfiguration;
+
+/** The file source to use. Defaults to `mbgl::DefaultFileSource` */
+@property (nonatomic, readonly) mbgl::DefaultFileSource *fileSource;
+
+/** The GL context mode to use. Defaults to `mbgl::GLContextMode::Unique` */
+@property (nonatomic, readonly) mbgl::GLContextMode contextMode;
+
+/** The scale factor to use.
+
+ Based on the native scale where available, otherwise the standard screen scale. */
+@property (nonatomic, readonly) const float scaleFactor;
+
+/** The cache dir to use. */
+@property (nonatomic, readonly) mbgl::optional<std::string> cacheDir;
+
+/** The name of the font family to use for client-side text rendering.
+
+ Currently only used for CJK glyphs. Changing this at run time is not currently
+ supported. Enable client-side rendering of CJK glyphs by setting
+ `MGLIdeographicFontFamilyName` in your containing app's Info.plist to a value
+ which will be available at runtime, i.e. "Arial Unicode MS". */
+@property (nonatomic, readonly) mbgl::optional<std::string> localFontFamilyName;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLRendererConfiguration.mm b/platform/darwin/src/MGLRendererConfiguration.mm
new file mode 100644
index 0000000000..ae7d7dd9fe
--- /dev/null
+++ b/platform/darwin/src/MGLRendererConfiguration.mm
@@ -0,0 +1,43 @@
+#import "MGLRendererConfiguration.h"
+#import "MGLOfflineStorage_Private.h"
+
+#if TARGET_OS_IPHONE
+#import <UIKit/UIKit.h>
+#else
+#import <AppKit/AppKit.h>
+#endif
+
+
+@implementation MGLRendererConfiguration
+
++ (instancetype)currentConfiguration {
+ return [[self alloc] init];
+}
+
+- (mbgl::DefaultFileSource *)fileSource {
+ return [MGLOfflineStorage sharedOfflineStorage].mbglFileSource;
+}
+
+- (mbgl::GLContextMode)contextMode {
+ return mbgl::GLContextMode::Unique;
+}
+
+- (const float)scaleFactor {
+#if TARGET_OS_IPHONE
+ return [UIScreen instancesRespondToSelector:@selector(nativeScale)] ? [[UIScreen mainScreen] nativeScale] : [[UIScreen mainScreen] scale];
+#else
+ return [NSScreen mainScreen].backingScaleFactor;
+#endif
+}
+
+- (mbgl::optional<std::string>)cacheDir {
+ return mbgl::optional<std::string>();
+}
+
+- (mbgl::optional<std::string>)localFontFamilyName {
+ NSString *fontFamilyName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLIdeographicFontFamilyName"];
+
+ return fontFamilyName ? std::string([fontFamilyName UTF8String]) : mbgl::optional<std::string>();
+}
+
+@end