2011-04-22 68 views
0

我有大量的唯一字符串,我想計算它們的邊界矩形時,他們將被放置在一個無限大矩形。目前我使用一個單一的NSTextStorage/NSLayoutManager和遍歷所有字符串,收集矩形:使用NSLayoutManager獲取字符串的邊界矩形

// setup NSTextStorage and its NSLayoutManager, NSTextContainer 
... 

forall (NSAttributedString *astring in ...) 
{ 
    // put string into textstorage 
    [textStorage setAttributedString:astring]; 

    // trigger glyph generation and layout 
    [textContainer setContainerSize: NSMakeSize (CGFLOAT_MAX, CGFLOAT_MAX)]; 
    [layoutManager ensureLayoutForTextContainer: textContainer]; 

    // finally get the bounding box 
    NSRect boundingBox = [layoutManager usedRectForTextContainer: textContainer]; 
    ... 
} 

的問題是:是否有可能加快考慮到字符串並不需要繪製的計算?我只對矩形的寬度和高度感興趣。

回答

0

Jut在幾天的測試後回答這個問題:不,不幸的是,使用佈局管理器沒有更快的方法。使用CoreText的速度似乎快了一倍,但CoreText本身也有一些令人討厭的問題。