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 Symbol from './examples/Symbol';
import * as Gradients from './examples/Gradients';
import * as Clipping from './examples/Clipping';
export {
Svg,
@@ -27,5 +28,6 @@ export {
G,
Use,
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
* 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"];

View File

@@ -24,19 +24,21 @@ import {
} from 'react-native-art-svg';
import * as examples from './examples';
import Modal from 'react-native-root-modal';
const hairline = 1 / PixelRatio.get();
const hairline = StyleSheet.hairlineWidth;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
paddingTop: 20,
alignItems: 'center',
overflow: 'hidden'
},
content: {
flex: 1,
alignSelf: 'stretch'
},
contentContainer: {
alignSelf: 'stretch',
alignItems: 'center',
borderTopWidth: hairline,
borderTopColor: '#ccc',
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 {
constructor() {
@@ -184,7 +186,9 @@ class ArtSvgExample extends Component {
};
render() {
return <View style={styles.container}>
return <View
style={styles.container}
>
<Animated.Modal
visible={this.state.modal}
style={[styles.modal, {
@@ -237,9 +241,12 @@ class ArtSvgExample extends Component {
<Text style={styles.welcome}>
SVG by ART!
</Text>
<View style={styles.content}>
<ScrollView
style={styles.content}
contentContainerStyle={styles.contentContainer}
>
{this.getExamples()}
</View>
</ScrollView>
</View>;
}
}

View File

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

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <CoreGraphics/CoreGraphics.h>

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGBrush.h"
@@ -15,19 +14,19 @@
- (instancetype)initWithArray:(NSArray *)data
{
return [super init];
return [super init];
}
RCT_NOT_IMPLEMENTED(- (instancetype)init)
- (BOOL)applyFillColor:(CGContextRef)context
{
return NO;
return NO;
}
- (void)paint:(CGContextRef)context
{
// abstract
// abstract
}
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGLinearGradient.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGPattern.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRadialGradient.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGBrush.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGSolidColor.h"

View File

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

View File

@@ -80,7 +80,7 @@
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>"; };
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 */
/* Begin PBXFrameworksBuildPhase section */
@@ -100,7 +100,7 @@
0CF68AEA1AF0549300FF9E5C /* Brushes */,
0CF68AF81AF0549300FF9E5C /* ViewManagers */,
0CF68ADB1AF0549300FF9E5C /* RNSVGCGFloatArray.h */,
10FEAC6A1CC7D05200F1C23C /* RNSVGCGFillRule.h */,
10FEAC6A1CC7D05200F1C23C /* RNSVGCGFCRule.h */,
0CF68ADC1AF0549300FF9E5C /* RNSVGContainer.h */,
0CF68ADD1AF0549300FF9E5C /* RNSVGGroup.h */,
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.
*
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
// 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.
*
* 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.
* 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>

View File

@@ -1,17 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* 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 "RNSVGContainer.h"
#import "RNSVGNode.h"
#import "RNSVGCGFCRule.h"
@interface RNSVGGroup : RNSVGNode <RNSVGContainer>
@property (nonatomic, assign) CGPathRef clipPath;
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGGroup.h"
@@ -13,10 +12,10 @@
- (void)renderLayerTo:(CGContextRef)context
{
// TO-DO: Clipping rectangle
for (RNSVGNode *node in self.subviews) {
[node renderTo:context];
}
[self clip:context];
for (RNSVGNode *node in self.subviews) {
[node renderTo:context];
}
}
@end

View File

@@ -1,14 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* 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 <UIKit/UIKit.h>
#import "RNSVGCGFCRule.h"
/**
* 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) CGPathRef clipPath;
@property (nonatomic, assign) RNSVGCGFCRule clipRule;
- (void)invalidate;
- (void)renderTo:(CGContextRef)context;
@@ -30,4 +33,6 @@
*/
- (void)renderLayerTo:(CGContextRef)context;
- (void)clip:(CGContextRef)context;
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGNode.h"
@@ -15,62 +14,94 @@
- (void)insertSubview:(UIView *)subview atIndex:(NSInteger)index
{
[self invalidate];
[super insertSubview:subview atIndex:index];
[self invalidate];
[super insertSubview:subview atIndex:index];
}
- (void)removeFromSuperview
{
[self invalidate];
[super removeFromSuperview];
[self invalidate];
[super removeFromSuperview];
}
- (void)setOpacity:(CGFloat)opacity
{
[self invalidate];
_opacity = opacity;
[self invalidate];
_opacity = opacity;
}
- (void)setTransform:(CGAffineTransform)transform
{
[self invalidate];
super.transform = transform;
[self invalidate];
super.transform = transform;
}
- (void)invalidate
{
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
[container invalidate];
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
[container invalidate];
}
- (void)renderTo:(CGContextRef)context
{
if (self.opacity <= 0) {
// Nothing to paint
return;
}
if (self.opacity >= 1) {
// Just paint at full opacity
float opacity = self.opacity;
BOOL transparent = NO;
if (opacity <= 0) {
// Nothing to paint
return;
}
if (opacity >= 1) {
opacity = 1;
transparent = YES;
}
// This needs to be painted on a layer before being composited.
CGContextSaveGState(context);
CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, 1);
CGContextSetAlpha(context, opacity);
if (transparent) {
CGContextBeginTransparencyLayer(context, NULL);
}
[self renderLayerTo:context];
if (transparent) {
CGContextEndTransparencyLayer(context);
}
CGContextRestoreGState(context);
return;
}
// This needs to be painted on a layer before being composited.
CGContextSaveGState(context);
CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, self.opacity);
CGContextBeginTransparencyLayer(context, NULL);
[self renderLayerTo:context];
CGContextEndTransparencyLayer(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
{
// abstract
// abstract
}
- (void)clip:(CGContextRef)context
{
if (self.clipPath) {
CGContextAddPath(context, self.clipPath);
if (self.clipRule == kRNSVGCGFCRuleEvenodd) {
CGContextEOClip(context);
} else {
CGContextClip(context);
}
}
}
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* 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>

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGPath.h"
@@ -13,58 +12,60 @@
- (void)setD:(CGPathRef)d
{
if (d == _d) {
return;
}
[self invalidate];
CGPathRelease(_d);
_d = CGPathRetain(d);
if (d == _d) {
return;
}
[self invalidate];
CGPathRelease(_d);
_d = CGPathRetain(d);
}
- (void)dealloc
{
CGPathRelease(_d);
CGPathRelease(_d);
}
- (void)renderLayerTo:(CGContextRef)context
{
if ((!self.fill && !self.stroke) || !self.d) {
return;
}
CGPathDrawingMode mode = kCGPathStroke;
if (self.fill) {
if ([self.fill applyFillColor:context]) {
mode = self.fillRule == kARTCGFillRuleEvenodd ? kCGPathEOFill : kCGPathFill;
} else {
CGContextSaveGState(context);
CGContextAddPath(context, self.d);
CGContextClip(context);
[self.fill paint:context];
CGContextRestoreGState(context);
if (!self.stroke) {
if ((!self.fill && !self.stroke) || !self.d) {
return;
}
}
}
if (self.stroke) {
CGContextSetStrokeColorWithColor(context, self.stroke);
CGContextSetLineWidth(context, self.strokeWidth);
CGContextSetLineCap(context, self.strokeLinecap);
CGContextSetLineJoin(context, self.strokeLinejoin);
RNSVGCGFloatArray dash = self.strokeDash;
if (dash.count) {
CGContextSetLineDash(context, 0, dash.array, dash.count);
CGPathDrawingMode mode = kCGPathStroke;
if (self.fill) {
if ([self.fill applyFillColor:context]) {
mode = self.fillRule == kRNSVGCGFCRuleEvenodd ? kCGPathEOFill : kCGPathFill;
} else {
CGContextSaveGState(context);
CGContextAddPath(context, self.d);
CGContextClip(context);
[self.fill paint:context];
CGContextRestoreGState(context);
if (!self.stroke) {
return;
}
}
}
if (mode == kCGPathFill) {
mode = kCGPathFillStroke;
} else if (mode == kCGPathEOFill) {
mode = kCGPathEOFillStroke;
if (self.stroke) {
CGContextSetStrokeColorWithColor(context, self.stroke);
CGContextSetLineWidth(context, self.strokeWidth);
CGContextSetLineCap(context, self.strokeLinecap);
CGContextSetLineJoin(context, self.strokeLinejoin);
RNSVGCGFloatArray dash = self.strokeDash;
if (dash.count) {
CGContextSetLineDash(context, 0, dash.array, dash.count);
}
if (mode == kCGPathFill) {
mode = kCGPathFillStroke;
} else if (mode == kCGPathEOFill) {
mode = kCGPathEOFillStroke;
}
}
}
CGContextAddPath(context, self.d);
CGContextDrawPath(context, mode);
[self clip:context];
CGContextAddPath(context, self.d);
CGContextDrawPath(context, mode);
}
@end

View File

@@ -1,23 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* 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 "RNSVGBrush.h"
#import "RNSVGCGFloatArray.h"
#import "RNSVGCGFillRule.h"
#import "RNSVGCGFCRule.h"
#import "RNSVGNode.h"
@interface RNSVGRenderable : RNSVGNode
@property (nonatomic, strong) RNSVGBrush *fill;
@property (nonatomic, assign) RNSVGCGFillRule fillRule;
@property (nonatomic, assign) RNSVGCGFCRule fillRule;
@property (nonatomic, assign) CGColorRef stroke;
@property (nonatomic, assign) CGFloat strokeWidth;
@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.
*
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRenderable.h"
@@ -12,84 +11,78 @@
@implementation RNSVGRenderable
- (void)setFill:(RNSVGBrush *)fill
{
[self invalidate];
_fill = fill;
}
- (void)setFillRule:(RNSVGCGFillRule)fillRule
{
[self invalidate];
_fillRule = fillRule;
_fill = fill;
}
- (void)setStroke:(CGColorRef)stroke
{
if (stroke == _stroke) {
return;
}
[self invalidate];
CGColorRelease(_stroke);
_stroke = CGColorRetain(stroke);
if (stroke == _stroke) {
return;
}
[self invalidate];
CGColorRelease(_stroke);
_stroke = CGColorRetain(stroke);
}
- (void)setStrokeWidth:(CGFloat)strokeWidth
{
[self invalidate];
_strokeWidth = strokeWidth;
[self invalidate];
_strokeWidth = strokeWidth;
}
- (void)setStrokeLinecap:(CGLineCap)strokeLinecap
{
[self invalidate];
_strokeLinecap = strokeLinecap;
[self invalidate];
_strokeLinecap = strokeLinecap;
}
- (void)setStrokeJoin:(CGLineJoin)strokeLinejoin
{
[self invalidate];
_strokeLinejoin = strokeLinejoin;
[self invalidate];
_strokeLinejoin = strokeLinejoin;
}
- (void)setStrokeDash:(RNSVGCGFloatArray)strokeDash
{
if (strokeDash.array == _strokeDash.array) {
return;
}
if (_strokeDash.array) {
free(_strokeDash.array);
}
[self invalidate];
_strokeDash = strokeDash;
if (strokeDash.array == _strokeDash.array) {
return;
}
if (_strokeDash.array) {
free(_strokeDash.array);
}
[self invalidate];
_strokeDash = strokeDash;
}
- (void)dealloc
{
CGColorRelease(_stroke);
if (_strokeDash.array) {
free(_strokeDash.array);
}
CGColorRelease(_stroke);
if (_strokeDash.array) {
free(_strokeDash.array);
}
}
- (void)renderTo:(CGContextRef)context
{
if (self.opacity <= 0 || self.opacity >= 1 || (self.fill && self.stroke)) {
// If we have both fill and stroke, we will need to paint this using normal compositing
[super renderTo: context];
return;
}
// This is a terminal with only one painting. Therefore we don't need to paint this
// off-screen. We can just composite it straight onto the buffer.
CGContextSaveGState(context);
CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, self.opacity);
[self renderLayerTo:context];
CGContextRestoreGState(context);
if (self.opacity <= 0 || self.opacity >= 1 || (self.fill && self.stroke)) {
// If we have both fill and stroke, we will need to paint this using normal compositing
[super renderTo: context];
return;
}
// This is a terminal with only one painting. Therefore we don't need to paint this
// off-screen. We can just composite it straight onto the buffer.
CGContextSaveGState(context);
CGContextConcatCTM(context, self.transform);
CGContextSetAlpha(context, self.opacity);
[self renderLayerTo:context];
CGContextRestoreGState(context);
}
- (void)renderLayerTo:(CGContextRef)context
{
// abstract
// abstract
}
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGSvgView.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* 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>

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGText.h"
@@ -54,7 +53,8 @@ static void RNSVGFreeTextFrame(RNSVGTextFrame frame)
}
// to-do: draw along a path
// to-do: fill-rule
// to-do: clip
CGTextDrawingMode mode = kCGTextStroke;
if (self.fill) {
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.
*
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <CoreText/CoreText.h>

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGNodeManager.h"

View File

@@ -1,14 +1,13 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGGroupManager.h"
#import "RNSVGCGFCRule.h"
#import "RNSVGGroup.h"
@implementation RNSVGGroupManager
@@ -20,4 +19,8 @@ RCT_EXPORT_MODULE()
return [RNSVGGroup new];
}
RCT_EXPORT_VIEW_PROPERTY(clipPath, CGPath)
RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule)
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGNode.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGNodeManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRenderableManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGPathManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGNodeManager.h"

View File

@@ -1,16 +1,15 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRenderableManager.h"
#import "RCTConvert+RNSVG.h"
#import "RNSVGCGFillRule.h"
#import "RNSVGCGFCRule.h"
@implementation RNSVGRenderableManager
@@ -18,15 +17,17 @@ RCT_EXPORT_MODULE()
- (RNSVGRenderable *)node
{
return [RNSVGRenderable new];
return [RNSVGRenderable new];
}
RCT_EXPORT_VIEW_PROPERTY(strokeWidth, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(strokeLinecap, CGLineCap)
RCT_EXPORT_VIEW_PROPERTY(strokeLinejoin, CGLineJoin)
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(strokeDash, RNSVGCGFloatArray)
RCT_EXPORT_VIEW_PROPERTY(clipPath, CGPath)
RCT_EXPORT_VIEW_PROPERTY(clipRule, RNSVGCGFCRule)
@end

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTViewManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGSvgViewManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGRenderableManager.h"

View File

@@ -1,10 +1,9 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) 2015-present, Horcrux.
* 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.
* This source code is licensed under the MIT-style license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RNSVGTextManager.h"