Add TextPath element

This commit is contained in:
Horcrux
2017-01-09 13:08:22 +08:00
parent f9fe7bdc4e
commit 1d06134719
18 changed files with 106 additions and 236 deletions

View File

@@ -1,5 +1,5 @@
import React, { PropTypes, Component } from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/src/renderers/native/createReactNativeComponentClass';
import extractText from '../lib/extract/extractText';
import {numberProp, pathProps, fontProps} from '../lib/props';
import {TSpanAttibutes} from '../lib/attributes';

View File

@@ -1,10 +1,12 @@
import React, {PropTypes} from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {UseAttributes} from '../lib/attributes';
import createReactNativeComponentClass from 'react-native/Libraries/Renderer/src/renderers/native/createReactNativeComponentClass';
import {TextPathAttributes} from '../lib/attributes';
import extractText from '../lib/extract/extractText';
import Shape from './Shape';
import {pathProps, fontProps} from '../lib/props';
const idExpReg = /^#(.+)$/;
class TextPath extends Shape {
static displayName = 'Span';
@@ -30,22 +32,13 @@ class TextPath extends Shape {
return <RNSVGTextPath
href={href}
{...this.extractProps({
...props,
x: null,
y: null
})}
{...extractText({
...props,
dx: null,
dy: null
})}
{...extractText({children: props.children})}
/>;
}
}
const RNSVGTextPath = createReactNativeComponentClass({
validAttributes: UseAttributes,
validAttributes: TextPathAttributes,
uiViewClassName: 'RNSVGTextPath'
});

View File

