From 66241b7a25e4ccb4e93882686a89e9813c201cfd Mon Sep 17 00:00:00 2001 From: Mikael Sand Date: Sun, 10 Feb 2019 01:47:46 +0200 Subject: [PATCH] [iOS] Simplify text subtree advance calculation / anchor root resolution --- ios/Text/RNSVGGlyphContext.h | 1 + ios/Text/RNSVGGlyphContext.m | 3 +++ ios/Text/RNSVGText.m | 25 ++++++++++--------------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/ios/Text/RNSVGGlyphContext.h b/ios/Text/RNSVGGlyphContext.h index 723b12fc..de49110e 100644 --- a/ios/Text/RNSVGGlyphContext.h +++ b/ios/Text/RNSVGGlyphContext.h @@ -44,5 +44,6 @@ - (void)pushContext:(RNSVGGroup*)node font:(NSDictionary *)font; +- (NSArray*)getFontContext; @end diff --git a/ios/Text/RNSVGGlyphContext.m b/ios/Text/RNSVGGlyphContext.m index 93056dcd..43f30a12 100644 --- a/ios/Text/RNSVGGlyphContext.m +++ b/ios/Text/RNSVGGlyphContext.m @@ -107,6 +107,9 @@ @implementation RNSVGGlyphContext +- (NSArray*)getFontContext { + return mFontContext_; +} - (CTFontRef)getGlyphFont { diff --git a/ios/Text/RNSVGText.m b/ios/Text/RNSVGText.m index 94625158..48f52e97 100644 --- a/ios/Text/RNSVGText.m +++ b/ios/Text/RNSVGText.m @@ -253,24 +253,19 @@ - (RNSVGText*)getTextAnchorRoot { RNSVGGlyphContext* gc = [self.textRoot getGlyphContext]; - RNSVGFontData* font = [gc getFont]; - enum RNSVGTextAnchor textAnchor = font->textAnchor; - if (textAnchor == RNSVGTextAnchorStart) { - return self; - } + NSArray* font = [gc getFontContext]; + RNSVGText* node = self; UIView* parent = [self superview]; - if ([parent isKindOfClass:[RNSVGText class]]) { - RNSVGText *parentText = (RNSVGText*)parent; - RNSVGGlyphContext* gc = [parentText.textRoot getGlyphContext]; - RNSVGFontData* font = [gc getFont]; - enum RNSVGTextAnchor textAnchor = font->textAnchor; - if (textAnchor == RNSVGTextAnchorStart) { - return self; - } else { - return [parentText getTextAnchorRoot]; + for (NSInteger i = [font count] - 1; i >= 0; i--) { + RNSVGFontData* fontData = [font objectAtIndex:i]; + if (![parent isKindOfClass:[RNSVGText class]] || + fontData->textAnchor == RNSVGTextAnchorStart) { + return node; } + node = (RNSVGText*) parent; + parent = [node superview]; } - return self; + return node; } - (CGFloat)getSubtreeTextChunksTotalAdvance