summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-19 14:53:35 -0700
committerGitHub <noreply@github.com>2019-03-19 14:53:35 -0700
commit174c8fa7e4927ebf28a3d0e07c995d3e3d69de76 (patch)
treef503bdf15e24f9c744f634107fc04c6338d1c42d /platform/darwin/src/NSExpression+MGLAdditions.mm
parent10e1e63aee95f579f951e3c2001640a268d3d95c (diff)
downloadqtlocation-mapboxgl-174c8fa7e4927ebf28a3d0e07c995d3e3d69de76.tar.gz
[ios, macos] Add text-color support to format expressions. (#14146)
Added the possibility of overriding paint properties inside the format expression. Added an example of how to create an MGLAttributedExpression object and documented the attributes keys and value types. Fixed a bug that ignored the font names.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm27
1 files changed, 25 insertions, 2 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index c4e2908888..f0f1d62ef7 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -1,3 +1,4 @@
+#import "MGLFoundation_Private.h"
#import "NSExpression+MGLPrivateAdditions.h"
#import "MGLTypes.h"
@@ -878,9 +879,23 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
NSExpression *expression = [NSExpression expressionWithMGLJSONObject:argumentObjects[index]];
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
if ((index + 1) < argumentObjects.count) {
- attrs = argumentObjects[index + 1];
+ attrs = [NSMutableDictionary dictionaryWithDictionary:argumentObjects[index + 1]];
}
+ if (attrs.count) {
+ if (NSArray *fontNames = MGL_OBJC_DYNAMIC_CAST(attrs[MGLFontNamesAttribute], NSArray)) {
+ attrs[MGLFontNamesAttribute] = fontNames[1];
+ }
+ if (NSArray *colorArray = MGL_OBJC_DYNAMIC_CAST(attrs[MGLFontColorAttribute], NSArray)) {
+ if ([colorArray[0] isEqualToString:@"rgb"] || [colorArray[0] isEqualToString:@"rgba"]) {
+ NSArray *colorArguments = [colorArray subarrayWithRange:NSMakeRange(1, colorArray.count - 1)];
+ NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(colorArguments);
+ MGLColor *color = [NSExpression mgl_colorWithRGBComponents:subexpressions];
+
+ attrs[MGLFontColorAttribute] = color;
+ }
+ }
+ }
MGLAttributedExpression *attributedExpression = [[MGLAttributedExpression alloc] initWithExpression:expression attributes:attrs];
[attributedExpressions addObject:[NSExpression expressionForConstantValue:attributedExpression]];
@@ -1008,7 +1023,15 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) {
[attributes addObject:jsonObject];
}
if (attributedExpression.attributes) {
- [attributes addObject:attributedExpression.attributes];
+ NSMutableDictionary *attributedDictionary = [NSMutableDictionary dictionaryWithDictionary:attributedExpression.attributes];
+ if (attributedDictionary[MGLFontNamesAttribute]) {
+ attributedDictionary[MGLFontNamesAttribute] = @[@"literal", attributedDictionary[MGLFontNamesAttribute]];
+ }
+ if (attributedDictionary[MGLFontColorAttribute] && [attributedDictionary[MGLFontColorAttribute] isKindOfClass:[MGLColor class]]) {
+ MGLColor *color = attributedDictionary[MGLFontColorAttribute];
+ attributedDictionary[MGLFontColorAttribute] = color.mgl_jsonExpressionObject;
+ }
+ [attributes addObject:attributedDictionary];
} else {
[attributes addObject:@{}];
}