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];
...
}
的問題是:是否有可能加快考慮到字符串並不需要繪製的計算?我只對矩形的寬度和高度感興趣。