mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-01 06:07:41 +00:00
Port new GlyphContext, FontData, enums, props, Bezier and text rendering
This commit is contained in:
+28
-53
@@ -11,17 +11,13 @@
|
||||
#import <React/RCTFont.h>
|
||||
#import <CoreText/CoreText.h>
|
||||
#import "RNSVGGlyphContext.h"
|
||||
#import "GlyphContext.h"
|
||||
|
||||
@implementation RNSVGText
|
||||
{
|
||||
RNSVGText *_textRoot;
|
||||
RNSVGGlyphContext *_glyphContext;
|
||||
}
|
||||
|
||||
- (void)setTextAnchor:(RNSVGTextAnchor)textAnchor
|
||||
{
|
||||
[self invalidate];
|
||||
_textAnchor = textAnchor;
|
||||
GlyphContext *_glyphContext;
|
||||
RNSVGGlyphContext *_RNSVGGlyphContext;
|
||||
}
|
||||
|
||||
- (void)renderLayerTo:(CGContextRef)context
|
||||
@@ -31,21 +27,20 @@
|
||||
[self setupGlyphContext:context];
|
||||
|
||||
CGPathRef path = [self getGroupPath:context];
|
||||
CGAffineTransform transform = [self getAlignTransform:path];
|
||||
CGContextConcatCTM(context, transform);
|
||||
[self renderGroupTo:context];
|
||||
[self releaseCachedPath];
|
||||
CGContextRestoreGState(context);
|
||||
|
||||
|
||||
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &transform);
|
||||
CGPathRef transformedPath = CGPathCreateCopyByTransformingPath(path, &CGAffineTransformIdentity);
|
||||
[self setHitArea:transformedPath];
|
||||
CGPathRelease(transformedPath);
|
||||
}
|
||||
|
||||
- (void)setupGlyphContext:(CGContextRef)context
|
||||
{
|
||||
_glyphContext = [[RNSVGGlyphContext alloc] initWithDimensions:[self getContextWidth]
|
||||
_glyphContext = [[GlyphContext alloc] initWithScale:1 width:[self getContextWidth]
|
||||
height:[self getContextHeight]];
|
||||
_RNSVGGlyphContext = [[RNSVGGlyphContext alloc] initWithDimensions:[self getContextWidth]
|
||||
height:[self getContextHeight]];
|
||||
}
|
||||
|
||||
@@ -72,10 +67,9 @@
|
||||
{
|
||||
[self setupGlyphContext:context];
|
||||
CGPathRef groupPath = [self getGroupPath:context];
|
||||
CGAffineTransform transform = [self getAlignTransform:groupPath];
|
||||
[self releaseCachedPath];
|
||||
|
||||
return (CGPathRef)CFAutorelease(CGPathCreateCopyByTransformingPath(groupPath, &transform));
|
||||
return (CGPathRef)CFAutorelease(CGPathCreateCopyByTransformingPath(groupPath, &CGAffineTransformIdentity));
|
||||
}
|
||||
|
||||
- (void)renderGroupTo:(CGContextRef)context
|
||||
@@ -85,38 +79,6 @@
|
||||
[self popGlyphContext];
|
||||
}
|
||||
|
||||
- (CGAffineTransform)getAlignTransform:(CGPathRef)path
|
||||
{
|
||||
CGFloat width = CGRectGetWidth(CGPathGetBoundingBox(path));
|
||||
CGFloat x = 0;
|
||||
|
||||
switch ([self getComputedTextAnchor]) {
|
||||
case kRNSVGTextAnchorMiddle:
|
||||
x = -width / 2;
|
||||
break;
|
||||
case kRNSVGTextAnchorEnd:
|
||||
x = -width;
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
|
||||
return CGAffineTransformMakeTranslation(x, 0);
|
||||
}
|
||||
|
||||
- (RNSVGTextAnchor)getComputedTextAnchor
|
||||
{
|
||||
RNSVGTextAnchor anchor = self.textAnchor;
|
||||
if (self.subviews.count > 0) {
|
||||
RNSVGText *child = [self.subviews firstObject];
|
||||
|
||||
while (child.subviews.count && anchor == kRNSVGTextAnchorAuto) {
|
||||
anchor = child.textAnchor;
|
||||
child = [child.subviews firstObject];
|
||||
}
|
||||
}
|
||||
return anchor;
|
||||
}
|
||||
|
||||
- (RNSVGText *)getTextRoot
|
||||
{
|
||||
if (!_textRoot) {
|
||||
@@ -133,18 +95,31 @@
|
||||
return _textRoot;
|
||||
}
|
||||
|
||||
- (RNSVGGlyphContext *)getGlyphContext
|
||||
- (RNSVGGlyphContext *)getRNSVGGlyphContext
|
||||
{
|
||||
return _RNSVGGlyphContext;
|
||||
}
|
||||
|
||||
- (GlyphContext *)getGlyphContext
|
||||
{
|
||||
return _glyphContext;
|
||||
}
|
||||
|
||||
- (void)pushGlyphContext
|
||||
{
|
||||
[[[self getTextRoot] getGlyphContext] pushContext:self.font
|
||||
deltaX:self.deltaX
|
||||
deltaY:self.deltaY
|
||||
positionX:self.positionX
|
||||
positionY:self.positionY];
|
||||
[[[self getTextRoot] getRNSVGGlyphContext] pushContext:self.font
|
||||
deltaX:self.deltaX
|
||||
deltaY:self.deltaY
|
||||
positionX:self.positionX
|
||||
positionY:self.positionY];
|
||||
[[[self getTextRoot] getGlyphContext] pushContextwithRNSVGText:self
|
||||
reset:false
|
||||
font:self.font
|
||||
x:self.positionX
|
||||
y:self.positionY
|
||||
deltaX:self.deltaX
|
||||
deltaY:self.deltaY
|
||||
rotate:self.rotate];
|
||||
}
|
||||
|
||||
- (void)popGlyphContext
|
||||
@@ -159,7 +134,7 @@
|
||||
|
||||
- (CGPoint)getGlyphPointFromContext:(CGPoint)offset glyphWidth:(CGFloat)glyphWidth
|
||||
{
|
||||
return [[[self getTextRoot] getGlyphContext] getNextGlyphPoint:(CGPoint)offset glyphWidth:glyphWidth];
|
||||
return [[[self getTextRoot] getRNSVGGlyphContext] getNextGlyphPoint:(CGPoint)offset glyphWidth:glyphWidth];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user