mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-02 14:50:43 +00:00
BezierPath => BezierTransformer
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
1023B4901D3DF4C40051496D /* RNSVGDefs.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B48F1D3DF4C40051496D /* RNSVGDefs.m */; };
|
1023B4901D3DF4C40051496D /* RNSVGDefs.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B48F1D3DF4C40051496D /* RNSVGDefs.m */; };
|
||||||
1023B4931D3DF5060051496D /* RNSVGUse.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B4921D3DF5060051496D /* RNSVGUse.m */; };
|
1023B4931D3DF5060051496D /* RNSVGUse.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B4921D3DF5060051496D /* RNSVGUse.m */; };
|
||||||
1023B4961D3DF57D0051496D /* RNSVGUseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B4951D3DF57D0051496D /* RNSVGUseManager.m */; };
|
1023B4961D3DF57D0051496D /* RNSVGUseManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 1023B4951D3DF57D0051496D /* RNSVGUseManager.m */; };
|
||||||
103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 103371311D41C5C90028AF13 /* RNSVGBezierPath.m */; };
|
103371321D41C5C90028AF13 /* RNSVGBezierTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 103371311D41C5C90028AF13 /* RNSVGBezierTransformer.m */; };
|
||||||
1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2821CE71EB7001E90A8 /* RNSVGGroup.m */; };
|
1039D2891CE71EB7001E90A8 /* RNSVGGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2821CE71EB7001E90A8 /* RNSVGGroup.m */; };
|
||||||
1039D28A1CE71EB7001E90A8 /* RNSVGImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2841CE71EB7001E90A8 /* RNSVGImage.m */; };
|
1039D28A1CE71EB7001E90A8 /* RNSVGImage.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2841CE71EB7001E90A8 /* RNSVGImage.m */; };
|
||||||
1039D28B1CE71EB7001E90A8 /* RNSVGPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2861CE71EB7001E90A8 /* RNSVGPath.m */; };
|
1039D28B1CE71EB7001E90A8 /* RNSVGPath.m in Sources */ = {isa = PBXBuildFile; fileRef = 1039D2861CE71EB7001E90A8 /* RNSVGPath.m */; };
|
||||||
@@ -86,8 +86,8 @@
|
|||||||
1023B4921D3DF5060051496D /* RNSVGUse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGUse.m; path = Elements/RNSVGUse.m; sourceTree = "<group>"; };
|
1023B4921D3DF5060051496D /* RNSVGUse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGUse.m; path = Elements/RNSVGUse.m; sourceTree = "<group>"; };
|
||||||
1023B4941D3DF57D0051496D /* RNSVGUseManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGUseManager.h; sourceTree = "<group>"; };
|
1023B4941D3DF57D0051496D /* RNSVGUseManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNSVGUseManager.h; sourceTree = "<group>"; };
|
||||||
1023B4951D3DF57D0051496D /* RNSVGUseManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGUseManager.m; sourceTree = "<group>"; };
|
1023B4951D3DF57D0051496D /* RNSVGUseManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNSVGUseManager.m; sourceTree = "<group>"; };
|
||||||
103371311D41C5C90028AF13 /* RNSVGBezierPath.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGBezierPath.m; path = Text/RNSVGBezierPath.m; sourceTree = "<group>"; };
|
103371311D41C5C90028AF13 /* RNSVGBezierTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGBezierTransformer.m; path = Text/RNSVGBezierTransformer.m; sourceTree = "<group>"; };
|
||||||
103371331D41D3400028AF13 /* RNSVGBezierPath.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGBezierPath.h; path = Text/RNSVGBezierPath.h; sourceTree = "<group>"; };
|
103371331D41D3400028AF13 /* RNSVGBezierTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGBezierTransformer.h; path = Text/RNSVGBezierTransformer.h; sourceTree = "<group>"; };
|
||||||
1039D2811CE71EB7001E90A8 /* RNSVGGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGGroup.h; path = Elements/RNSVGGroup.h; sourceTree = "<group>"; };
|
1039D2811CE71EB7001E90A8 /* RNSVGGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGGroup.h; path = Elements/RNSVGGroup.h; sourceTree = "<group>"; };
|
||||||
1039D2821CE71EB7001E90A8 /* RNSVGGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGGroup.m; path = Elements/RNSVGGroup.m; sourceTree = "<group>"; };
|
1039D2821CE71EB7001E90A8 /* RNSVGGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGGroup.m; path = Elements/RNSVGGroup.m; sourceTree = "<group>"; };
|
||||||
1039D2831CE71EB7001E90A8 /* RNSVGImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGImage.h; path = Elements/RNSVGImage.h; sourceTree = "<group>"; };
|
1039D2831CE71EB7001E90A8 /* RNSVGImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGImage.h; path = Elements/RNSVGImage.h; sourceTree = "<group>"; };
|
||||||
@@ -98,7 +98,6 @@
|
|||||||
1039D2881CE71EB7001E90A8 /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSvgView.m; path = Elements/RNSVGSvgView.m; sourceTree = "<group>"; };
|
1039D2881CE71EB7001E90A8 /* RNSVGSvgView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGSvgView.m; path = Elements/RNSVGSvgView.m; sourceTree = "<group>"; };
|
||||||
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGText.h; path = Text/RNSVGText.h; sourceTree = "<group>"; };
|
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGText.h; path = Text/RNSVGText.h; sourceTree = "<group>"; };
|
||||||
1039D2901CE71EC2001E90A8 /* RNSVGText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGText.m; path = Text/RNSVGText.m; sourceTree = "<group>"; };
|
1039D2901CE71EC2001E90A8 /* RNSVGText.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RNSVGText.m; path = Text/RNSVGText.m; sourceTree = "<group>"; };
|
||||||
1039D2911CE71EC2001E90A8 /* RNSVGTextFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGTextFrame.h; path = Text/RNSVGTextFrame.h; sourceTree = "<group>"; };
|
|
||||||
1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "RCTConvert+RNSVG.h"; path = "Utils/RCTConvert+RNSVG.h"; sourceTree = "<group>"; };
|
1039D29B1CE72177001E90A8 /* RCTConvert+RNSVG.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "RCTConvert+RNSVG.h"; path = "Utils/RCTConvert+RNSVG.h"; sourceTree = "<group>"; };
|
||||||
1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "RCTConvert+RNSVG.m"; path = "Utils/RCTConvert+RNSVG.m"; sourceTree = "<group>"; };
|
1039D29C1CE72177001E90A8 /* RCTConvert+RNSVG.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "RCTConvert+RNSVG.m"; path = "Utils/RCTConvert+RNSVG.m"; sourceTree = "<group>"; };
|
||||||
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGCGFloatArray.h; path = Utils/RNSVGCGFloatArray.h; sourceTree = "<group>"; };
|
1039D29E1CE72177001E90A8 /* RNSVGCGFloatArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RNSVGCGFloatArray.h; path = Utils/RNSVGCGFloatArray.h; sourceTree = "<group>"; };
|
||||||
@@ -298,8 +297,8 @@
|
|||||||
7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */,
|
7F08CE9D1E23479700650F83 /* RNSVGTextPath.m */,
|
||||||
7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */,
|
7F08CE9E1E23479700650F83 /* RNSVGTSpan.h */,
|
||||||
7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */,
|
7F08CE9F1E23479700650F83 /* RNSVGTSpan.m */,
|
||||||
103371331D41D3400028AF13 /* RNSVGBezierPath.h */,
|
103371331D41D3400028AF13 /* RNSVGBezierTransformer.h */,
|
||||||
103371311D41C5C90028AF13 /* RNSVGBezierPath.m */,
|
103371311D41C5C90028AF13 /* RNSVGBezierTransformer.m */,
|
||||||
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */,
|
1039D28F1CE71EC2001E90A8 /* RNSVGText.h */,
|
||||||
1039D2901CE71EC2001E90A8 /* RNSVGText.m */,
|
1039D2901CE71EC2001E90A8 /* RNSVGText.m */,
|
||||||
);
|
);
|
||||||
@@ -429,7 +428,7 @@
|
|||||||
10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */,
|
10BA0D3E1CE74E3100887C2B /* RNSVGSvgViewManager.m in Sources */,
|
||||||
0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */,
|
0CF68B0F1AF0549300FF9E5C /* RNSVGSolidColorBrush.m in Sources */,
|
||||||
10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */,
|
10BA0D3A1CE74E3100887C2B /* RNSVGPathManager.m in Sources */,
|
||||||
103371321D41C5C90028AF13 /* RNSVGBezierPath.m in Sources */,
|
103371321D41C5C90028AF13 /* RNSVGBezierTransformer.m in Sources */,
|
||||||
10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */,
|
10BA0D3C1CE74E3100887C2B /* RNSVGRenderableManager.m in Sources */,
|
||||||
10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */,
|
10BEC1BD1D3F66F500FDCB19 /* RNSVGRadialGradient.m in Sources */,
|
||||||
10BEC1C31D3F680F00FDCB19 /* RNSVGRadialGradientManager.m in Sources */,
|
10BEC1C31D3F680F00FDCB19 /* RNSVGRadialGradientManager.m in Sources */,
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
@interface RNSVGBezierPath : NSObject
|
@interface RNSVGBezierTransformer : NSObject
|
||||||
|
|
||||||
+ (BOOL) hasReachedEnd:(CGAffineTransform)transform;
|
+ (BOOL) hasReachedEnd:(CGAffineTransform)transform;
|
||||||
+ (BOOL) hasReachedStart:(CGAffineTransform) transform;
|
+ (BOOL) hasReachedStart:(CGAffineTransform) transform;
|
||||||
|
|
||||||
- (instancetype)initWithBezierCurvesAndStartOffset:(NSArray<NSArray *> *)bezierCurves startOffset:(CGFloat)startOffset;
|
- (instancetype)initWithBezierCurvesAndStartOffset:(NSArray<NSArray *> *)bezierCurves startOffset:(CGFloat)startOffset;
|
||||||
- (CGAffineTransform)transformAtDistance:(CGFloat)distance;
|
- (CGAffineTransform)getTransformAtDistance:(CGFloat)distance;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -10,11 +10,9 @@
|
|||||||
* based on CurvyText by iosptl: https://github.com/iosptl/ios7ptl/blob/master/ch21-Text/CurvyText/CurvyText/CurvyTextView.m
|
* based on CurvyText by iosptl: https://github.com/iosptl/ios7ptl/blob/master/ch21-Text/CurvyText/CurvyText/CurvyTextView.m
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "RNSVGBezierPath.h"
|
#import "RNSVGBezierTransformer.h"
|
||||||
#import <QuartzCore/QuartzCore.h>
|
|
||||||
#import <CoreText/CoreText.h>
|
|
||||||
|
|
||||||
@implementation RNSVGBezierPath
|
@implementation RNSVGBezierTransformer
|
||||||
{
|
{
|
||||||
NSArray<NSArray *> *_bezierCurves;
|
NSArray<NSArray *> *_bezierCurves;
|
||||||
int _currentBezierIndex;
|
int _currentBezierIndex;
|
||||||
@@ -123,7 +121,7 @@ static CGFloat calculateDistance(CGPoint a, CGPoint b) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (CGAffineTransform)transformAtDistance:(CGFloat)distance
|
- (CGAffineTransform)getTransformAtDistance:(CGFloat)distance
|
||||||
{
|
{
|
||||||
distance += _startOffset;
|
distance += _startOffset;
|
||||||
if (_reachedEnd) {
|
if (_reachedEnd) {
|
||||||
@@ -150,7 +148,7 @@ static CGFloat calculateDistance(CGPoint a, CGPoint b) {
|
|||||||
_lastPoint = _P0 = _P3;
|
_lastPoint = _P0 = _P3;
|
||||||
_lastRecord += _lastDistance;
|
_lastRecord += _lastDistance;
|
||||||
[self setControlPoints];
|
[self setControlPoints];
|
||||||
return [self transformAtDistance:distance - _startOffset];
|
return [self getTransformAtDistance:distance - _startOffset];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+34
-34
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
|
|
||||||
#import "RNSVGTSpan.h"
|
#import "RNSVGTSpan.h"
|
||||||
#import "RNSVGBezierPath.h"
|
#import "RNSVGBezierTransformer.h"
|
||||||
#import "RNSVGText.h"
|
#import "RNSVGText.h"
|
||||||
#import "RNSVGTextPath.h"
|
#import "RNSVGTextPath.h"
|
||||||
|
|
||||||
@implementation RNSVGTSpan
|
@implementation RNSVGTSpan
|
||||||
{
|
{
|
||||||
RNSVGBezierPath *_bezierPath;
|
RNSVGBezierTransformer *_bezierTransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderLayerTo:(CGContextRef)context
|
- (void)renderLayerTo:(CGContextRef)context
|
||||||
@@ -33,32 +33,32 @@
|
|||||||
return [self getGroupPath:context];
|
return [self getGroupPath:context];
|
||||||
}
|
}
|
||||||
[self setContextBoundingBox:CGContextGetClipBoundingBox(context)];
|
[self setContextBoundingBox:CGContextGetClipBoundingBox(context)];
|
||||||
|
|
||||||
[self initialTextPath];
|
[self initialTextPath];
|
||||||
CGMutablePathRef path = CGPathCreateMutable();
|
CGMutablePathRef path = CGPathCreateMutable();
|
||||||
|
|
||||||
if ([self.content isEqualToString:@""]) {
|
if ([self.content isEqualToString:@""]) {
|
||||||
RNSVGGlyphPoint computedPoint = [self getComputedGlyphPoint:0 glyphOffset:CGPointZero];
|
RNSVGGlyphPoint computedPoint = [self getComputedGlyphPoint:0 glyphOffset:CGPointZero];
|
||||||
[self getTextRoot].lastX = computedPoint.x;
|
[self getTextRoot].lastX = computedPoint.x;
|
||||||
[self getTextRoot].lastY = computedPoint.y;
|
[self getTextRoot].lastY = computedPoint.y;
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTFontRef font = [self getComputedFont];
|
CTFontRef font = [self getComputedFont];
|
||||||
// Create a dictionary for this font
|
// Create a dictionary for this font
|
||||||
CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{
|
CFDictionaryRef attributes = (__bridge CFDictionaryRef)@{
|
||||||
(NSString *)kCTFontAttributeName: (__bridge id)font,
|
(NSString *)kCTFontAttributeName: (__bridge id)font,
|
||||||
(NSString *)kCTForegroundColorFromContextAttributeName: @YES
|
(NSString *)kCTForegroundColorFromContextAttributeName: @YES
|
||||||
};
|
};
|
||||||
|
|
||||||
CFStringRef string = (__bridge CFStringRef)self.content;
|
CFStringRef string = (__bridge CFStringRef)self.content;
|
||||||
CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, string, attributes);
|
CFAttributedStringRef attrString = CFAttributedStringCreate(kCFAllocatorDefault, string, attributes);
|
||||||
CTLineRef line = CTLineCreateWithAttributedString(attrString);
|
CTLineRef line = CTLineCreateWithAttributedString(attrString);
|
||||||
|
|
||||||
CGMutablePathRef linePath = [self getLinePath:line];
|
CGMutablePathRef linePath = [self getLinePath:line];
|
||||||
CGAffineTransform offset = CGAffineTransformMakeTranslation(0, _bezierPath ? 0 : CTFontGetSize(font) * 1.1);
|
CGAffineTransform offset = CGAffineTransformMakeTranslation(0, _bezierTransformer ? 0 : CTFontGetSize(font) * 1.1);
|
||||||
CGPathAddPath(path, &offset, linePath);
|
CGPathAddPath(path, &offset, linePath);
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
CFRelease(attrString);
|
CFRelease(attrString);
|
||||||
CFRelease(line);
|
CFRelease(line);
|
||||||
@@ -71,81 +71,81 @@
|
|||||||
{
|
{
|
||||||
CGAffineTransform upsideDown = CGAffineTransformMakeScale(1.0, -1.0);
|
CGAffineTransform upsideDown = CGAffineTransformMakeScale(1.0, -1.0);
|
||||||
CGMutablePathRef path = CGPathCreateMutable();
|
CGMutablePathRef path = CGPathCreateMutable();
|
||||||
|
|
||||||
CFArrayRef glyphRuns = CTLineGetGlyphRuns(line);
|
CFArrayRef glyphRuns = CTLineGetGlyphRuns(line);
|
||||||
CTRunRef run = CFArrayGetValueAtIndex(glyphRuns, 0);
|
CTRunRef run = CFArrayGetValueAtIndex(glyphRuns, 0);
|
||||||
|
|
||||||
CFIndex runGlyphCount = CTRunGetGlyphCount(run);
|
CFIndex runGlyphCount = CTRunGetGlyphCount(run);
|
||||||
CGPoint positions[runGlyphCount];
|
CGPoint positions[runGlyphCount];
|
||||||
CGGlyph glyphs[runGlyphCount];
|
CGGlyph glyphs[runGlyphCount];
|
||||||
|
|
||||||
// Grab the glyphs, positions, and font
|
// Grab the glyphs, positions, and font
|
||||||
CTRunGetPositions(run, CFRangeMake(0, 0), positions);
|
CTRunGetPositions(run, CFRangeMake(0, 0), positions);
|
||||||
CTRunGetGlyphs(run, CFRangeMake(0, 0), glyphs);
|
CTRunGetGlyphs(run, CFRangeMake(0, 0), glyphs);
|
||||||
CFDictionaryRef attributes = CTRunGetAttributes(run);
|
CFDictionaryRef attributes = CTRunGetAttributes(run);
|
||||||
|
|
||||||
CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName);
|
CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName);
|
||||||
|
|
||||||
CGFloat lineStartX;
|
CGFloat lineStartX;
|
||||||
RNSVGGlyphPoint computedPoint;
|
RNSVGGlyphPoint computedPoint;
|
||||||
for(CFIndex i = 0; i < runGlyphCount; i++) {
|
for(CFIndex i = 0; i < runGlyphCount; i++) {
|
||||||
computedPoint = [self getComputedGlyphPoint:i glyphOffset:positions[i]];
|
computedPoint = [self getComputedGlyphPoint:i glyphOffset:positions[i]];
|
||||||
|
|
||||||
if (!i) {
|
if (!i) {
|
||||||
lineStartX = computedPoint.x;
|
lineStartX = computedPoint.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyphs[i], nil);
|
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyphs[i], nil);
|
||||||
|
|
||||||
CGAffineTransform textPathTransform = [self getTextPathTransform:computedPoint.x];
|
CGAffineTransform textPathTransform = [self getTextPathTransform:computedPoint.x];
|
||||||
|
|
||||||
if ([RNSVGBezierPath hasReachedEnd:textPathTransform]) {
|
if ([RNSVGBezierTransformer hasReachedEnd:textPathTransform]) {
|
||||||
break;
|
break;
|
||||||
} else if ([RNSVGBezierPath hasReachedStart:textPathTransform]) {
|
} else if ([RNSVGBezierTransformer hasReachedStart:textPathTransform]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAffineTransform transform;
|
CGAffineTransform transform;
|
||||||
|
|
||||||
if (_bezierPath) {
|
if (_bezierTransformer) {
|
||||||
textPathTransform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(0, computedPoint.y), textPathTransform);
|
textPathTransform = CGAffineTransformConcat(CGAffineTransformMakeTranslation(0, computedPoint.y), textPathTransform);
|
||||||
transform = CGAffineTransformScale(textPathTransform, 1.0, -1.0);
|
transform = CGAffineTransformScale(textPathTransform, 1.0, -1.0);
|
||||||
} else {
|
} else {
|
||||||
transform = CGAffineTransformTranslate(upsideDown, computedPoint.x, -computedPoint.y);
|
transform = CGAffineTransformTranslate(upsideDown, computedPoint.x, -computedPoint.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPathAddPath(path, &transform, letter);
|
CGPathAddPath(path, &transform, letter);
|
||||||
CGPathRelease(letter);
|
CGPathRelease(letter);
|
||||||
}
|
}
|
||||||
|
|
||||||
[self getTextRoot].lastX = computedPoint.x;
|
[self getTextRoot].lastX = computedPoint.x;
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)initialTextPath
|
- (void)initialTextPath
|
||||||
{
|
{
|
||||||
__block RNSVGBezierPath *bezierPath;
|
__block RNSVGBezierTransformer *bezierTransformer;
|
||||||
[self traverseTextSuperviews:^(__kindof RNSVGText *node) {
|
[self traverseTextSuperviews:^(__kindof RNSVGText *node) {
|
||||||
if ([node class] == [RNSVGTextPath class]) {
|
if ([node class] == [RNSVGTextPath class]) {
|
||||||
RNSVGTextPath *textPath = node;
|
RNSVGTextPath *textPath = node;
|
||||||
bezierPath = [node getBezierPath];
|
bezierTransformer = [node getBezierTransformer];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
_bezierPath = bezierPath;
|
_bezierTransformer = bezierTransformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGAffineTransform)getTextPathTransform:(CGFloat)distance
|
- (CGAffineTransform)getTextPathTransform:(CGFloat)distance
|
||||||
{
|
{
|
||||||
if (_bezierPath) {
|
if (_bezierTransformer) {
|
||||||
return [_bezierPath transformAtDistance:distance];
|
return [_bezierTransformer getTransformAtDistance:distance];
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGAffineTransformIdentity;
|
return CGAffineTransformIdentity;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,13 +9,13 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import <CoreText/CoreText.h>
|
#import <CoreText/CoreText.h>
|
||||||
#import "RNSVGText.h"
|
#import "RNSVGText.h"
|
||||||
#import "RNSVGBezierPath.h"
|
#import "RNSVGBezierTransformer.h"
|
||||||
|
|
||||||
@interface RNSVGTextPath : RNSVGText
|
@interface RNSVGTextPath : RNSVGText
|
||||||
|
|
||||||
@property (nonatomic, strong) NSString *href;
|
@property (nonatomic, strong) NSString *href;
|
||||||
@property (nonatomic, strong) NSString *startOffset;
|
@property (nonatomic, strong) NSString *startOffset;
|
||||||
|
|
||||||
- (RNSVGBezierPath *)getBezierPath;
|
- (RNSVGBezierTransformer *)getBezierTransformer;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#import "RNSVGTextPath.h"
|
#import "RNSVGTextPath.h"
|
||||||
#import "RNSVGBezierPath.h"
|
#import "RNSVGBezierTransformer.h"
|
||||||
|
|
||||||
@implementation RNSVGTextPath
|
@implementation RNSVGTextPath
|
||||||
|
|
||||||
@@ -23,19 +23,20 @@
|
|||||||
return [self getGroupPath:context];
|
return [self getGroupPath:context];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RNSVGBezierPath *)getBezierPath
|
- (RNSVGBezierTransformer *)getBezierTransformer
|
||||||
{
|
{
|
||||||
RNSVGSvgView *svg = [self getSvgView];
|
RNSVGSvgView *svg = [self getSvgView];
|
||||||
RNSVGNode *template = [svg getDefinedTemplate:self.href];
|
RNSVGNode *template = [svg getDefinedTemplate:self.href];
|
||||||
|
|
||||||
if ([template class] != [RNSVGPath class]) {
|
if ([template class] != [RNSVGPath class]) {
|
||||||
// warning about this.
|
// warning about this.
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
RNSVGPath *path = template;
|
RNSVGPath *path = template;
|
||||||
CGFloat startOffset = [self getWidthRelatedValue:self.startOffset];
|
CGFloat startOffset = [self getWidthRelatedValue:self.startOffset];
|
||||||
return [[RNSVGBezierPath alloc] initWithBezierCurvesAndStartOffset:[path getBezierCurves] startOffset:startOffset];
|
return [[RNSVGBezierTransformer alloc] initWithBezierCurvesAndStartOffset:[path getBezierCurves]
|
||||||
|
startOffset:startOffset];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user