clean up unused code

This commit is contained in:
Horcrux
2016-09-17 09:49:28 +08:00
parent 09c5b10f02
commit d549f6ca9c
18 changed files with 142 additions and 288 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ class SvgExample extends Component {
this.state.scale.setValue(0); this.state.scale.setValue(0);
Animated.spring(this.state.scale, { Animated.spring(this.state.scale, {
toValue: 1, toValue: 1,
useNativeDriver: true useNativeDriver: false
}).start(); }).start();
this.setState({ this.setState({
+10 -28
View File
@@ -1,42 +1,24 @@
import React from 'react'; import React, {PropTypes} from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass'; import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {SpanAttributes} from '../lib/attributes'; import {SpanAttributes} from '../lib/attributes';
import Shape from './Shape'; 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 { class Span extends Shape {
static displayName = 'Span'; static displayName = 'Span';
static propTypes = { static propTypes = {
...pathProps, content: PropTypes.string.isRequired,
x1: numberProp.isRequired, dx: numberProp,
x2: numberProp.isRequired, dy: numberProp,
y1: numberProp.isRequired, px: numberProp,
y2: numberProp.isRequired py: numberProp
};
static defaultProps = {
x1: 0,
y1: 0,
x2: 0,
y2: 0
};
setNativeProps = (...args) => {
this.root.setNativeProps(...args);
}; };
render() { render() {
let props = this.props; return <RNSVGSpan {...this.props}/>;
return null;
return <RNSVGSpan
ref={ele => {this.root = ele;}}
{...this.extractProps(props)}
x1={props.x1.toString()}
y1={props.y1.toString()}
x2={props.x2.toString()}
y2={props.y2.toString()}
/>;
} }
} }
+12 -14
View File
@@ -23,8 +23,8 @@
1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2901CE71EC2001E90A8 /* RNSVGText.m */; }; 1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2901CE71EC2001E90A8 /* RNSVGText.m */; };
1039D2A01CE72177001E90A8 /* RCTConvert+RNSVG.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.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 */; }; 1039D2B01CE72F27001E90A8 /* RNSVGPercentageConverter.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */; };
107CD53E1D7166B700F0A7AC /* RNSVGTSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */; }; 107CD53E1D7166B700F0A7AC /* RNSVGSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */; };
107CD5401D71672E00F0A7AC /* RNSVGTSpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */; }; 107CD5401D71672E00F0A7AC /* RNSVGSpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */; };
10ABC7331D435915006CCF6E /* RNSVGViewBoxManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */; }; 10ABC7331D435915006CCF6E /* RNSVGViewBoxManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */; };
10ABC7361D43595E006CCF6E /* RNSVGViewBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7351D43595E006CCF6E /* RNSVGViewBox.m */; }; 10ABC7361D43595E006CCF6E /* RNSVGViewBox.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ABC7351D43595E006CCF6E /* RNSVGViewBox.m */; };
10BA0D341CE74E3100887C2B /* RNSVGCircleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10BA0D1D1CE74E3100887C2B /* RNSVGCircleManager.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 = "<group>"; }; 1039D2881CE71EB7001E90A8 /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSvgView.m; path = Elements/RNSVGSvgView.m; sourceTree = "<group>"; };
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGText.h; path = Text/RNSVGText.h; sourceTree = "<group>"; }; 1039D28F1CE71EC2001E90A8 /* RNSVGText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGText.h; path = Text/RNSVGText.h; sourceTree = "<group>"; };
1039D2901CE71EC2001E90A8 /* RNSVGText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGText.m; path = Text/RNSVGText.m; sourceTree = "<group>"; }; 1039D2901CE71EC2001E90A8 /* RNSVGText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGText.m; path = Text/RNSVGText.m; sourceTree = "<group>"; };
1039D2911CE71EC2001E90A8 /* RNSVGTextFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextFrame.h; path = Text/RNSVGTextFrame.h; sourceTree = "<group>"; };
1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "RCTConvert+RNSVG.h"; path = "Utils/RCTConvert+RNSVG.h"; sourceTree = "<group>"; }; 1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "RCTConvert+RNSVG.h"; path = "Utils/RCTConvert+RNSVG.h"; sourceTree = "<group>"; };
1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "RCTConvert+RNSVG.m"; path = "Utils/RCTConvert+RNSVG.m"; sourceTree = "<group>"; }; 1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "RCTConvert+RNSVG.m"; path = "Utils/RCTConvert+RNSVG.m"; sourceTree = "<group>"; };
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGCGFloatArray.h; path = Utils/RNSVGCGFloatArray.h; sourceTree = "<group>"; }; 1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGCGFloatArray.h; path = Utils/RNSVGCGFloatArray.h; sourceTree = "<group>"; };
1039D2A11CE721A7001E90A8 /* RNSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGContainer.h; sourceTree = "<group>"; }; 1039D2A11CE721A7001E90A8 /* RNSVGContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGContainer.h; sourceTree = "<group>"; };
1039D2AE1CE72F27001E90A8 /* RNSVGPercentageConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPercentageConverter.h; path = Utils/RNSVGPercentageConverter.h; sourceTree = "<group>"; }; 1039D2AE1CE72F27001E90A8 /* RNSVGPercentageConverter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPercentageConverter.h; path = Utils/RNSVGPercentageConverter.h; sourceTree = "<group>"; };
1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPercentageConverter.m; path = Utils/RNSVGPercentageConverter.m; sourceTree = "<group>"; }; 1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPercentageConverter.m; path = Utils/RNSVGPercentageConverter.m; sourceTree = "<group>"; };
107CD53B1D7166A000F0A7AC /* RNSVGTSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTSpan.h; path = Text/RNSVGTSpan.h; sourceTree = "<group>"; }; 107CD53B1D7166A000F0A7AC /* RNSVGSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGSpan.h; path = Text/RNSVGSpan.h; sourceTree = "<group>"; };
107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTSpanManager.h; sourceTree = "<group>"; }; 107CD53C1D7166B700F0A7AC /* RNSVGSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGSpanManager.h; sourceTree = "<group>"; };
107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTSpanManager.m; sourceTree = "<group>"; }; 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSpanManager.m; sourceTree = "<group>"; };
107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; sourceTree = "<group>"; }; 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSpan.m; path = Text/RNSVGSpan.m; sourceTree = "<group>"; };
10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBoxManager.h; sourceTree = "<group>"; }; 10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBoxManager.h; sourceTree = "<group>"; };
10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGViewBoxManager.m; sourceTree = "<group>"; }; 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGViewBoxManager.m; sourceTree = "<group>"; };
10ABC7341D43595E006CCF6E /* RNSVGViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBox.h; sourceTree = "<group>"; }; 10ABC7341D43595E006CCF6E /* RNSVGViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBox.h; sourceTree = "<group>"; };
@@ -223,8 +222,8 @@
0CF68AF81AF0549300FF9E5C /* ViewManagers */ = { 0CF68AF81AF0549300FF9E5C /* ViewManagers */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */, 107CD53C1D7166B700F0A7AC /* RNSVGSpanManager.h */,
107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */, 107CD53D1D7166B700F0A7AC /* RNSVGSpanManager.m */,
10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */, 10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */,
10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */, 10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */,
10BEC1BE1D3F680F00FDCB19 /* RNSVGLinearGradientManager.h */, 10BEC1BE1D3F680F00FDCB19 /* RNSVGLinearGradientManager.h */,
@@ -283,11 +282,10 @@
children = ( children = (
103371331D41D3400028AF13 /* RNSVGBezierPath.h */, 103371331D41D3400028AF13 /* RNSVGBezierPath.h */,
103371311D41C5C90028AF13 /* RNSVGBezierPath.m */, 103371311D41C5C90028AF13 /* RNSVGBezierPath.m */,
107CD53B1D7166A000F0A7AC /* RNSVGTSpan.h */, 107CD53B1D7166A000F0A7AC /* RNSVGSpan.h */,
107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */, 107CD53F1D71672E00F0A7AC /* RNSVGSpan.m */,
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */, 1039D28F1CE71EC2001E90A8 /* RNSVGText.h */,
1039D2901CE71EC2001E90A8 /* RNSVGText.m */, 1039D2901CE71EC2001E90A8 /* RNSVGText.m */,
1039D2911CE71EC2001E90A8 /* RNSVGTextFrame.h */,
); );
name = Text; name = Text;
sourceTree = "<group>"; sourceTree = "<group>";
@@ -402,7 +400,7 @@
1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */, 1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */,
10BA0D3B1CE74E3100887C2B /* RNSVGRectManager.m in Sources */, 10BA0D3B1CE74E3100887C2B /* RNSVGRectManager.m in Sources */,
0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */, 0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */,
107CD53E1D7166B700F0A7AC /* RNSVGTSpanManager.m in Sources */, 107CD53E1D7166B700F0A7AC /* RNSVGSpanManager.m in Sources */,
1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */, 1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */,
10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */, 10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */,
10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */, 10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */,
@@ -411,7 +409,7 @@
10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */, 10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */,
0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */, 0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */,
10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */, 10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */,
107CD5401D71672E00F0A7AC /* RNSVGTSpan.m in Sources */, 107CD5401D71672E00F0A7AC /* RNSVGSpan.m in Sources */,
103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */, 103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */,
10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */, 10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */,
10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */, 10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */,
@@ -7,13 +7,16 @@
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <CoreText/CoreText.h>
#import "RNSVGPath.h" #import "RNSVGPath.h"
#import "RNSVGTextFrame.h" #import "RNSVGTextFrame.h"
@interface RNSVGTSpan : RNSVGPath @interface RNSVGSpan : RNSVGPath
@property (nonatomic, assign) NSString *line; @property (nonatomic, assign) CGFloat *dx;
@property (nonatomic, assign) NSString *dx; @property (nonatomic, assign) CGFloat *dy;
@property (nonatomic, assign) NSString *dy; @property (nonatomic, assign) NSString *px;
@property (nonatomic, assign) NSString *py;
@property (nonatomic, assign) CTFontRef font;
@end @end
@@ -6,11 +6,11 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
*/ */
#import "RNSVGTSpan.h" #import "RNSVGSpan.h"
#import "RNSVGBezierPath.h" #import "RNSVGBezierPath.h"
#import <CoreText/CoreText.h> #import <CoreText/CoreText.h>
@implementation RNSVGTSpan @implementation RNSVGSpan
- (CGPathRef)getPath:(CGContextRef)context - (CGPathRef)getPath:(CGContextRef)context
{ {
-12
View File
@@ -12,18 +12,6 @@
@implementation RNSVGText @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 - (void)setAlignment:(CTTextAlignment)alignment
{ {
[self invalidate]; [self invalidate];
-24
View File
@@ -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 <CoreText/CoreText.h>
// 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;
+2 -2
View File
@@ -7,9 +7,9 @@
*/ */
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
#import <CoreText/CoreText.h>
#import "RCTConvert+RNSVG.h" #import "RCTConvert+RNSVG.h"
#import "RNSVGCGFloatArray.h" #import "RNSVGCGFloatArray.h"
#import "RNSVGTextFrame.h"
#import "RCTConvert.h" #import "RCTConvert.h"
#import "RNSVGCGFCRule.h" #import "RNSVGCGFCRule.h"
@@ -20,7 +20,7 @@
+ (CGPathRef)CGPath:(id)json; + (CGPathRef)CGPath:(id)json;
+ (CTTextAlignment)CTTextAlignment:(id)json; + (CTTextAlignment)CTTextAlignment:(id)json;
+ (RNSVGCGFCRule)RNSVGCGFCRule:(id)json; + (RNSVGCGFCRule)RNSVGCGFCRule:(id)json;
+ (RNSVGTextFrame)RNSVGTextFrame:(id)json; + (CTFontRef)RNSVGFont:(id)json;
+ (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json; + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json;
+ (RNSVGBrush *)RNSVGBrush:(id)json; + (RNSVGBrush *)RNSVGBrush:(id)json;
+54 -46
View File
@@ -85,61 +85,69 @@ RCT_ENUM_CONVERTER(RNSVGVBMOS, (@{
}), kRNSVGVBMOSMeet, intValue) }), kRNSVGVBMOSMeet, intValue)
// This takes a tuple of text lines and a font to generate a CTLine for each text line. + (CTFontRef)RNSVGFont:(id)json
// This prepares everything for rendering a frame of text in RNSVGText.
+ (RNSVGTextFrame)RNSVGTextFrame:(id)json
{ {
NSDictionary *dict = [self NSDictionary: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]) { if (![[UIFont familyNames] containsObject:fontFamily]) {
fontFamily = nil; 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 return (__bridge CTFontRef)[RCTFont updateFont:nil withFamily:fontFamily size:dict[@"fontSize"] weight:dict[@"fontWeight"] style:dict[@"fontStyle"] variant:nil scaleMultiplier:1.0];
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;
} }
// 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 + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json
{ {
NSArray *arr = [self NSNumberArray:json]; NSArray *arr = [self NSNumberArray:json];
@@ -8,6 +8,6 @@
#import "RNSVGRenderableManager.h" #import "RNSVGRenderableManager.h"
@interface RNSVGTSpanManager : RNSVGRenderableManager @interface RNSVGSpanManager : RNSVGRenderableManager
@end @end
+29
View File
@@ -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
-27
View File
@@ -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
-1
View File
@@ -21,7 +21,6 @@ RCT_EXPORT_MODULE()
} }
RCT_EXPORT_VIEW_PROPERTY(alignment, CTTextAlignment) RCT_EXPORT_VIEW_PROPERTY(alignment, CTTextAlignment)
RCT_REMAP_VIEW_PROPERTY(frame, textFrame, RNSVGTextFrame)
RCT_EXPORT_VIEW_PROPERTY(path, RNSVGBezier) RCT_EXPORT_VIEW_PROPERTY(path, RNSVGBezier)
@end @end
+20 -5
View File
@@ -17,6 +17,18 @@ function arrayDiffer(a, b) {
return false; 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 = { const ViewBoxAttributes = {
minX: true, minX: true,
minY: true, minY: true,
@@ -81,11 +93,14 @@ const PathAttributes = merge({
}, RenderableAttributes); }, RenderableAttributes);
const SpanAttributes = merge({ const SpanAttributes = merge({
fontFamily: true, font: {
fontSize: true, diff: fontDiffer
fontWeight: true, },
fontStyle: true, content: true,
line: true dx: true,
dy: true,
px: true,
py: true
}, RenderableAttributes); }, RenderableAttributes);
-21
View File
@@ -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
};
};
-71
View File
@@ -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)
};
}
+4 -3
View File
@@ -209,9 +209,10 @@ export default function(props) {
...extractFont(frame.props) ...extractFont(frame.props)
} }
}; };
return <Span {...spanProps} />
}) return <Span {...spanProps} />;
// TODO: format children });
return { return {
alignment, alignment,
children children
-26
View File
@@ -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 = <TSpan>{child.replace(newLine, ' ')}</TSpan>;
} else if (child.type === TSpan) {
span = child;
} else {
// give warning about the illegal child type
return;
}
spans.push(span);
});
return spans;
}