summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLAttributedExpression.m
diff options
context:
space:
mode:
authorFabian Guerra Soto <fabian.guerra@mapbox.com>2019-03-15 16:10:27 -0700
committerGitHub <noreply@github.com>2019-03-15 16:10:27 -0700
commit7939ff213a98de055e93ddd893ccae40b82a7d16 (patch)
treef23371b62e4ce1e4964361a04c0b11a39ede8569 /platform/darwin/src/MGLAttributedExpression.m
parentc8cfdb1ced822711e772dfcc8f708b1a7a68b5fc (diff)
downloadqtlocation-mapboxgl-7939ff213a98de055e93ddd893ccae40b82a7d16.tar.gz
[ios, macos] Add format expression convenience methods support. (#14094)
Added the ios/macos format expression bindings. The equivalent is mgl_attributed: or mgl_attributed({}) when making an expression using the expressionForFormat selector. A new constructor called mgl_expressionForAttributedExpressions:(NSArray<NSExpression*>*)attributedExpressions was added to NSExpression+MGLAdditions category. Updated the symbol style layer text test to use the bindings. Updated the Predicates and Expressions.md and For Style Authors.md.ejs template with the bindings.
Diffstat (limited to 'platform/darwin/src/MGLAttributedExpression.m')
-rw-r--r--platform/darwin/src/MGLAttributedExpression.m59
1 files changed, 59 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLAttributedExpression.m b/platform/darwin/src/MGLAttributedExpression.m
new file mode 100644
index 0000000000..715f74e42f
--- /dev/null
+++ b/platform/darwin/src/MGLAttributedExpression.m
@@ -0,0 +1,59 @@
+#import "MGLAttributedExpression.h"
+#import "MGLLoggingConfiguration_Private.h"
+
+const MGLAttributedExpressionKey MGLFontNamesAttribute = @"text-font";
+const MGLAttributedExpressionKey MGLFontSizeAttribute = @"font-scale";
+
+@implementation MGLAttributedExpression
+
+- (instancetype)initWithExpression:(NSExpression *)expression {
+ self = [self initWithExpression:expression attributes:nil];
+ return self;
+}
+
++ (instancetype)attributedExpression:(NSExpression *)expression fontNames:(nullable NSArray<NSString *> *)fontNames fontSize:(nullable NSNumber *)fontSize {
+ MGLAttributedExpression *attributedExpression;
+
+ NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
+
+ if (fontNames && fontNames.count > 0) {
+ attrs[MGLFontNamesAttribute] = fontNames;
+ }
+
+ if (fontSize) {
+ attrs[MGLFontSizeAttribute] = fontSize;
+ }
+
+ attributedExpression = [[self alloc] initWithExpression:expression attributes:attrs];
+ return attributedExpression;
+}
+
+- (instancetype)initWithExpression:(NSExpression *)expression attributes:(NSDictionary<MGLAttributedExpressionKey,id> *)attrs {
+ if (self = [super init])
+ {
+ MGLLogInfo(@"Starting %@ initialization.", NSStringFromClass([self class]));
+ _expression = expression;
+ _attributes = attrs;
+
+ MGLLogInfo(@"Finalizing %@ initialization.", NSStringFromClass([self class]));
+ }
+ return self;
+}
+
+- (BOOL)isEqual:(id)object {
+ BOOL result = NO;
+
+ if ([object isKindOfClass:[self class]]) {
+ MGLAttributedExpression *otherObject = object;
+ result = [self.expression isEqual:otherObject.expression] &&
+ [_attributes isEqual:otherObject.attributes];
+ }
+
+ return result;
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"MGLAttributedExpression<Expression: %@ Attributes: %@>", self.expression, self.attributes];
+}
+
+@end