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];
...
}
的问题是:是否有可能加快考虑到字符串并不需要绘制的计算?我只对矩形的宽度和高度感兴趣。