@geastack/apple 0.2.32 → 0.2.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -400,7 +400,7 @@ static bool measureNativeText(const char *text,
|
|
|
400
400
|
|
|
401
401
|
// Memoize by (text, maxWidth, fontId, fontSize): the layout engine re-measures
|
|
402
402
|
// EVERY text node on EVERY layout pass, and a pass now runs on every
|
|
403
|
-
// interaction.
|
|
403
|
+
// interaction. NSAttributedString boundingRectWithSize:/sizeWithAttributes:
|
|
404
404
|
// dominated the interaction profile; the inputs fully determine the result,
|
|
405
405
|
// so a cache turns repeat measurements (the stable note list) into O(1).
|
|
406
406
|
static std::mutex measureLock;
|
|
@@ -439,21 +439,16 @@ static bool measureNativeText(const char *text,
|
|
|
439
439
|
NSParagraphStyleAttributeName: paragraph,
|
|
440
440
|
};
|
|
441
441
|
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:str attributes:attrs];
|
|
442
|
-
//
|
|
443
|
-
//
|
|
444
|
-
//
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
//
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
cell.wraps = YES;
|
|
453
|
-
cell.attributedStringValue = attributed;
|
|
454
|
-
const NSSize cellSize = [cell cellSizeForBounds:NSMakeRect(0, 0, boundedMax, CGFLOAT_MAX)];
|
|
455
|
-
*outWidth = static_cast<int>(std::ceil(cellSize.width));
|
|
456
|
-
*outHeight = static_cast<int>(std::ceil(cellSize.height));
|
|
442
|
+
// Measure with the exact call the renderer draws with: GeaTextCell's
|
|
443
|
+
// drawInteriorWithFrame: draws the attributed string with
|
|
444
|
+
// drawWithRect:options: (line-fragment origin, font leading) and no cell
|
|
445
|
+
// padding. NSTextFieldCell's cellSizeForBounds: adds its own inset (4px
|
|
446
|
+
// wide, 1px tall at 11px) that the drawing never uses, so centered text
|
|
447
|
+
// landed 2px left of its box's center.
|
|
448
|
+
const NSRect used = [attributed boundingRectWithSize:NSMakeSize(boundedMax, CGFLOAT_MAX)
|
|
449
|
+
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading];
|
|
450
|
+
*outWidth = static_cast<int>(std::ceil(used.size.width));
|
|
451
|
+
*outHeight = static_cast<int>(std::ceil(used.size.height));
|
|
457
452
|
{
|
|
458
453
|
std::scoped_lock guard(measureLock);
|
|
459
454
|
if (measureCache.size() > 8192) measureCache.clear(); // bound unbounded growth
|