2012-04-02 33 views
4

請問我們如何才能獲得法文字母的特定阿拉伯文路徑?我剛剛發現CTFontCreatePathForGlyph會給CGPathRef一樣,但它將成爲文本的輪廓。CGPathRef字符串

我需要這個真正的文本路徑顯示文本繪製動畫..

任何幫助,請

+0

爲什麼你想要將路徑轉換爲字符串? U可以直接在返回的路徑上動畫任務:) – DivineDesert 2012-04-02 13:01:02

+0

我不會轉換我想要獲取特定字符串的路徑我的對象是使我的項目學校的應用程序像信函學校或我writeword – 2012-04-02 13:20:56

+0

來解釋外觀在這個應用程序http://letterschool.com/我想同樣的想法,因爲他們這樣寫信「對不起,我的牀英語」 – 2012-04-02 13:50:36

回答

10

你不要求UR路徑將被轉換成的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。此代碼是此示例項目的一部分。 希望這可以幫到你

+0

謝謝:)但使用這種方法,我們將得到大綱路徑。 – 2012-04-05 13:18:13

+0

雅我知道..但這是你完成工作的方式。顯然你需要改變代碼來完成你的要求。 – DivineDesert 2012-04-06 04:09:57

+0

我怎麼能改變它得到正確的結果例如字母A與你的方法是由12lines組成,但在實際上是3lines對不起我的壞英語 – 2012-04-08 02:56:38