2011-04-22 47 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本身也有一些令人讨厌的问题。