forked from PSPDFKit/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RCTConvert+PSPDFAnnotationToolbarConfiguration.m
73 lines (63 loc) · 3.52 KB
/
RCTConvert+PSPDFAnnotationToolbarConfiguration.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Copyright © 2018-2020 PSPDFKit GmbH. All rights reserved.
//
// THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
// AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE PSPDFKIT LICENSE AGREEMENT.
// UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
// This notice may not be removed from this file.
//
#import "RCTConvert+PSPDFAnnotationToolbarConfiguration.h"
@implementation RCTConvert (PSPDFAnnotationToolbarConfiguration)
+ (PSPDFAnnotationToolbarConfiguration *)PSPDFAnnotationToolbarConfiguration:(id)json {
NSArray *itemsToParse = [RCTConvert NSArray:json];
NSMutableArray *parsedItems = [NSMutableArray arrayWithCapacity:itemsToParse.count];
for (id itemToParse in itemsToParse) {
if ([itemToParse isKindOfClass:[NSDictionary class]]) {
NSDictionary *dict = itemToParse;
NSArray *subArray = dict[@"items"];
NSMutableArray *subItems = [NSMutableArray arrayWithCapacity:subArray.count];
for (id subItem in subArray) {
if (subItem) {
PSPDFAnnotationString annotationString = [RCTConvert PSPDFAnnotationStringFromName:subItem];
[subItems addObject:[PSPDFAnnotationGroupItem itemWithType:annotationString]];
}
}
[parsedItems addObject:[PSPDFAnnotationGroup groupWithItems:subItems]];
} else {
PSPDFAnnotationString annotationString = [RCTConvert PSPDFAnnotationStringFromName:itemToParse];
if (annotationString) {
[parsedItems addObject:[PSPDFAnnotationGroup groupWithItems:@[[PSPDFAnnotationGroupItem itemWithType:annotationString]]]];
}
}
}
return [[PSPDFAnnotationToolbarConfiguration alloc] initWithAnnotationGroups:parsedItems];
}
+ (PSPDFAnnotationString)PSPDFAnnotationStringFromName:(NSString *)name {
static NSDictionary *nameToAnnotationStringMapping;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSMutableDictionary *mapping = [[NSMutableDictionary alloc] init];
[mapping setValue:PSPDFAnnotationStringLink forKeyPath:@"link"];
[mapping setValue:PSPDFAnnotationStringHighlight forKeyPath:@"highlight"];
[mapping setValue:PSPDFAnnotationMenuStrikeout forKeyPath:@"strikeout"];
[mapping setValue:PSPDFAnnotationStringUnderline forKeyPath:@"underline"];
[mapping setValue:PSPDFAnnotationMenuSquiggle forKeyPath:@"squiggly"];
[mapping setValue:PSPDFAnnotationStringNote forKeyPath:@"note"];
[mapping setValue:PSPDFAnnotationStringFreeText forKeyPath:@"freetext"];
[mapping setValue:PSPDFAnnotationStringInk forKeyPath:@"ink"];
[mapping setValue:PSPDFAnnotationStringSquare forKeyPath:@"square"];
[mapping setValue:PSPDFAnnotationStringCircle forKeyPath:@"circle"];
[mapping setValue:PSPDFAnnotationStringLine forKeyPath:@"line"];
[mapping setValue:PSPDFAnnotationStringPolygon forKeyPath:@"polygon"];
[mapping setValue:PSPDFAnnotationStringPolyLine forKeyPath:@"polyline"];
[mapping setValue:PSPDFAnnotationStringSignature forKeyPath:@"signature"];
[mapping setValue:PSPDFAnnotationStringStamp forKeyPath:@"stamp"];
[mapping setValue:PSPDFAnnotationStringEraser forKeyPath:@"eraser"];
[mapping setValue:PSPDFAnnotationStringSound forKeyPath:@"sound"];
[mapping setValue:PSPDFAnnotationStringImage forKeyPath:@"image"];
[mapping setValue:PSPDFAnnotationStringRedaction forKeyPath:@"redaction"];
nameToAnnotationStringMapping = [[NSDictionary alloc] initWithDictionary:mapping];
});
return nameToAnnotationStringMapping[name];
}
@end