change copy right and add clip for ios

This commit is contained in:
Horcrux
2016-04-21 15:42:30 +08:00
parent cea32755f5
commit c8aaa1eb12
47 changed files with 454 additions and 313 deletions

View File

@@ -12,6 +12,7 @@ import * as Stroking from './examples/Stroking';
import * as Use from './examples/Use'; import * as Use from './examples/Use';
import * as Symbol from './examples/Symbol'; import * as Symbol from './examples/Symbol';
import * as Gradients from './examples/Gradients'; import * as Gradients from './examples/Gradients';
import * as Clipping from './examples/Clipping';
export { export {
Svg, Svg,
@@ -27,5 +28,6 @@ export {
G, G,
Use, Use,
Symbol, Symbol,
Gradients Gradients,
Clipping
}; };

View File

@@ -0,0 +1,124 @@
import React, {
Component
} from 'react-native';
import Svg, {
GlipPath,
Defs,
Line,
Rect,
Text,
G
} from 'react-native-art-svg';
class ClipPathExample extends Component{
static title = 'Clip by set clip-path with a path data';
render() {
return <Svg
height="100"
width="100"
>
<Rect
x="0"
y="0"
width="100"
height="100"
fill="red"
clipPath="M50,5L20,99L95,39L5,39L80,99z"
/>
</Svg>;
}
}
class ClipRulePathExample extends Component{
static title = 'Clip by set clip-path with a path data';
render() {
return <Svg
height="100"
width="100"
>
<G
clipPath="M50,5L20,99L95,39L5,39L80,99z"
clipRule="evenodd"
>
<Rect
x="0"
y="0"
width="50"
height="50"
fill="red"
/>
<Rect
x="50"
y="0"
width="50"
height="50"
fill="blue"
/>
<Rect
x="0"
y="50"
width="50"
height="50"
fill="yellow"
/>
<Rect
x="50"
y="50"
width="50"
height="50"
fill="green"
/>
</G>
</Svg>;
}
}
const icon = <Svg
height="20"
width="20"
>
<G
clipPath="M50,5L20,99L95,39L5,39L80,99z"
clipRule="evenodd"
scale="0.2"
>
<G>
<Rect
x="0"
y="0"
width="50"
height="50"
fill="red"
/>
<Rect
x="50"
y="0"
width="50"
height="50"
fill="blue"
/>
<Rect
x="0"
y="50"
width="50"
height="50"
fill="yellow"
/>
<Rect
x="50"
y="50"
width="50"
height="50"
fill="green"
/>
</G>
</G>
</Svg>;
const samples = [ClipPathExample, ClipRulePathExample];
export {
icon,
samples
}

View File

@@ -36,7 +36,9 @@
/** /**
* OPTION 2 * OPTION 2
* Load from pre-bundled file on disk. The static bundle is automatically * Load from pre-bundled file on disk. The static bundle is automatically
* generated by "Bundle React Native code and images" build step. * generated by the "Bundle React Native code and images" build step when
* running the project on an actual device or running the project on the
* simulator in the "Release" build configuration.
*/ */
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; // jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

View File

@@ -24,19 +24,21 @@ import {
} from 'react-native-art-svg'; } from 'react-native-art-svg';
import * as examples from './examples'; import * as examples from './examples';
import Modal from 'react-native-root-modal'; import Modal from 'react-native-root-modal';
const hairline = 1 / PixelRatio.get(); const hairline = StyleSheet.hairlineWidth;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
flex: 1, flex: 1,
backgroundColor: '#F5FCFF',
paddingTop: 20, paddingTop: 20,
alignItems: 'center', alignItems: 'center',
overflow: 'hidden' overflow: 'hidden'
}, },
content: { content: {
flex: 1,
alignSelf: 'stretch'
},
contentContainer: {
alignSelf: 'stretch', alignSelf: 'stretch',
alignItems: 'center',
borderTopWidth: hairline, borderTopWidth: hairline,
borderTopColor: '#ccc', borderTopColor: '#ccc',
borderBottomWidth: hairline, borderBottomWidth: hairline,
@@ -104,7 +106,7 @@ const styles = StyleSheet.create({
} }
}); });
const names = ['Svg', 'Stroking', 'Path', 'Line', 'Rect', 'Polygon', 'Polyline', 'Circle', 'Ellipse', 'G', 'Text', 'Use', 'Symbol', 'Gradients']; const names = ['Svg', 'Stroking', 'Path', 'Line', 'Rect', 'Polygon', 'Polyline', 'Circle', 'Ellipse', 'G', 'Text', 'Use', 'Symbol', 'Gradients', 'Clipping'];
class ArtSvgExample extends Component { class ArtSvgExample extends Component {
constructor() { constructor() {
@@ -184,7 +186,9 @@ class ArtSvgExample extends Component {
}; };
render() { render() {
return <View style={styles.container}> return <View
style={styles.container}
>
<Animated.Modal <Animated.Modal
visible={this.state.modal} visible={this.state.modal}
style={[styles.modal, { style={[styles.modal, {
@@ -237,9 +241,12 @@ class ArtSvgExample extends Component {
<Text style={styles.welcome}> <Text style={styles.welcome}>
SVG by ART! SVG by ART!
</Text> </Text>
<View style={styles.content}> <ScrollView
style={styles.content}
contentContainerStyle={styles.contentContainer}
>
{this.getExamples()} {this.getExamples()}
</View> </ScrollView>
</View>; </View>;
} }
} }

View File

@@ -253,6 +253,7 @@ public class RNSVGPathShadowNode extends RNSVGVirtualNode {
stops = new float[stopsCount]; stops = new float[stopsCount];
parseGradientStops(mFillColor, stopsCount, stops, stopsColors, 7); parseGradientStops(mFillColor, stopsCount, stops, stopsColors, 7);
// TODO:
float focusX = mFillColor[1]; float focusX = mFillColor[1];
float focusY = mFillColor[2]; float focusY = mFillColor[2];

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <CoreGraphics/CoreGraphics.h> #import <CoreGraphics/CoreGraphics.h>

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGBrush.h" #import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGBrush.h" #import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGLinearGradient.h" #import "RNSVGLinearGradient.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGBrush.h" #import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGPattern.h" #import "RNSVGPattern.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGBrush.h" #import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGRadialGradient.h" #import "RNSVGRadialGradient.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGBrush.h" #import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGSolidColor.h" #import "RNSVGSolidColor.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <QuartzCore/QuartzCore.h> #import <QuartzCore/QuartzCore.h>
@@ -13,13 +12,13 @@
#import "RNSVGCGFloatArray.h" #import "RNSVGCGFloatArray.h"
#import "RNSVGTextFrame.h" #import "RNSVGTextFrame.h"
#import "RCTConvert.h" #import "RCTConvert.h"
#import "RNSVGCGFillRule.h" #import "RNSVGCGFCRule.h"
@interface RCTConvert (RNSVG) @interface RCTConvert (RNSVG)
+ (CGPathRef)CGPath:(id)json; + (CGPathRef)CGPath:(id)json;
+ (CTTextAlignment)CTTextAlignment:(id)json; + (CTTextAlignment)CTTextAlignment:(id)json;
+ (RNSVGCGFillRule)ARTCGFillRule:(id)json; + (RNSVGCGFCRule)RNSVGCGFCRule:(id)json;
+ (RNSVGTextFrame)RNSVGTextFrame:(id)json; + (RNSVGTextFrame)RNSVGTextFrame:(id)json;
+ (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json; + (RNSVGCGFloatArray)RNSVGCGFloatArray:(id)json;
+ (RNSVGBrush *)RNSVGBrush:(id)json; + (RNSVGBrush *)RNSVGBrush:(id)json;

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RCTConvert+RNSVG.h" #import "RCTConvert+RNSVG.h"
@@ -14,7 +13,7 @@
#import "RNSVGRadialGradient.h" #import "RNSVGRadialGradient.h"
#import "RNSVGSolidColor.h" #import "RNSVGSolidColor.h"
#import "RCTLog.h" #import "RCTLog.h"
#import "RNSVGCGFillRule.h" #import "RNSVGCGFCRule.h"
@implementation RCTConvert (RNSVG) @implementation RCTConvert (RNSVG)
@@ -73,10 +72,10 @@ RCT_ENUM_CONVERTER(CTTextAlignment, (@{
@"justify": @(kCTTextAlignmentJustified), @"justify": @(kCTTextAlignmentJustified),
}), kCTTextAlignmentNatural, integerValue) }), kCTTextAlignmentNatural, integerValue)
RCT_ENUM_CONVERTER(RNSVGCGFillRule, (@{ RCT_ENUM_CONVERTER(RNSVGCGFCRule, (@{
@"evenodd": @(kARTCGFillRuleEvenodd), @"evenodd": @(kRNSVGCGFCRuleEvenodd),
@"nonzero": @(kARTCGFillRuleNonzero), @"nonzero": @(kRNSVGCGFCRuleNonzero),
}), kARTCGFillRuleEvenodd, intValue) }), kRNSVGCGFCRuleNonzero, intValue)
// This takes a tuple of text lines and a font to generate a CTLine for each text line. // 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. // This prepares everything for rendering a frame of text in RNSVGText.

View File

@@ -80,7 +80,7 @@
10A063011CC7320C0000CEEF /* RNSVGPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGPath.m; sourceTree = "<group>"; }; 10A063011CC7320C0000CEEF /* RNSVGPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGPath.m; sourceTree = "<group>"; };
10A063021CC7320C0000CEEF /* RNSVGSvgView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGSvgView.h; sourceTree = "<group>"; }; 10A063021CC7320C0000CEEF /* RNSVGSvgView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGSvgView.h; sourceTree = "<group>"; };
10A063031CC7320C0000CEEF /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSvgView.m; sourceTree = "<group>"; }; 10A063031CC7320C0000CEEF /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGSvgView.m; sourceTree = "<group>"; };
10FEAC6A1CC7D05200F1C23C /* RNSVGCGFillRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGCGFillRule.h; sourceTree = "<group>"; }; 10FEAC6A1CC7D05200F1C23C /* RNSVGCGFCRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGCGFCRule.h; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@@ -100,7 +100,7 @@
0CF68AEA1AF0549300FF9E5C /* Brushes */, 0CF68AEA1AF0549300FF9E5C /* Brushes */,
0CF68AF81AF0549300FF9E5C /* ViewManagers */, 0CF68AF81AF0549300FF9E5C /* ViewManagers */,
0CF68ADB1AF0549300FF9E5C /* RNSVGCGFloatArray.h */, 0CF68ADB1AF0549300FF9E5C /* RNSVGCGFloatArray.h */,
10FEAC6A1CC7D05200F1C23C /* RNSVGCGFillRule.h */, 10FEAC6A1CC7D05200F1C23C /* RNSVGCGFCRule.h */,
0CF68ADC1AF0549300FF9E5C /* RNSVGContainer.h */, 0CF68ADC1AF0549300FF9E5C /* RNSVGContainer.h */,
0CF68ADD1AF0549300FF9E5C /* RNSVGGroup.h */, 0CF68ADD1AF0549300FF9E5C /* RNSVGGroup.h */,
0CF68ADE1AF0549300FF9E5C /* RNSVGGroup.m */, 0CF68ADE1AF0549300FF9E5C /* RNSVGGroup.m */,

12
ios/RNSVGCGFCRule.h Normal file
View File

@@ -0,0 +1,12 @@
/**
* 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.
*/
typedef CF_ENUM(int32_t, RNSVGCGFCRule) {
kRNSVGCGFCRuleEvenodd,
kRNSVGCGFCRuleNonzero
};

View File

@@ -1,13 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
typedef CF_ENUM(int32_t, RNSVGCGFillRule) {
kARTCGFillRuleEvenodd,
kARTCGFillRuleNonzero
};

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
// A little helper to make sure we have the right memory allocation ready for use. // A little helper to make sure we have the right memory allocation ready for use.

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>

View File

@@ -1,17 +1,20 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "RNSVGContainer.h" #import "RNSVGContainer.h"
#import "RNSVGNode.h" #import "RNSVGNode.h"
#import "RNSVGCGFCRule.h"
@interface RNSVGGroup : RNSVGNode <RNSVGContainer> @interface RNSVGGroup : RNSVGNode <RNSVGContainer>
@property (nonatomic, assign) CGPathRef clipPath;
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
@end @end

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGGroup.h" #import "RNSVGGroup.h"
@@ -13,7 +12,7 @@
- (void)renderLayerTo:(CGContextRef)context - (void)renderLayerTo:(CGContextRef)context
{ {
// TO-DO: Clipping rectangle [self clip:context];
for (RNSVGNode *node in self.subviews) { for (RNSVGNode *node in self.subviews) {
[node renderTo:context]; [node renderTo:context];
} }

View File

@@ -1,14 +1,14 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "RNSVGCGFCRule.h"
/** /**
* RNSVG nodes are implemented as empty UIViews but this is just an implementation detail to fit * RNSVG nodes are implemented as empty UIViews but this is just an implementation detail to fit
@@ -20,6 +20,9 @@
@property (nonatomic, assign) CGFloat opacity; @property (nonatomic, assign) CGFloat opacity;
@property (nonatomic, assign) CGPathRef clipPath;
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
- (void)invalidate; - (void)invalidate;
- (void)renderTo:(CGContextRef)context; - (void)renderTo:(CGContextRef)context;
@@ -30,4 +33,6 @@
*/ */
- (void)renderLayerTo:(CGContextRef)context; - (void)renderLayerTo:(CGContextRef)context;
- (void)clip:(CGContextRef)context;
@end @end

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGNode.h" #import "RNSVGNode.h"
@@ -45,32 +44,64 @@
- (void)renderTo:(CGContextRef)context - (void)renderTo:(CGContextRef)context
{ {
if (self.opacity <= 0) { float opacity = self.opacity;
BOOL transparent = NO;
if (opacity <= 0) {
// Nothing to paint // Nothing to paint
return; return;
} }
if (self.opacity >= 1) { if (opacity >= 1) {
// Just paint at full opacity opacity = 1;
CGContextSaveGState(context); transparent = YES;
CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, 1);
[self renderLayerTo:context];
CGContextRestoreGState(context);
return;
} }
// This needs to be painted on a layer before being composited. // This needs to be painted on a layer before being composited.
CGContextSaveGState(context); CGContextSaveGState(context);
CGContextConcatCTM(context, self.transform); CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, self.opacity); CGContextSetAlpha(context, opacity);
if (transparent) {
CGContextBeginTransparencyLayer(context, NULL); CGContextBeginTransparencyLayer(context, NULL);
}
[self renderLayerTo:context]; [self renderLayerTo:context];
if (transparent) {
CGContextEndTransparencyLayer(context); CGContextEndTransparencyLayer(context);
}
CGContextRestoreGState(context); CGContextRestoreGState(context);
} }
- (void)setClipPath:(CGPathRef)clipPath
{
if (clipPath == _clipPath) {
return;
}
[self invalidate];
CGPathRelease(_clipPath);
_clipPath = CGPathRetain(clipPath);
}
- (void)dealloc
{
CGPathRelease(_clipPath);
}
- (void)renderLayerTo:(CGContextRef)context - (void)renderLayerTo:(CGContextRef)context
{ {
// abstract // abstract
} }
- (void)clip:(CGContextRef)context
{
if (self.clipPath) {
CGContextAddPath(context, self.clipPath);
if (self.clipRule == kRNSVGCGFCRuleEvenodd) {
CGContextEOClip(context);
} else {
CGContextClip(context);
}
}
}
@end @end

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGPath.h" #import "RNSVGPath.h"
@@ -35,7 +34,7 @@
CGPathDrawingMode mode = kCGPathStroke; CGPathDrawingMode mode = kCGPathStroke;
if (self.fill) { if (self.fill) {
if ([self.fill applyFillColor:context]) { if ([self.fill applyFillColor:context]) {
mode = self.fillRule == kARTCGFillRuleEvenodd ? kCGPathEOFill : kCGPathFill; mode = self.fillRule == kRNSVGCGFCRuleEvenodd ? kCGPathEOFill : kCGPathFill;
} else { } else {
CGContextSaveGState(context); CGContextSaveGState(context);
CGContextAddPath(context, self.d); CGContextAddPath(context, self.d);
@@ -63,6 +62,8 @@
} }
} }
[self clip:context];
CGContextAddPath(context, self.d); CGContextAddPath(context, self.d);
CGContextDrawPath(context, mode); CGContextDrawPath(context, mode);
} }

View File

@@ -1,23 +1,22 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "RNSVGBrush.h" #import "RNSVGBrush.h"
#import "RNSVGCGFloatArray.h" #import "RNSVGCGFloatArray.h"
#import "RNSVGCGFillRule.h" #import "RNSVGCGFCRule.h"
#import "RNSVGNode.h" #import "RNSVGNode.h"
@interface RNSVGRenderable : RNSVGNode @interface RNSVGRenderable : RNSVGNode
@property (nonatomic, strong) RNSVGBrush *fill; @property (nonatomic, strong) RNSVGBrush *fill;
@property (nonatomic, assign) RNSVGCGFillRule fillRule; @property (nonatomic, assign) RNSVGCGFCRule fillRule;
@property (nonatomic, assign) CGColorRef stroke; @property (nonatomic, assign) CGColorRef stroke;
@property (nonatomic, assign) CGFloat strokeWidth; @property (nonatomic, assign) CGFloat strokeWidth;
@property (nonatomic, assign) CGLineCap strokeLinecap; @property (nonatomic, assign) CGLineCap strokeLinecap;

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGRenderable.h" #import "RNSVGRenderable.h"
@@ -17,12 +16,6 @@
_fill = fill; _fill = fill;
} }
- (void)setFillRule:(RNSVGCGFillRule)fillRule
{
[self invalidate];
_fillRule = fillRule;
}
- (void)setStroke:(CGColorRef)stroke - (void)setStroke:(CGColorRef)stroke
{ {
if (stroke == _stroke) { if (stroke == _stroke) {

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGSvgView.h" #import "RNSVGSvgView.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGText.h" #import "RNSVGText.h"
@@ -54,7 +53,8 @@ static void RNSVGFreeTextFrame(RNSVGTextFrame frame)
} }
// to-do: draw along a path // to-do: draw along a path
// to-do: fill-rule
// to-do: clip
CGTextDrawingMode mode = kCGTextStroke; CGTextDrawingMode mode = kCGTextStroke;
if (self.fill) { if (self.fill) {
if ([self.fill applyFillColor:context]) { if ([self.fill applyFillColor:context]) {

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import <CoreText/CoreText.h> #import <CoreText/CoreText.h>

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGNodeManager.h" #import "RNSVGNodeManager.h"

View File

@@ -1,14 +1,13 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGGroupManager.h" #import "RNSVGGroupManager.h"
#import "RNSVGCGFCRule.h"
#import "RNSVGGroup.h" #import "RNSVGGroup.h"
@implementation RNSVGGroupManager @implementation RNSVGGroupManager
@@ -20,4 +19,8 @@ RCT_EXPORT_MODULE()
return [RNSVGGroup new]; return [RNSVGGroup new];
} }
RCT_EXPORT_VIEW_PROPERTY(clipPath, CGPath)
RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule)
@end @end

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGNode.h" #import "RNSVGNode.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGNodeManager.h" #import "RNSVGNodeManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGRenderableManager.h" #import "RNSVGRenderableManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGPathManager.h" #import "RNSVGPathManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGNodeManager.h" #import "RNSVGNodeManager.h"

View File

@@ -1,16 +1,15 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGRenderableManager.h" #import "RNSVGRenderableManager.h"
#import "RCTConvert+RNSVG.h" #import "RCTConvert+RNSVG.h"
#import "RNSVGCGFillRule.h" #import "RNSVGCGFCRule.h"
@implementation RNSVGRenderableManager @implementation RNSVGRenderableManager
@@ -25,8 +24,10 @@ RCT_EXPORT_VIEW_PROPERTY(strokeWidth, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(strokeLinecap, CGLineCap) RCT_EXPORT_VIEW_PROPERTY(strokeLinecap, CGLineCap)
RCT_EXPORT_VIEW_PROPERTY(strokeLinejoin, CGLineJoin) RCT_EXPORT_VIEW_PROPERTY(strokeLinejoin, CGLineJoin)
RCT_EXPORT_VIEW_PROPERTY(fill, RNSVGBrush) RCT_EXPORT_VIEW_PROPERTY(fill, RNSVGBrush)
RCT_EXPORT_VIEW_PROPERTY(fillRule, RNSVGCGFillRule) RCT_EXPORT_VIEW_PROPERTY(fillRule, RNSVGCGFCRule)
RCT_EXPORT_VIEW_PROPERTY(stroke, CGColor) RCT_EXPORT_VIEW_PROPERTY(stroke, CGColor)
RCT_EXPORT_VIEW_PROPERTY(strokeDash, RNSVGCGFloatArray) RCT_EXPORT_VIEW_PROPERTY(strokeDash, RNSVGCGFloatArray)
RCT_EXPORT_VIEW_PROPERTY(clipPath, CGPath)
RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule)
@end @end

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RCTViewManager.h" #import "RCTViewManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGSvgViewManager.h" #import "RNSVGSvgViewManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGRenderableManager.h" #import "RNSVGRenderableManager.h"

View File

@@ -1,10 +1,9 @@
/** /**
* Copyright (c) 2015-present, Facebook, Inc. * Copyright (c) 2015-present, Horcrux.
* All rights reserved. * All rights reserved.
* *
* This source code is licensed under the BSD-style license found in the * This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree.
* of patent rights can be found in the PATENTS file in the same directory.
*/ */
#import "RNSVGTextManager.h" #import "RNSVGTextManager.h"