From 1d06134719c27b948937930be460f7b10ac506c8 Mon Sep 17 00:00:00 2001 From: Horcrux Date: Mon, 9 Jan 2017 13:08:22 +0800 Subject: [PATCH] Add TextPath element --- elements/TSpan.js | 2 +- elements/TextPath.js | 21 ++-- index.js | 2 + ios/Elements/RNSVGGroup.m | 13 ++- ios/RNSVG.xcodeproj/project.pbxproj | 51 ++++---- ios/RNSVGNode.h | 11 +- ios/RNSVGNode.m | 14 +-- ios/RNSVGRenderable.m | 3 +- ios/Text/RNSVGSpan.h | 23 ---- ios/Text/RNSVGSpan.m | 110 ------------------ ios/Text/RNSVGTSpan.m | 3 +- ios/Text/RNSVGText.m | 14 ++- ios/Text/RNSVGTextPath.h | 7 +- ios/Utils/RCTConvert+RNSVG.h | 5 - ios/ViewManagers/RNSVGSpanManager.m | 30 ----- ...VGSpanManager.h => RNSVGTextPathManager.h} | 4 +- ios/ViewManagers/RNSVGTextPathManager.m | 24 ++++ lib/attributes.js | 5 + 18 files changed, 106 insertions(+), 236 deletions(-) delete mode 100644 ios/Text/RNSVGSpan.h delete mode 100644 ios/Text/RNSVGSpan.m delete mode 100644 ios/ViewManagers/RNSVGSpanManager.m rename ios/ViewManagers/{RNSVGSpanManager.h => RNSVGTextPathManager.h} (70%) create mode 100644 ios/ViewManagers/RNSVGTextPathManager.m diff --git a/elements/TSpan.js b/elements/TSpan.js index bca84cf1..9cf073a1 100644 --- a/elements/TSpan.js +++ b/elements/TSpan.js @@ -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'; diff --git a/elements/TextPath.js b/elements/TextPath.js index d7476d69..cce88e0d 100644 --- a/elements/TextPath.js +++ b/elements/TextPath.js @@ -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'; @@ -27,25 +29,16 @@ class TextPath extends Shape { if (!href) { console.warn('Invalid `href` prop for `TextPath` element, expected a href like `"#id"`, but got: "' + props.href + '"'); } - + return ; } } const RNSVGTextPath = createReactNativeComponentClass({ - validAttributes: UseAttributes, + validAttributes: TextPathAttributes, uiViewClassName: 'RNSVGTextPath' }); diff --git a/index.js b/index.js index adfcab1c..a72b59c6 100644 --- a/index.js +++ b/index.js @@ -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, diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index aae4bd58..a2866276 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -67,9 +67,16 @@ { CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform); - CGPathRef clip = [self getComputedClipPath]; - if (clip && !CGPathContainsPoint(clip, nil, point, NO)) { - return nil; + 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]) { diff --git a/ios/RNSVG.xcodeproj/project.pbxproj b/ios/RNSVG.xcodeproj/project.pbxproj index 79ed9360..bc1d4ef3 100644 --- a/ios/RNSVG.xcodeproj/project.pbxproj +++ b/ios/RNSVG.xcodeproj/project.pbxproj @@ -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 = ""; }; 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 = ""; }; 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 = ""; }; @@ -161,12 +160,18 @@ 10FDEEB01D3FB60500A5C46C /* RNSVGBaseBrush.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBaseBrush.h; sourceTree = ""; }; 10FDEEB11D3FB60500A5C46C /* RNSVGBaseBrush.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGBaseBrush.m; sourceTree = ""; }; 10FDEEB31D3FBED400A5C46C /* RNSVGBrushType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGBrushType.h; sourceTree = ""; }; - - 7F888B9C1DD378000038D083 /* RNSVGGlyphPoint.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNSVGGlyphPoint.h; path = Utils/RNSVGGlyphPoint.h; sourceTree = ""; }; - 7FF070191DC249BE000E28A0 /* RNSVGTextAnchor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextAnchor.h; path = Utils/RNSVGTextAnchor.h; sourceTree = ""; }; + 7F08CE961E23476900650F83 /* RNSVGTextPathManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTextPathManager.h; sourceTree = ""; }; + 7F08CE971E23476900650F83 /* RNSVGTextPathManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTextPathManager.m; sourceTree = ""; }; + 7F08CE981E23476900650F83 /* RNSVGTSpanManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGTSpanManager.h; sourceTree = ""; }; + 7F08CE991E23476900650F83 /* RNSVGTSpanManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGTSpanManager.m; sourceTree = ""; }; + 7F08CE9C1E23479700650F83 /* RNSVGTextPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextPath.h; path = Text/RNSVGTextPath.h; sourceTree = ""; }; + 7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTextPath.m; path = Text/RNSVGTextPath.m; sourceTree = ""; }; + 7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTSpan.h; path = Text/RNSVGTSpan.h; sourceTree = ""; }; + 7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGTSpan.m; path = Text/RNSVGTSpan.m; sourceTree = ""; }; + 7F08CEA21E23481F00650F83 /* RNSVGGlyphPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGGlyphPoint.h; path = Utils/RNSVGGlyphPoint.h; sourceTree = ""; }; + 7F08CEA31E23481F00650F83 /* RNSVGTextAnchor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextAnchor.h; path = Utils/RNSVGTextAnchor.h; sourceTree = ""; }; 7F9CDAF81E1F809C00E0C805 /* RNSVGPathParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGPathParser.h; path = Utils/RNSVGPathParser.h; sourceTree = ""; }; 7F9CDAF91E1F809C00E0C805 /* RNSVGPathParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGPathParser.m; path = Utils/RNSVGPathParser.m; sourceTree = ""; }; - /* 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 = ""; @@ -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 = ""; @@ -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 */, diff --git a/ios/RNSVGNode.h b/ios/RNSVGNode.h index 42ab8d54..39f278e4 100644 --- a/ios/RNSVGNode.h +++ b/ios/RNSVGNode.h @@ -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 */ diff --git a/ios/RNSVGNode.m b/ios/RNSVGNode.m index 0d07c0d9..3c5c6849 100644 --- a/ios/RNSVGNode.m +++ b/ios/RNSVGNode.m @@ -58,13 +58,13 @@ if (opacity == _opacity) { return; } - + if (opacity < 0) { opacity = 0; } else if (opacity > 1) { opacity = 1; } - + [self invalidate]; _transparent = opacity < 1; _opacity = opacity; @@ -120,14 +120,14 @@ CGPathRelease(_cachedClipPath); _cachedClipPath = CGPathRetain([[[self getSvgView] getDefinedClipPath:self.clipPath] getPath:context]); } - + return [self getClipPath]; } - (void)clip:(CGContextRef)context { CGPathRef clipPath = [self getClipPath:context]; - + if (clipPath) { CGContextAddPath(context, clipPath); if (self.clipRule == kRNSVGCGFCRuleEvenodd) { @@ -152,7 +152,7 @@ // hitTest delagate - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { - + // abstract return nil; } @@ -169,7 +169,7 @@ while (parent && [parent class] != [RNSVGSvgView class]) { parent = parent.superview; } - + return (RNSVGSvgView *)parent; } @@ -177,7 +177,7 @@ { if (self.name) { RNSVGSvgView* svg = [self getSvgView]; - [svg defineTemplate:self templateRef:self.name]; + [svg defineTemplate:self templateName:self.name]; } } diff --git a/ios/RNSVGRenderable.m b/ios/RNSVGRenderable.m index 02e11c67..122106bf 100644 --- a/ios/RNSVGRenderable.m +++ b/ios/RNSVGRenderable.m @@ -137,8 +137,9 @@ return; } + [self invalidate]; CGPathRelease(_hitArea); - _hitArea = CGPathRetain(CFAutorelease(hitArea)); + _hitArea = CGPathRetain(hitArea); } - (void)setPropList:(NSArray *)propList diff --git a/ios/Text/RNSVGSpan.h b/ios/Text/RNSVGSpan.h deleted file mode 100644 index 27a98e0a..00000000 --- a/ios/Text/RNSVGSpan.h +++ /dev/null @@ -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 -#import -#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 diff --git a/ios/Text/RNSVGSpan.m b/ios/Text/RNSVGSpan.m deleted file mode 100644 index 383b44c9..00000000 --- a/ios/Text/RNSVGSpan.m +++ /dev/null @@ -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 diff --git a/ios/Text/RNSVGTSpan.m b/ios/Text/RNSVGTSpan.m index d5465333..634218db 100644 --- a/ios/Text/RNSVGTSpan.m +++ b/ios/Text/RNSVGTSpan.m @@ -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; diff --git a/ios/Text/RNSVGText.m b/ios/Text/RNSVGText.m index 4ef47b97..eefcca94 100644 --- a/ios/Text/RNSVGText.m +++ b/ios/Text/RNSVGText.m @@ -8,7 +8,7 @@ #import "RNSVGText.h" #import "RNSVGBezierPath.h" -#import "RCTFont.h" +#import #import @implementation RNSVGText @@ -66,11 +66,13 @@ - (RNSVGTextAnchor)getComputedTextAnchor { RNSVGTextAnchor anchor = self.textAnchor; - RNSVGText *child = [self.subviews objectAtIndex:0]; - - while (child.subviews.count && anchor == kRNSVGTextAnchorAuto) { - anchor = child.textAnchor; - child = [child.subviews objectAtIndex:0]; + 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; diff --git a/ios/Text/RNSVGTextPath.h b/ios/Text/RNSVGTextPath.h index 293e1ab9..dd200227 100644 --- a/ios/Text/RNSVGTextPath.h +++ b/ios/Text/RNSVGTextPath.h @@ -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 diff --git a/ios/Utils/RCTConvert+RNSVG.h b/ios/Utils/RCTConvert+RNSVG.h index c8d7068b..610be33f 100644 --- a/ios/Utils/RCTConvert+RNSVG.h +++ b/ios/Utils/RCTConvert+RNSVG.h @@ -10,7 +10,6 @@ #import #import "RCTConvert+RNSVG.h" #import "RNSVGCGFloatArray.h" -#import "RNSVGTextFrame.h" #import #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; diff --git a/ios/ViewManagers/RNSVGSpanManager.m b/ios/ViewManagers/RNSVGSpanManager.m deleted file mode 100644 index f3fd9410..00000000 --- a/ios/ViewManagers/RNSVGSpanManager.m +++ /dev/null @@ -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 diff --git a/ios/ViewManagers/RNSVGSpanManager.h b/ios/ViewManagers/RNSVGTextPathManager.h similarity index 70% rename from ios/ViewManagers/RNSVGSpanManager.h rename to ios/ViewManagers/RNSVGTextPathManager.h index cfd29417..165db271 100644 --- a/ios/ViewManagers/RNSVGSpanManager.h +++ b/ios/ViewManagers/RNSVGTextPathManager.h @@ -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 diff --git a/ios/ViewManagers/RNSVGTextPathManager.m b/ios/ViewManagers/RNSVGTextPathManager.m new file mode 100644 index 00000000..f0c58739 --- /dev/null +++ b/ios/ViewManagers/RNSVGTextPathManager.m @@ -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 diff --git a/lib/attributes.js b/lib/attributes.js index 5b74c97b..feab328d 100644 --- a/lib/attributes.js +++ b/lib/attributes.js @@ -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,