summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2020-03-01 03:32:40 -0800
committerMinh Nguyễn <mxn@1ec5.org>2020-04-24 13:46:40 -0700
commitf97ca0ccf9c875c5a5e0d26864e381c8de47ddcb (patch)
tree9f4f430dc21d7f53e8cd657660e212d2f6832ceb
parent52d4c5e222cafb48139a2dfcd3eec46fe38b857d (diff)
downloadqtlocation-mapboxgl-f97ca0ccf9c875c5a5e0d26864e381c8de47ddcb.tar.gz
[ios, macos] Allow specifying multiple fonts or font families for local font rendering
mbgl::Renderer and mbgl::MapSnapshotter can now contain a list of font family names, font display names, and font PostScript names, each name separated by a newline.
-rw-r--r--CHANGELOG.md7
-rw-r--r--platform/darwin/src/local_glyph_rasterizer.mm31
2 files changed, 30 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 823a47415f..36c8126851 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -26,7 +26,11 @@
By default, the source is not volatile.
-### Bug fixes
+- [ios, macos] Allow specifying multiple fonts or font families for local font rendering ([#16253](https://github.com/mapbox/mapbox-gl-native/pull/16253))
+
+ The `localFontFamily` parameter of `mbgl::Renderer::Renderer()` and `mbgl::MapSnapshotter::MapSnapshotter()` can now contain a list of font family names, font display names, and font PostScript names, each name separated by a newline.
+
+### 🐞 Bug fixes
- [ios, macos] Fixed error receiving local file URL response ([#16428](https://github.com/mapbox/mapbox-gl-native/pull/16428))
@@ -205,7 +209,6 @@
- When feature is exactly on the geometry boundary, `within` expression returns inconsistent values for different zoom levels ([#16301](https://github.com/mapbox/mapbox-gl-native/issues/16301))
-
## maps-v1.3.0 (2020.02-relvanillashake)
### 🐞 Bug fixes
diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm
index 6ff346873a..78f7d74428 100644
--- a/platform/darwin/src/local_glyph_rasterizer.mm
+++ b/platform/darwin/src/local_glyph_rasterizer.mm
@@ -45,7 +45,9 @@ using CGColorSpaceHandle = CFHandle<CGColorSpaceRef, CGColorSpaceRef, CGColorSpa
using CGContextHandle = CFHandle<CGContextRef, CGContextRef, CGContextRelease>;
using CFStringRefHandle = CFHandle<CFStringRef, CFTypeRef, CFRelease>;
using CFAttributedStringRefHandle = CFHandle<CFAttributedStringRef, CFTypeRef, CFRelease>;
+using CFMutableArrayRefHandle = CFHandle<CFMutableArrayRef, CFTypeRef, CFRelease>;
using CFDictionaryRefHandle = CFHandle<CFDictionaryRef, CFTypeRef, CFRelease>;
+using CTFontRefHandle = CFHandle<CTFontRef, CFTypeRef, CFRelease>;
using CTFontDescriptorRefHandle = CFHandle<CTFontDescriptorRef, CFTypeRef, CFRelease>;
using CTLineRefHandle = CFHandle<CTLineRef, CFTypeRef, CFRelease>;
@@ -62,19 +64,36 @@ public:
}
}
-
CTFontRef getFont() {
if (!fontFamily) {
return NULL;
}
if (!fontHandle) {
- NSDictionary *fontAttributes = @{
- (NSString *)kCTFontSizeAttribute: [NSNumber numberWithFloat:24.0],
- (NSString *)kCTFontFamilyNameAttribute: [[NSString alloc] initWithCString:fontFamily->c_str() encoding:NSUTF8StringEncoding]
- };
+ NSArray<NSString *> *fontFamilyNames = [@(fontFamily->c_str()) componentsSeparatedByString:@"\n"];
+ CFMutableArrayRefHandle fontDescriptors(CFArrayCreateMutable(kCFAllocatorDefault, fontFamilyNames.count, &kCFTypeArrayCallBacks));
+ for (NSString *name in fontFamilyNames) {
+ NSDictionary *fontAttributes = @{
+ (NSString *)kCTFontSizeAttribute: @(24.0),
+ (NSString *)kCTFontNameAttribute: name,
+ (NSString *)kCTFontDisplayNameAttribute: name,
+ (NSString *)kCTFontFamilyNameAttribute: name,
+ };
+
+ CTFontDescriptorRefHandle descriptor(CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes));
+ CFArrayAppendValue(*fontDescriptors, *descriptor);
+ }
+
+ CFStringRef keys[] = { kCTFontSizeAttribute, kCTFontCascadeListAttribute };
+ CFTypeRef values[] = { (__bridge CFNumberRef)@(24.0), *fontDescriptors };
- CTFontDescriptorRefHandle descriptor(CTFontDescriptorCreateWithAttributes((CFDictionaryRef)fontAttributes));
+ CFDictionaryRefHandle attributes(
+ CFDictionaryCreate(kCFAllocatorDefault, (const void**)&keys,
+ (const void**)&values, sizeof(keys) / sizeof(keys[0]),
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+
+ CTFontDescriptorRefHandle descriptor(CTFontDescriptorCreateWithAttributes(*attributes));
fontHandle = CTFontCreateWithFontDescriptor(*descriptor, 0.0, NULL);
if (!fontHandle) {
throw std::runtime_error("CTFontCreateWithFontDescriptor failed");