/
pxSVGImage.m
44 lines (40 loc) · 982 Bytes
/
pxSVGImage.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
//
// pxSVGImage.m
// pxSVG
//
// Created by Yury Popov on 12 мая.
// Copyright (c) 2015 PhoeniX. All rights reserved.
//
#import "pxSVGImage.h"
#import "pxXMLNode.h"
#import "pxSVGRenderPath.h"
@interface pxSVGImage ()
@property pxSVGRenderPath *renderPath;
@end
@implementation pxSVGImage
+ (instancetype)svgImageWithXML:(NSString *)xml
{
return [[self alloc] initWithXML:xml];
}
- (instancetype)initWithXML:(NSString *)xml
{
pxXMLNode *xmlTree =
[[pxXMLNode parseTree:[[NSScanner alloc] initWithString:xml]]
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"tagName=%@",@"svg"]]
.firstObject;
if (!xmlTree) return nil;
pxSVGRenderPath *renderPath = [pxSVGRenderPath pathWithXML:xmlTree];
if (!renderPath) return nil;
self = [self init];
self.renderPath = renderPath;
return self;
}
- (CGRect)bounds
{
return self.renderPath.bounds;
}
- (CALayer *)makeLayer
{
return [self.renderPath makeLayer];
}
@end