5

フランス語の特定のアラビア語のパスを取得するにはどうすればよいですか? CTFontCreatePathForGlyph が CGPathRef のようになることがわかりましたが、それは text のアウトラインになります。

テキスト描画アニメーションを表示するには、この実際のテキスト パスが必要です。

助けてください

4

2 に答える 2

10

パスを 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);

これがパスの作成方法です。サンプル コードについては、このリンクを参照してください。このコードは、このサンプル プロジェクトの一部です。これがお役に立てば幸いです

于 2012-04-03T04:23:50.850 に答える