iphone - 来自字符串的 CGPathRef

标签 iphone objective-c ios core-text cgpath

请问我们怎样才能得到法语字母的特定阿拉伯语路径?我刚刚发现 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/

相关文章:

iphone - UIScrollView 不响应 setZoomScale :

iphone - 在 UITableView 的完成按钮上隐藏 UIPickerview

iphone - 带有内容矩形抖动的核心动画

iPhone Twitter SDK 与 iOS 5 设备的集成问题

ios - 如何将 iOS 模拟器设置为 iPhone 6 和 iPhone 6 Plus 屏幕分辨率?

ios - 声明数组 : compiler is unable to type-check . 时出现编译器错误 .. 不同的子表达式

iphone - Cordova - 内部超链接始终在 Safari 中打开

Objective-C:将 int 返回到 BOOL 方法

ios - 加载 View Controller 而不显示 Nib

iphone - 如何解决通过 iPhone 模拟器 5.1 将文本发布到 Facebook 的共享工具包问题