Finish TextPath

Finish TextPath step two: add `dy` support
This commit is contained in:
Horcrux
2017-01-09 20:48:33 +08:00
parent 52dfe21074
commit 84ea887a06
2 changed files with 14 additions and 11 deletions

View File

@@ -86,36 +86,36 @@
CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName); CTFontRef runFont = CFDictionaryGetValue(attributes, kCTFontAttributeName);
CGFloat lineStartX; CGFloat lineStartX;
CGFloat lastX; RNSVGGlyphPoint computedPoint;
for(CFIndex i = 0; i < runGlyphCount; i++) { for(CFIndex i = 0; i < runGlyphCount; i++) {
RNSVGGlyphPoint computedPoint = [self getComputedGlyphPoint:i glyphOffset:positions[i]]; computedPoint = [self getComputedGlyphPoint:i glyphOffset:positions[i]];
if (!i) { if (!i) {
lineStartX = computedPoint.x; lineStartX = computedPoint.x;
lastX = lineStartX;
} }
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyphs[i], nil);
CGAffineTransform textPathTransform = [self getTextPathTransform:computedPoint.x]; CGAffineTransform textPathTransform = [self getTextPathTransform:computedPoint.x];
if (!textPathTransform.a || !textPathTransform.d) { if (!textPathTransform.a || !textPathTransform.d) {
return path; break;
} }
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyphs[i], nil);
CGAffineTransform transform; CGAffineTransform transform;
if (_bezierPath) { if (_bezierPath) {
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);
lastX += CGPathGetBoundingBox(letter).size.width;
CGPathRelease(letter); CGPathRelease(letter);
} }
[self getTextRoot].lastX = lastX; [self getTextRoot].lastX = computedPoint.x;
return path; return path;
} }

View File

@@ -8,8 +8,7 @@ const fontRegExp = /^\s*((?:(?:normal|bold|italic)\s+)*)(?:(\d+(?:\.\d+)?)[ptexm
const fontFamilyPrefix = /^[\s"']*/; const fontFamilyPrefix = /^[\s"']*/;
const fontFamilySuffix = /[\s"']*$/; const fontFamilySuffix = /[\s"']*$/;
const spaceReg = /\s+/; const spaceReg = /\s+/;
const deltaReg = /^((-?\d*(\.\d+)?)+\s*)+$/; const commaReg = /,/g;
const commaReg = /,/;
const anchors = { const anchors = {
auto: 0, auto: 0,
@@ -70,8 +69,12 @@ function extractFont(props) {
} }
function parseDelta(delta) { function parseDelta(delta) {
if (typeof delta === 'string' && deltaReg.test(delta)) { if (typeof delta === 'string') {
return delta.trim().split(spaceReg).map(d => +d); if (isNaN(+delta)) {
return delta.trim().replace(commaReg, ' ').split(spaceReg).map(d => +d || 0);
} else {
return [+delta];
}
} else if (typeof delta === 'number') { } else if (typeof delta === 'number') {
return [delta]; return [delta];
} else { } else {