diff --git a/Example/main.js b/Example/main.js index de1400aa..c6f9378a 100644 --- a/Example/main.js +++ b/Example/main.js @@ -145,7 +145,7 @@ class SvgExample extends Component { this.state.scale.setValue(0); Animated.spring(this.state.scale, { toValue: 1, - useNativeDriver: true + useNativeDriver: false }).start(); this.setState({ diff --git a/elements/Span.js b/elements/Span.js index 977ca708..e9a0fd2c 100644 --- a/elements/Span.js +++ b/elements/Span.js @@ -1,42 +1,24 @@ -import React from 'react'; +import React, {PropTypes} from 'react'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import {SpanAttributes} from '../lib/attributes'; import Shape from './Shape'; -import {pathProps, numberProp} from '../lib/props'; +import {numberProp} from '../lib/props'; + +// Span components are only for internal use for Text. class Span extends Shape { static displayName = 'Span'; static propTypes = { - ...pathProps, - x1: numberProp.isRequired, - x2: numberProp.isRequired, - y1: numberProp.isRequired, - y2: numberProp.isRequired - }; - - static defaultProps = { - x1: 0, - y1: 0, - x2: 0, - y2: 0 - }; - - setNativeProps = (...args) => { - this.root.setNativeProps(...args); + content: PropTypes.string.isRequired, + dx: numberProp, + dy: numberProp, + px: numberProp, + py: numberProp }; render() { - let props = this.props; - return null; - return {this.root = ele;}} - {...this.extractProps(props)} - x1={props.x1.toString()} - y1={props.y1.toString()} - x2={props.x2.toString()} - y2={props.y2.toString()} - />; + return ; } } diff --git a/ios/RNSVG.xcodeproj/project.pbxproj b/ios/RNSVG.xcodeproj/project.pbxproj index ab15a5ef..e410f955 100644 --- a/ios/RNSVG.xcodeproj/project.pbxproj +++ b/ios/RNSVG.xcodeproj/project.pbxproj @@ -23,8 +23,8 @@ 1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2901CE71EC2001E90A8 /* RNSVGText.m */; }; 1039D2A01CE72177001E90A8 /* RCTConvert+RNSVG.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */; }; 1039D2B01CE72F27001E90A8 /* RNSVGPercentageConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */; }; - 107CD53E1D7166B700F0A7AC /* RNSVGTSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */; }; - 107CD5401D71672E00F0A7AC /* RNSVGTSpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */; }; + 107CD53E1D7166B700F0A7AC /* RNSVGSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */; }; + 107CD5401D71672E00F0A7AC /* RNSVGSpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */; }; 10ABC7331D435915006CCF6E /* RNSVGViewBoxManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */; }; 10ABC7361D43595E006CCF6E /* RNSVGViewBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7351D43595E006CCF6E /* RNSVGViewBox.m */; }; 10BA0D341CE74E3100887C2B /* RNSVGCircleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BA0D1D1CE74E3100887C2B /* RNSVGCircleManager.m */; }; @@ -95,17 +95,16 @@ 1039D2881CE71EB7001E90A8 /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSvgView.m; path = Elements/RNSVGSvgView.m; sourceTree = ""; }; 1039D28F1CE71EC2001E90A8 /* RNSVGText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGText.h; path = Text/RNSVGText.h; sourceTree = ""; }; 1039D2901CE71EC2001E90A8 /* RNSVGText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGText.m; path = Text/RNSVGText.m; sourceTree = ""; }; - 1039D2911CE71EC2001E90A8 /* RNSVGTextFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextFrame.h; path = Text/RNSVGTextFrame.h; sourceTree = ""; }; 1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "RCTConvert+RNSVG.h"; path = "Utils/RCTConvert+RNSVG.h"; sourceTree = ""; }; 1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "RCTConvert+RNSVG.m"; path = "Utils/RCTConvert+RNSVG.m"; sourceTree = ""; }; 1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGCGFloatArray.h; path = Utils/RNSVGCGFloatArray.h; sourceTree = ""; }; 1039D2A11CE721A7001E90A8 /* RNSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGContainer.h; sourceTree = ""; }; 1039D2AE1CE72F27001E90A8 /* RNSVGPercentageConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPercentageConverter.h; path = Utils/RNSVGPercentageConverter.h; sourceTree = ""; }; 1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPercentageConverter.m; path = Utils/RNSVGPercentageConverter.m; sourceTree = ""; }; - 107CD53B1D7166A000F0A7AC /* RNSVGTSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTSpan.h; path = Text/RNSVGTSpan.h; sourceTree = ""; }; - 107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTSpanManager.h; sourceTree = ""; }; - 107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTSpanManager.m; sourceTree = ""; }; - 107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; sourceTree = ""; }; + 107CD53B1D7166A000F0A7AC /* RNSVGSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGSpan.h; path = Text/RNSVGSpan.h; sourceTree = ""; }; + 107CD53C1D7166B700F0A7AC /* RNSVGSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGSpanManager.h; sourceTree = ""; }; + 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSpanManager.m; sourceTree = ""; }; + 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSpan.m; path = Text/RNSVGSpan.m; sourceTree = ""; }; 10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBoxManager.h; sourceTree = ""; }; 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGViewBoxManager.m; sourceTree = ""; }; 10ABC7341D43595E006CCF6E /* RNSVGViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBox.h; sourceTree = ""; }; @@ -223,8 +222,8 @@ 0CF68AF81AF0549300FF9E5C /* ViewManagers */ = { isa = PBXGroup; children = ( - 107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */, - 107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */, + 107CD53C1D7166B700F0A7AC /* RNSVGSpanManager.h */, + 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */, 10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */, 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */, 10BEC1BE1D3F680F00FDCB19 /* RNSVGLinearGradientManager.h */, @@ -283,11 +282,10 @@ children = ( 103371331D41D3400028AF13 /* RNSVGBezierPath.h */, 103371311D41C5C90028AF13 /* RNSVGBezierPath.m */, - 107CD53B1D7166A000F0A7AC /* RNSVGTSpan.h */, - 107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */, + 107CD53B1D7166A000F0A7AC /* RNSVGSpan.h */, + 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */, 1039D28F1CE71EC2001E90A8 /* RNSVGText.h */, 1039D2901CE71EC2001E90A8 /* RNSVGText.m */, - 1039D2911CE71EC2001E90A8 /* RNSVGTextFrame.h */, ); name = Text; sourceTree = ""; @@ -402,7 +400,7 @@ 1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */, 10BA0D3B1CE74E3100887C2B /* RNSVGRectManager.m in Sources */, 0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */, - 107CD53E1D7166B700F0A7AC /* RNSVGTSpanManager.m in Sources */, + 107CD53E1D7166B700F0A7AC /* RNSVGSpanManager.m in Sources */, 1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */, 10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */, 10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */, @@ -411,7 +409,7 @@ 10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */, 0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */, 10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */, - 107CD5401D71672E00F0A7AC /* RNSVGTSpan.m in Sources */, + 107CD5401D71672E00F0A7AC /* RNSVGSpan.m in Sources */, 103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */, 10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */, 10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */, diff --git a/ios/Text/RNSVGTSpan.h b/ios/Text/RNSVGSpan.h similarity index 51% rename from ios/Text/RNSVGTSpan.h rename to ios/Text/RNSVGSpan.h index 80732c8c..a4866b82 100644 --- a/ios/Text/RNSVGTSpan.h +++ b/ios/Text/RNSVGSpan.h @@ -7,13 +7,16 @@ */ #import +#import #import "RNSVGPath.h" #import "RNSVGTextFrame.h" -@interface RNSVGTSpan : RNSVGPath +@interface RNSVGSpan : RNSVGPath -@property (nonatomic, assign) NSString *line; -@property (nonatomic, assign) NSString *dx; -@property (nonatomic, assign) NSString *dy; +@property (nonatomic, assign) CGFloat *dx; +@property (nonatomic, assign) CGFloat *dy; +@property (nonatomic, assign) NSString *px; +@property (nonatomic, assign) NSString *py; +@property (nonatomic, assign) CTFontRef font; @end diff --git a/ios/Text/RNSVGTSpan.m b/ios/Text/RNSVGSpan.m similarity index 89% rename from ios/Text/RNSVGTSpan.m rename to ios/Text/RNSVGSpan.m index 0e546c8d..ed7a51ed 100644 --- a/ios/Text/RNSVGTSpan.m +++ b/ios/Text/RNSVGSpan.m @@ -6,11 +6,11 @@ * LICENSE file in the root directory of this source tree. */ -#import "RNSVGTSpan.h" +#import "RNSVGSpan.h" #import "RNSVGBezierPath.h" #import -@implementation RNSVGTSpan +@implementation RNSVGSpan - (CGPathRef)getPath:(CGContextRef)context { diff --git a/ios/Text/RNSVGText.m b/ios/Text/RNSVGText.m index e26ece30..b48a2116 100644 --- a/ios/Text/RNSVGText.m +++ b/ios/Text/RNSVGText.m @@ -12,18 +12,6 @@ @implementation RNSVGText -//static void RNSVGFreeTextFrame(RNSVGTextFrame frame) -//{ -// if (frame.count) { -// // We must release each line before freeing up this struct -// for (int i = 0; i < frame.count; i++) { -// CFRelease(frame.lines[i]); -// } -// free(frame.lines); -// free(frame.widths); -// } -//} - - (void)setAlignment:(CTTextAlignment)alignment { [self invalidate]; diff --git a/ios/Text/RNSVGTextFrame.h b/ios/Text/RNSVGTextFrame.h deleted file mode 100644 index 1d4d4701..00000000 --- a/ios/Text/RNSVGTextFrame.h +++ /dev/null @@ -1,24 +0,0 @@ -/** - * Copyright (c) 2015-present, Horcrux. - * All rights reserved. - * - * This source code is licensed under the MIT-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import - -// A little helper to make sure we have a set of lines including width ready for use. -// We assume that we will only this in one place so no reference counting is necessary. -// Needs to be freed when dealloced. - -// This is fragile since this relies on these values not getting reused. Consider -// wrapping these in an Obj-C class or some ARC hackery to get refcounting. - -typedef struct { - size_t count; - CGFloat baseLine; // Distance from the origin to the base line of the first line - CGFloat lineHeight; // Distance between lines - CTLineRef *lines; - CGFloat *widths; // Width of each line -} RNSVGTextFrame; diff --git a/ios/Utils/RCTConvert+RNSVG.h b/ios/Utils/RCTConvert+RNSVG.h index 5dc78a95..a8e284df 100644 --- a/ios/Utils/RCTConvert+RNSVG.h +++ b/ios/Utils/RCTConvert+RNSVG.h @@ -7,9 +7,9 @@ */ #import +#import #import "RCTConvert+RNSVG.h" #import "RNSVGCGFloatArray.h" -#import "RNSVGTextFrame.h" #import "RCTConvert.h" #import "RNSVGCGFCRule.h" @@ -20,7 +20,7 @@ + (CGPathRef)CGPath:(id)json; + (CTTextAlignment)CTTextAlignment:(id)json; + (RNSVGCGFCRule)RNSVGCGFCRule:(id)json; -+ (RNSVGTextFrame)RNSVGTextFrame:(id)json; ++ (CTFontRef)RNSVGFont:(id)json; + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json; + (RNSVGBrush *)RNSVGBrush:(id)json; diff --git a/ios/Utils/RCTConvert+RNSVG.m b/ios/Utils/RCTConvert+RNSVG.m index 0d841a69..ebcf6608 100644 --- a/ios/Utils/RCTConvert+RNSVG.m +++ b/ios/Utils/RCTConvert+RNSVG.m @@ -85,61 +85,69 @@ RCT_ENUM_CONVERTER(RNSVGVBMOS, (@{ }), kRNSVGVBMOSMeet, intValue) -// This takes a tuple of text lines and a font to generate a CTLine for each text line. -// This prepares everything for rendering a frame of text in RNSVGText. -+ (RNSVGTextFrame)RNSVGTextFrame:(id)json ++ (CTFontRef)RNSVGFont:(id)json { NSDictionary *dict = [self NSDictionary:json]; - RNSVGTextFrame frame; - frame.count = 0; - - NSArray *lines = [self NSArray:dict[@"lines"]]; - NSUInteger lineCount = [lines count]; - if (lineCount == 0) { - return frame; - } - - NSDictionary *fontDict = dict[@"font"]; - NSString *fontFamily = fontDict[@"fontFamily"]; + NSString *fontFamily = dict[@"fontFamily"]; if (![[UIFont familyNames] containsObject:fontFamily]) { fontFamily = nil; } - - CTFontRef font = (__bridge CTFontRef)[RCTFont updateFont:nil withFamily:fontFamily size:fontDict[@"fontSize"] weight:fontDict[@"fontWeight"] style:fontDict[@"fontStyle"] - variant:nil scaleMultiplier:1.0]; - if (!font) { - return frame; - } - // Create a dictionary for this font - CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{ - (NSString *)kCTFontAttributeName: (__bridge id)font, - (NSString *)kCTForegroundColorFromContextAttributeName: @YES - }; - - // Set up text frame with font metrics - CGFloat size = CTFontGetSize(font); - frame.count = lineCount; - frame.baseLine = size; // estimate base line - frame.lineHeight = size * 1.1; // Base on RNSVG canvas line height estimate - frame.lines = malloc(sizeof(CTLineRef) * lineCount); - frame.widths = malloc(sizeof(CGFloat) * lineCount); - - [lines enumerateObjectsUsingBlock:^(NSString *text, NSUInteger i, BOOL *stop) { - - CFStringRef string = (__bridge CFStringRef)text; - CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, string, attributes); - CTLineRef line = CTLineCreateWithAttributedString(attrString); - CFRelease(attrString); - - frame.lines[i] = line; - frame.widths[i] = CTLineGetTypographicBounds(line, nil, nil, nil); - }]; - - return frame; + return (__bridge CTFontRef)[RCTFont updateFont:nil withFamily:fontFamily size:dict[@"fontSize"] weight:dict[@"fontWeight"] style:dict[@"fontStyle"] variant:nil scaleMultiplier:1.0]; } +// This takes a tuple of text lines and a font to generate a CTLine for each text line. +// This prepares everything for rendering a frame of text in RNSVGText. +//+ (RNSVGTextFrame)RNSVGTextFrame:(id)json +//{ +// NSDictionary *dict = [self NSDictionary:json]; +// RNSVGTextFrame frame; +// frame.count = 0; +// +// NSArray *lines = [self NSArray:dict[@"lines"]]; +// NSUInteger lineCount = [lines count]; +// if (lineCount == 0) { +// return frame; +// } +// +// NSDictionary *fontDict = dict[@"font"]; +// NSString *fontFamily = fontDict[@"fontFamily"]; +// +// if (![[UIFont familyNames] containsObject:fontFamily]) { +// fontFamily = nil; +// } +// +// CTFontRef font = (__bridge CTFontRef)[RCTFont updateFont:nil withFamily:fontFamily size:fontDict[@"fontSize"] weight:fontDict[@"fontWeight"] style:fontDict[@"fontStyle"] variant:nil scaleMultiplier:1.0]; +// +// // Create a dictionary for this font +// CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{ +// (NSString *)kCTFontAttributeName: (__bridge id)font, +// (NSString *)kCTForegroundColorFromContextAttributeName: @YES +// }; +// +// // Set up text frame with font metrics +// CGFloat size = CTFontGetSize(font); +// frame.count = lineCount; +// frame.baseLine = size; // estimate base line +// frame.lineHeight = size * 1.1; // Base on RNSVG canvas line height estimate +// frame.lines = malloc(sizeof(CTLineRef) * lineCount); +// frame.widths = malloc(sizeof(CGFloat) * lineCount); +// +// [lines enumerateObjectsUsingBlock:^(NSString *text, NSUInteger i, BOOL *stop) { +// +// CFStringRef string = (__bridge CFStringRef)text; +// CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, string, attributes); +// CTLineRef line = CTLineCreateWithAttributedString(attrString); +// CFRelease(attrString); +// +// frame.lines[i] = line; +// frame.widths[i] = CTLineGetTypographicBounds(line, nil, nil, nil); +// }]; +// +// return frame; +//} + + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json { NSArray *arr = [self NSNumberArray:json]; diff --git a/ios/ViewManagers/RNSVGTSpanManager.h b/ios/ViewManagers/RNSVGSpanManager.h similarity index 82% rename from ios/ViewManagers/RNSVGTSpanManager.h rename to ios/ViewManagers/RNSVGSpanManager.h index 0eb2f24a..cfd29417 100644 --- a/ios/ViewManagers/RNSVGTSpanManager.h +++ b/ios/ViewManagers/RNSVGSpanManager.h @@ -8,6 +8,6 @@ #import "RNSVGRenderableManager.h" -@interface RNSVGTSpanManager : RNSVGRenderableManager +@interface RNSVGSpanManager : RNSVGRenderableManager @end diff --git a/ios/ViewManagers/RNSVGSpanManager.m b/ios/ViewManagers/RNSVGSpanManager.m new file mode 100644 index 00000000..94e0631c --- /dev/null +++ b/ios/ViewManagers/RNSVGSpanManager.m @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2015-present, Horcrux. + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RNSVGSpanManager.h" + +#import "RNSVGSpan.h" +#import "RCTConvert+RNSVG.h" + +@implementation RNSVGSpanManager + +RCT_EXPORT_MODULE() + +- (RNSVGRenderable *)node +{ + return [RNSVGSpan new]; +} + +RCT_EXPORT_VIEW_PROPERTY(dx, CGFloat) +RCT_EXPORT_VIEW_PROPERTY(dy, CGFloat) +RCT_EXPORT_VIEW_PROPERTY(px, NSString) +RCT_EXPORT_VIEW_PROPERTY(py, NSString) +RCT_REMAP_VIEW_PROPERTY(font, font, RNSVGFont) + +@end diff --git a/ios/ViewManagers/RNSVGTSpanManager.m b/ios/ViewManagers/RNSVGTSpanManager.m deleted file mode 100644 index d066f0e0..00000000 --- a/ios/ViewManagers/RNSVGTSpanManager.m +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2015-present, Horcrux. - * All rights reserved. - * - * This source code is licensed under the MIT-style license found in the - * LICENSE file in the root directory of this source tree. - */ - -#import "RNSVGTSpanManager.h" - -#import "RNSVGTSpan.h" -#import "RCTConvert+RNSVG.h" - -@implementation RNSVGTSpanManager - -RCT_EXPORT_MODULE() - -- (RNSVGRenderable *)node -{ - return [RNSVGTSpan new]; -} - -RCT_EXPORT_VIEW_PROPERTY(line, NSString) -RCT_EXPORT_VIEW_PROPERTY(dx, NSString) -RCT_EXPORT_VIEW_PROPERTY(dy, NSString) - -@end diff --git a/ios/ViewManagers/RNSVGTextManager.m b/ios/ViewManagers/RNSVGTextManager.m index 7df0b2eb..9786ddc0 100644 --- a/ios/ViewManagers/RNSVGTextManager.m +++ b/ios/ViewManagers/RNSVGTextManager.m @@ -21,7 +21,6 @@ RCT_EXPORT_MODULE() } RCT_EXPORT_VIEW_PROPERTY(alignment, CTTextAlignment) -RCT_REMAP_VIEW_PROPERTY(frame, textFrame, RNSVGTextFrame) RCT_EXPORT_VIEW_PROPERTY(path, RNSVGBezier) @end diff --git a/lib/attributes.js b/lib/attributes.js index 5b38de6e..2be83ddb 100644 --- a/lib/attributes.js +++ b/lib/attributes.js @@ -17,6 +17,18 @@ function arrayDiffer(a, b) { return false; } +function fontDiffer(a, b) { + if (a === b) { + return false; + } + + if (a.fontSize !== b.fontSize || a.fontFamily !== b.fontFamily || a.fontStyle !== b.fontStyle || a.fontWeight !== b.fontWeight) { + return true; + } + + return false; +} + const ViewBoxAttributes = { minX: true, minY: true, @@ -81,11 +93,14 @@ const PathAttributes = merge({ }, RenderableAttributes); const SpanAttributes = merge({ - fontFamily: true, - fontSize: true, - fontWeight: true, - fontStyle: true, - line: true + font: { + diff: fontDiffer + }, + content: true, + dx: true, + dy: true, + px: true, + py: true }, RenderableAttributes); diff --git a/lib/extract/extractFrame.js b/lib/extract/extractFrame.js deleted file mode 100644 index 7f8c2a74..00000000 --- a/lib/extract/extractFrame.js +++ /dev/null @@ -1,21 +0,0 @@ -import extractSpan from './extractSpan'; -import extractTextContent from './extractTextContent'; - -export default function (props) { - let {children, line} = props; - let extractedProps = extractSpan(props); - - if (typeof children === 'string') { - line = children; - children = null; - } else { - children = extractTextContent(props.children); - line = null; - } - console.log(extractedProps); - return { - ...extractedProps, - children, - line - }; -}; diff --git a/lib/extract/extractSpan.js b/lib/extract/extractSpan.js deleted file mode 100644 index 2fd895dc..00000000 --- a/lib/extract/extractSpan.js +++ /dev/null @@ -1,71 +0,0 @@ -import extractTextContent from './extractTextContent'; -import SerializablePath from '../SerializablePath'; -import _ from 'lodash'; -const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm%]*(?:\s*\/.*?)?\s+)?\s*"?([^"]*)/i; -const fontFamilyPrefix = /^[\s"']*/; -const fontFamilySuffix = /[\s"']*$/; -const spaceReg = /\s+/; -const commaReg = /,/; - -let cachedFontObjectsFromString = {}; - -function extractSingleFontFamily(fontFamilyString) { - // SVG on the web allows for multiple font-families to be specified. - // For compatibility, we extract the first font-family, hoping - // we'll get a match. - return fontFamilyString ? fontFamilyString.split(commaReg)[0] - .replace(fontFamilyPrefix, '') - .replace(fontFamilySuffix, '') : null; -} - -function parseFontString(font) { - if (cachedFontObjectsFromString.hasOwnProperty(font)) { - return cachedFontObjectsFromString[font]; - } - let match = fontRegExp.exec(font); - if (!match) { - return null; - } - let fontFamily = extractSingleFontFamily(match[3]); - let fontSize = +match[2] || 12; - let isBold = /bold/.exec(match[1]); - let isItalic = /italic/.exec(match[1]); - cachedFontObjectsFromString[font] = { - fontFamily: fontFamily, - fontSize: fontSize, - fontWeight: isBold ? 'bold' : 'normal', - fontStyle: isItalic ? 'italic' : 'normal' - }; - return cachedFontObjectsFromString[font]; -} - -function extractFont(props) { - let font = props.font; - let fontSize = +props.fontSize; - - let ownedFont = { - fontFamily: extractSingleFontFamily(props.fontFamily), - fontSize: isNaN(fontSize) ? null : fontSize, - fontWeight: props.fontWeight, - fontStyle: props.fontStyle - }; - - if (typeof props.font === 'string') { - font = parseFontString(props.font); - } - ownedFont = _.pickBy(ownedFont, prop => !_.isNil(prop)); - - return _.defaults(ownedFont, font); -} - -function parseDelta(delta) { - return delta.toString().split(spaceReg); -} - -export default function(props) { - return { - dx: parseDelta(props.dx || ''), - dy: parseDelta(props.dy || ''), - ...extractFont(props) - }; -} diff --git a/lib/extract/extractText.js b/lib/extract/extractText.js index 882eb24e..266b180a 100644 --- a/lib/extract/extractText.js +++ b/lib/extract/extractText.js @@ -209,9 +209,10 @@ export default function(props) { ...extractFont(frame.props) } }; - return - }) - // TODO: format children + + return ; + }); + return { alignment, children diff --git a/lib/extract/extractTextContent.js b/lib/extract/extractTextContent.js deleted file mode 100644 index d0a2a537..00000000 --- a/lib/extract/extractTextContent.js +++ /dev/null @@ -1,26 +0,0 @@ -import React, { - Children -} from 'react'; - -import TSpan from '../../elements/TSpan'; -const newLine = /\n/g; - -export default function(children) { - let spans = []; - - Children.forEach(children, function (child = '') { - let span; - if (typeof child === 'string') { - span = {child.replace(newLine, ' ')}; - } else if (child.type === TSpan) { - span = child; - } else { - // give warning about the illegal child type - return; - } - - spans.push(span); - }); - - return spans; -}