gpt4 book ai didi

iphone - 来自字符串的 CGPathRef

转载 作者:可可西里 更新时间:2023-11-01 05:04:50 37 4
gpt4 key购买 nike

请问我们怎样才能得到法语字母的特定阿拉伯语路径?我刚刚发现 CTFontCreatePathForGlyph 会给 CGPathRef 之类的,但它会是文本的轮廓。

我需要这个真实的文本路径来显示文本绘图动画..

请帮忙

最佳答案

您根本不需要将您的路径转换为 ​​NSString。

您可以按如下方式创建文本路径:

    CTFontRef font = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 72.0f, NULL);
NSDictionary *attrs = [NSDictionary dictionaryWithObjectsAndKeys:
(id)font, kCTFontAttributeName,
nil];
NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"Hello World!"
attributes:attrs];
CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)attrString);
CFArrayRef runArray = CTLineGetGlyphRuns(line);

// for each RUN
for (CFIndex runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++)
{
// Get FONT for this run
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runArray, runIndex);
CTFontRef runFont = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName);

// for each GLYPH in run
for (CFIndex runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++)
{
// get Glyph & Glyph-data
CFRange thisGlyphRange = CFRangeMake(runGlyphIndex, 1);
CGGlyph glyph;
CGPoint position;
CTRunGetGlyphs(run, thisGlyphRange, &glyph);
CTRunGetPositions(run, thisGlyphRange, &position);

// Get PATH of outline
{
CGPathRef letter = CTFontCreatePathForGlyph(runFont, glyph, NULL);
CGAffineTransform t = CGAffineTransformMakeTranslation(position.x, position.y);
CGPathAddPath(letters, &t, letter);
CGPathRelease(letter);
}
}
}
CFRelease(line);

这是创建路径的方式,示例代码请引用this link .此代码是此示例项目的一部分。希望对你有帮助

关于iphone - 来自字符串的 CGPathRef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9976454/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com