@windowkit/appkit 0.14.1 → 0.15.0

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/README.md CHANGED
@@ -531,6 +531,17 @@ const label = native.createLayout({
531
531
  });
532
532
  ```
533
533
 
534
+ ## Text: where a line's glyphs sit
535
+
536
+ `createLayout`'s `lineHeight` is a multiplier over each line's natural height — its
537
+ ascent, descent and the face's line gap — and a line's box is that tall. Whatever the box
538
+ has beyond the glyphs' ascent and descent is split evenly above and below them: each line's
539
+ `baseline` is its `y`, plus half that leading, plus its `ascent`. That is CSS's
540
+ half-leading, and it is ntk's, the engine react-x11 draws text with on X11 and Wayland, so
541
+ one tree sets its text in the same place on both. Below 1 the same split takes room from
542
+ both sides and the glyphs overflow a short box evenly; `0` is a box of no height, as CSS's
543
+ `line-height: 0` is. An absent multiplier is 1.
544
+
534
545
  ## Text: a layout's coverage
535
546
 
536
547
  - **`native.layoutCoverage(layout, pad?)`** — `{ width, height, data }`: how much of each
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windowkit/appkit",
3
- "version": "0.14.1",
3
+ "version": "0.15.0",
4
4
  "description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
5
5
  "author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
6
6
  "license": "MIT",
@@ -43,7 +43,7 @@
43
43
  "install": "node scripts/install.js",
44
44
  "build": "node-gyp rebuild",
45
45
  "demo": "node demo/demo.js",
46
- "test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
46
+ "test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/surface-blit.js && node test/text-features.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js"
47
47
  },
48
48
  "dependencies": {
49
49
  "node-addon-api": "^8.3.0"
Binary file
package/src/backend.mm CHANGED
@@ -5115,7 +5115,11 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5115
5115
  double maxWidth = BNumOr(o, "maxWidth", 0);
5116
5116
  bool bounded = maxWidth > 0 && std::isfinite(maxWidth);
5117
5117
  double flush = BNumOr(o, "align", 0);
5118
- double lineHeight = BNumOr(o, "lineHeight", 0);
5118
+ // A multiplier over each line's natural height, as ntk's is: absent is 1,
5119
+ // and 0 is a line box of no height — CSS's `line-height: 0`, which the
5120
+ // glyphs overflow evenly — not an option left unset.
5121
+ double lineHeight = BNumOr(o, "lineHeight", 1);
5122
+ if (!(lineHeight >= 0)) lineHeight = 1;
5119
5123
  long maxLines = (long)BNumOr(o, "maxLines", 0);
5120
5124
  bool ellipsis = BBoolOr(o, "ellipsis", false);
5121
5125
  bool rtl = BBoolOr(o, "rtl", false);
@@ -5180,8 +5184,22 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5180
5184
  }
5181
5185
  CGFloat ascent = 0, descent = 0, leading = 0;
5182
5186
  double lw = CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
5187
+ // A line is as wide as its ink, as ntk measures it: the white space it
5188
+ // ends on hangs past it. CoreText counts that space in, so a paragraph
5189
+ // ending in one measured a space wider here than on X11 — and a box
5190
+ // sized to it grew by one — and every wrapped line counted the space
5191
+ // it broke at. Flush alignment already leaves it out.
5192
+ lw -= CTLineGetTrailingWhitespaceWidth(line);
5183
5193
  double natural = ascent + descent + leading;
5184
- double advance = natural * (lineHeight > 0 ? lineHeight : 1);
5194
+ double advance = natural * lineHeight;
5195
+ // Half-leading, where ntk and CSS put a line's glyphs: whatever the
5196
+ // line box has beyond their ascent and descent — the font's own line
5197
+ // gap, and what the multiplier adds or takes away — is split evenly
5198
+ // above and below them. It all went under the text here, so a
5199
+ // paragraph set at 1.5 sat at the top of its lines on this backend and
5200
+ // in their middle on X11, and a line shorter than its glyphs
5201
+ // overflowed downwards only.
5202
+ double halfLeading = (advance - (ascent + descent)) / 2;
5185
5203
  CALLine L;
5186
5204
  L.line = line;
5187
5205
  L.width = lw;
@@ -5189,7 +5207,7 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5189
5207
  L.ascent = ascent;
5190
5208
  L.descent = descent;
5191
5209
  L.y = y;
5192
- L.baseline = y + ascent;
5210
+ L.baseline = y + halfLeading + ascent;
5193
5211
  L.start = start;
5194
5212
  L.end = lineEnd;
5195
5213
  if (lineEnd > start) {