@@ -9,6 +9,7 @@ import Path from './elements/Path';
import G from './elements/G';
import Text from './elements/Text';
import TSpan from './elements/TSpan';
import TextPath from './elements/TextPath';
import Use from './elements/Use';
import Image from './elements/Image';
import Symbol from './elements/Symbol';
@@ -25,6 +26,7 @@ export {
G,
Text,
TSpan,
TextPath,
Path,
Polygon,
Polyline,

View File

@@ -67,11 +67,18 @@
{
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform);
CGPathRef clip = [self getComputedClipPath];
if (clip && !CGPathContainsPoint(clip, nil, point, NO)) {
CGPathRef clip = [self getClipPath];
if (clip) {
CGPathRef transformedClipPath = CGPathCreateCopyByTransformingPath(clip, &matrix);
BOOL insideClipPath = CGPathContainsPoint(clip, nil, point, self.clipRule == kRNSVGCGFCRuleEvenodd);
CGPathRelease(transformedClipPath);
if (!insideClipPath) {
return nil;
}
}
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
if ([node isKindOfClass:[RNSVGNode class]]) {
if (event) {

View File

@@ -23,8 +23,6 @@
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 */; };
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 */; };
@@ -51,6 +49,10 @@
10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ED4A9D1CF0656A0078BC02 /* RNSVGClipPathManager.m */; };
10ED4AA21CF078830078BC02 /* RNSVGNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 10ED4AA11CF078830078BC02 /* RNSVGNode.m */; };
10FDEEB21D3FB60500A5C46C /* RNSVGBaseBrush.m in Sources */ = {isa = PBXBuildFile; fileRef = 10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */; };
7F08CE9A1E23476900650F83 /* RNSVGTextPathManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */; };
7F08CE9B1E23476900650F83 /* RNSVGTSpanManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE991E23476900650F83 /* RNSVGTSpanManager.m */; };
7F08CEA01E23479700650F83 /* RNSVGTextPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */; };
7F08CEA11E23479700650F83 /* RNSVGTSpan.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */; };
7F9CDAFA1E1F809C00E0C805 /* RNSVGPathParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 7F9CDAF91E1F809C00E0C805 /* RNSVGPathParser.m */; };
/* End PBXBuildFile section */
@@ -96,16 +98,13 @@
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>"; };
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>"; };
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>"; };
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>"; };
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>"; };
107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTSpanManager.h; sourceTree = "<group>"; };
107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTSpanManager.m; sourceTree = "<group>"; };
107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; 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>"; };
10ABC7341D43595E006CCF6E /* RNSVGViewBox.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGViewBox.h; sourceTree = "<group>"; };
@@ -161,12 +160,18 @@
10FDEEB01D3FB60500A5C46C /* RNSVGBaseBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBaseBrush.h; sourceTree = "<group>"; };
10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGBaseBrush.m; sourceTree = "<group>"; };
10FDEEB31D3FBED400A5C46C /* RNSVGBrushType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBrushType.h; sourceTree = "<group>"; };
7F888B9C1DD378000038D083 /* RNSVGGlyphPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSVGGlyphPoint.h; path = Utils/RNSVGGlyphPoint.h; sourceTree = "<group>"; };
7FF070191DC249BE000E28A0 /* RNSVGTextAnchor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextAnchor.h; path = Utils/RNSVGTextAnchor.h; sourceTree = "<group>"; };
7F08CE961E23476900650F83 /* RNSVGTextPathManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTextPathManager.h; sourceTree = "<group>"; };
7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTextPathManager.m; sourceTree = "<group>"; };
7F08CE981E23476900650F83 /* RNSVGTSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTSpanManager.h; sourceTree = "<group>"; };
7F08CE991E23476900650F83 /* RNSVGTSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTSpanManager.m; sourceTree = "<group>"; };
7F08CE9C1E23479700650F83 /* RNSVGTextPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextPath.h; path = Text/RNSVGTextPath.h; sourceTree = "<group>"; };
7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTextPath.m; path = Text/RNSVGTextPath.m; sourceTree = "<group>"; };
7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTSpan.h; path = Text/RNSVGTSpan.h; sourceTree = "<group>"; };
7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; sourceTree = "<group>"; };
7F08CEA21E23481F00650F83 /* RNSVGGlyphPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGGlyphPoint.h; path = Utils/RNSVGGlyphPoint.h; sourceTree = "<group>"; };
7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextAnchor.h; path = Utils/RNSVGTextAnchor.h; sourceTree = "<group>"; };
7F9CDAF81E1F809C00E0C805 /* RNSVGPathParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPathParser.h; path = Utils/RNSVGPathParser.h; sourceTree = "<group>"; };
7F9CDAF91E1F809C00E0C805 /* RNSVGPathParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPathParser.m; path = Utils/RNSVGPathParser.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -229,6 +234,10 @@
0CF68AF81AF0549300FF9E5C /* ViewManagers */ = {
isa = PBXGroup;
children = (
7F08CE961E23476900650F83 /* RNSVGTextPathManager.h */,
7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */,
7F08CE981E23476900650F83 /* RNSVGTSpanManager.h */,
7F08CE991E23476900650F83 /* RNSVGTSpanManager.m */,
10ABC7311D435915006CCF6E /* RNSVGViewBoxManager.h */,
10ABC7321D435915006CCF6E /* RNSVGViewBoxManager.m */,
10BEC1BE1D3F680F00FDCB19 /* RNSVGLinearGradientManager.h */,
@@ -263,8 +272,6 @@
10BA0D311CE74E3100887C2B /* RNSVGSvgViewManager.m */,
10BA0D321CE74E3100887C2B /* RNSVGTextManager.h */,
10BA0D331CE74E3100887C2B /* RNSVGTextManager.m */,
107CD53C1D7166B700F0A7AC /* RNSVGTSpanManager.h */,
107CD53D1D7166B700F0A7AC /* RNSVGTSpanManager.m */,
);
path = ViewManagers;
sourceTree = "<group>";
@@ -287,10 +294,12 @@
1039D27F1CE71D9B001E90A8 /* Text */ = {
isa = PBXGroup;
children = (
7F08CE9C1E23479700650F83 /* RNSVGTextPath.h */,
7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */,
7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */,
7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */,
103371331D41D3400028AF13 /* RNSVGBezierPath.h */,
103371311D41C5C90028AF13 /* RNSVGBezierPath.m */,
107CD53B1D7166A000F0A7AC /* RNSVGTSpan.h */,
107CD53F1D71672E00F0A7AC /* RNSVGTSpan.m */,
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */,
1039D2901CE71EC2001E90A8 /* RNSVGText.m */,
);
@@ -325,9 +334,10 @@
1039D29A1CE7212C001E90A8 /* Utils */ = {
isa = PBXGroup;
children = (
7F08CEA21E23481F00650F83 /* RNSVGGlyphPoint.h */,
7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */,
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */,
10ABC7381D43982B006CCF6E /* RNSVGVBMOS.h */,
7FF070191DC249BE000E28A0 /* RNSVGTextAnchor.h */,
10ABC7371D439779006CCF6E /* RNSVGCGFCRule.h */,
1039D2AE1CE72F27001E90A8 /* RNSVGPercentageConverter.h */,
1039D2AF1CE72F27001E90A8 /* RNSVGPercentageConverter.m */,
@@ -335,11 +345,6 @@
7F9CDAF91E1F809C00E0C805 /* RNSVGPathParser.m */,
1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */,
1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */,
<<<<<<< HEAD
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */,
7F888B9C1DD378000038D083 /* RNSVGGlyphPoint.h */,
=======
>>>>>>> master
);
name = Utils;
sourceTree = "<group>";
@@ -409,13 +414,13 @@
10BA0D491CE74E3D00887C2B /* RNSVGEllipse.m in Sources */,
10ABC7331D435915006CCF6E /* RNSVGViewBoxManager.m in Sources */,
1039D28B1CE71EB7001E90A8 /* RNSVGPath.m in Sources */,
7F08CEA01E23479700650F83 /* RNSVGTextPath.m in Sources */,
0CF68B0D1AF0549300FF9E5C /* RNSVGPattern.m in Sources */,
1023B4931D3DF5060051496D /* RNSVGUse.m in Sources */,
10BEC1C21D3F680F00FDCB19 /* RNSVGLinearGradientManager.m in Sources */,
1039D2951CE71EC2001E90A8 /* RNSVGText.m in Sources */,
10BA0D3B1CE74E3100887C2B /* RNSVGRectManager.m in Sources */,
0CF68B071AF0549300FF9E5C /* RNSVGRenderable.m in Sources */,
107CD53E1D7166B700F0A7AC /* RNSVGTSpanManager.m in Sources */,
1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */,
10ED4A9E1CF0656A0078BC02 /* RNSVGClipPathManager.m in Sources */,
10BEC1C61D3F7BD300FDCB19 /* RNSVGBrushConverter.m in Sources */,
@@ -424,7 +429,6 @@
10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */,
0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */,
10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */,
107CD5401D71672E00F0A7AC /* RNSVGTSpan.m in Sources */,
103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */,
10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */,
10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */,
@@ -439,6 +443,9 @@
0CF68B0B1AF0549300FF9E5C /* RNSVGBrush.m in Sources */,
7F9CDAFA1E1F809C00E0C805 /* RNSVGPathParser.m in Sources */,
10BA0D361CE74E3100887C2B /* RNSVGGroupManager.m in Sources */,
7F08CE9A1E23476900650F83 /* RNSVGTextPathManager.m in Sources */,
7F08CE9B1E23476900650F83 /* RNSVGTSpanManager.m in Sources */,
7F08CEA11E23479700650F83 /* RNSVGTSpan.m in Sources */,
10BA0D4A1CE74E3D00887C2B /* RNSVGLine.m in Sources */,
10FDEEB21D3FB60500A5C46C /* RNSVGBaseBrush.m in Sources */,
1039D28C1CE71EB7001E90A8 /* RNSVGSvgView.m in Sources */,

View File

@@ -36,8 +36,14 @@
*/
- (void)renderLayerTo:(CGContextRef)context;
/**
* get clipPath from cache
*/
- (CGPathRef)getClipPath;
/**
* get clipPath through context
*/
- (CGPathRef)getClipPath:(CGContextRef)context;
/**
@@ -50,11 +56,6 @@
*/
- (CGPathRef)getPath:(CGContextRef) context;
/**
* getComputedClipPath will return the CGPathRef computed with clipPath
*/
- (CGPathRef)getComputedClipPath;
/**
* run hitTest
*/

View File

@@ -177,7 +177,7 @@
{
if (self.name) {
RNSVGSvgView* svg = [self getSvgView];
[svg defineTemplate:self templateRef:self.name];
[svg defineTemplate:self templateName:self.name];
}
}

View File

@@ -137,8 +137,9 @@
return;
}
[self invalidate];
CGPathRelease(_hitArea);
_hitArea = CGPathRetain(CFAutorelease(hitArea));
_hitArea = CGPathRetain(hitArea);
}
- (void)setPropList:(NSArray<NSString *> *)propList

View File

@@ -1,23 +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 <Foundation/Foundation.h>
#import <CoreText/CoreText.h>
#import "RNSVGPath.h"
#import "RNSVGText.h"
@interface RNSVGSpan : RNSVGPath
@property (nonatomic, assign) CGFloat dx;
@property (nonatomic, assign) CGFloat dy;
@property (nonatomic, strong) NSString *px;
@property (nonatomic, strong) NSString *py;
@property (nonatomic, assign) CTFontRef font;
@property (nonatomic, strong) NSString *content;
@end

View File

@@ -1,110 +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 "RNSVGSpan.h"
#import "RNSVGBezierPath.h"
@class RNSVGText;
@implementation RNSVGSpan
- (CGPathRef)getPath:(CGContextRef)context
{
[self setBoundingBox:CGContextGetClipBoundingBox(context)];
CGMutablePathRef path = CGPathCreateMutable();
RNSVGText *text = [self getText];
if (![self.content isEqualToString:@""]) {
// Create a dictionary for this font
CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{
(NSString *)kCTFontAttributeName: (__bridge id)self.font,
(NSString *)kCTForegroundColorFromContextAttributeName: @YES
};
CFStringRef string = (__bridge CFStringRef)self.content;
CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, string, attributes);
CTLineRef line = CTLineCreateWithAttributedString(attrString);
CFRelease(attrString);
CGMutablePathRef linePath = [self setLinePath:line];
// Set up text frame with font metrics
CGFloat size = CTFontGetSize(self.font);
CGFloat px = self.px ? [self getWidthRelatedValue:self.px] : 0;
CGFloat py = self.py ? [self getHeightRelatedValue:self.py] : 0;
if (self.px) {
text.offsetX = px;
}
if (self.py) {
text.offsetY = py + size * 1.1;
}
text.offsetX += self.dx;
text.offsetY += self.dy;
CGAffineTransform offset = CGAffineTransformMakeTranslation(text.offsetX, text.offsetY);
text.offsetX += CTLineGetTypographicBounds(line, nil, nil, nil);
CGPathAddPath(path, &offset, linePath);
CGPathRelease(linePath);
} else {
text.offsetX += self.dx;
text.offsetY += self.dy;
}
return (CGPathRef)CFAutorelease(path);
}
- (RNSVGText *)getText
{
return self.superview;
}
- (CGMutablePathRef)setLinePath:(CTLineRef)line
{
CGAffineTransform upsideDown = CGAffineTransformMakeScale(1.0, -1.0);
CGMutablePathRef path = CGPathCreateMutable();
CFArrayRef glyphRuns = CTLineGetGlyphRuns(line);
CTRunRef run = CFArrayGetValueAtIndex(glyphRuns, 0);
CFIndex runGlyphCount = CTRunGetGlyphCount(run);
CGPoint positions[runGlyphCount];
CGGlyph glyphs[runGlyphCount];
// Grab the glyphs, positions, and font
CTRunGetPositions(run, CFRangeMake(0, 0), positions);
CTRunGetGlyphs(run, CFRangeMake(0, 0), glyphs);
CFDictionaryRef attributes = CTRunGetAttributes(run);
CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName);
for(CFIndex i = 0; i < runGlyphCount; ++i) {
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyphs[i], nil);
CGPoint point = positions[i];
if (letter) {
CGAffineTransform transform;
transform = CGAffineTransformTranslate(upsideDown, point.x, point.y);
CGPathAddPath(path, &transform, letter);
}
CGPathRelease(letter);
}
return path;
}
@end

