@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.32",
3
+ "version": "0.2.33",
4
4
  "description": "Generated Apple SDK bindings plus the macOS, iOS and tvOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -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. NSTextFieldCell.cellSizeForBounds:/sizeWithAttributes:
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
- // Use an actual NSTextFieldCell to measure: this is exactly what the
443
- // renderer's NSTextField uses to lay text out, so the size we report
444
- // here is the size AppKit will draw into — no off-by-side-bearing,
445
- // no kerning surprise, no device-metrics vs typographic gap. Sizing
446
- // against a fresh cell of size (maxWidth, large) returns the wrapped
447
- // height + the actual line width AppKit needs.
448
- NSTextFieldCell *cell = [[NSTextFieldCell alloc] init];
449
- cell.bezeled = NO;
450
- cell.bordered = NO;
451
- cell.drawsBackground = NO;
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