View File

@@ -81,8 +81,7 @@
CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName);
CGFloat lineStartX;
CFIndex i;
for(i = 0; i < runGlyphCount; i++) {
for(CFIndex i = 0; i < runGlyphCount; i++) {
RNSVGGlyphPoint computedPoint = [self getComputedGlyphPoint:i glyphOffset:positions[i]];
if (!i) {
lineStartX = computedPoint.x;

View File

@@ -8,7 +8,7 @@
#import "RNSVGText.h"
#import "RNSVGBezierPath.h"
#import "RCTFont.h"
#import <React/RCTFont.h>
#import <CoreText/CoreText.h>
@implementation RNSVGText
@@ -66,12 +66,14 @@
- (RNSVGTextAnchor)getComputedTextAnchor
{
RNSVGTextAnchor anchor = self.textAnchor;
if (self.subviews.count > 0) {
RNSVGText *child = [self.subviews objectAtIndex:0];
while (child.subviews.count && anchor == kRNSVGTextAnchorAuto) {
anchor = child.textAnchor;
child = [child.subviews objectAtIndex:0];
}
}
return anchor;
}

View File

@@ -11,11 +11,8 @@
#import "RNSVGPath.h"
#import "RNSVGText.h"
@interface RNSVGTextPath : RNSVGPath
@interface RNSVGTextPath : RNSVGText
@property (nonatomic, strong) NSString *positionX;
@property (nonatomic, strong) NSString *positionY;
@property (nonatomic, assign) CTFontRef font;
@property (nonatomic, strong) NSString *content;
@property (nonatomic, strong) NSString *href;
@end

View File

@@ -10,7 +10,6 @@
#import <CoreText/CoreText.h>
#import "RCTConvert+RNSVG.h"
#import "RNSVGCGFloatArray.h"
#import "RNSVGTextFrame.h"
#import <React/RCTConvert.h>
#import "RNSVGCGFCRule.h"
#import "RNSVGVBMOS.h"
@@ -20,13 +19,9 @@
@interface RCTConvert (RNSVG)
<<<<<<< HEAD
+ (CGPathRef)CGPath:(id)json;
+ (RNSVGTextAnchor)RNSVGTextAnchor:(id)json;
=======
+ (CGPathRef)CGPath:(NSString *)d;
+ (CTTextAlignment)CTTextAlignment:(id)json;
>>>>>>> master
+ (RNSVGCGFCRule)RNSVGCGFCRule:(id)json;
+ (RNSVGVBMOS)RNSVGVBMOS:(id)json;
+ (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json;

View File

@@ -1,30 +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 "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)
RCT_EXPORT_VIEW_PROPERTY(content, NSString)
@end

View File

@@ -6,8 +6,8 @@
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRenderableManager.h"
#import "RNSVGTextManager.h"
@interface RNSVGSpanManager : RNSVGRenderableManager
@interface RNSVGTextPathManager : RNSVGRenderableManager
@end

View File

@@ -0,0 +1,24 @@
/**
* 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 "RNSVGTextPathManager.h"
#import "RNSVGTextPath.h"
@implementation RNSVGTextPathManager
RCT_EXPORT_MODULE()
- (RNSVGRenderable *)node
{
return [RNSVGTextPath new];
}
RCT_EXPORT_VIEW_PROPERTY(href, NSString)
@end

View File

@@ -98,6 +98,10 @@ const TextAttributes = merge({
positionY: true
}, RenderableAttributes);
const TextPathAttributes = {
href: true
};
const TSpanAttibutes = merge({
content: true
}, TextAttributes);
@@ -173,6 +177,7 @@ export {
PathAttributes,
TextAttributes,
TSpanAttibutes,
TextPathAttributes,
GroupAttributes,
ClipPathAttributes,
CircleAttributes,