@windowkit/appkit 0.14.0 → 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
@@ -222,6 +222,13 @@ nothing. While `runMain` runs, `listScreens`, `accessibilityDisplayOptions` and
222
222
  `pasteboardChangeCount` answer from it when called off the main thread. On the main
223
223
  thread they still ask AppKit live, as in pump mode.
224
224
 
225
+ A copy that changes with no event after it is a renderer left waiting, so `showWindow`
226
+ sends `window-shown { handle }` once the window is on screen and published. AppKit's own
227
+ notifications usually say as much, since the window moves as it is ordered in, but a
228
+ window taller than its screen is constrained, resized and moved before it is visible, and
229
+ nothing after that says it is shown. A worker that holds the frames of a window it cannot
230
+ see waited on that window for good.
231
+
225
232
  **Exit and signals.** Before the run stops, menu tracking is cancelled and an app-modal
226
233
  loop stopped, since `[NSApp stop:]` only ends the innermost loop. A drag session or a live
227
234
  resize cannot be ended from code, so the exit waits for the button to come up. While the run lasts,
@@ -524,6 +531,17 @@ const label = native.createLayout({
524
531
  });
525
532
  ```
526
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
+
527
545
  ## Text: a layout's coverage
528
546
 
529
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.0",
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
@@ -1054,6 +1054,15 @@ static double BNumArg(const Napi::CallbackInfo& info, size_t i) {
1054
1054
  }
1055
1055
 
1056
1056
  // showWindow(win, activate) — map. Popups order front without activating.
1057
+ //
1058
+ // Then `window-shown`, once the window is on screen and published: a worker
1059
+ // reads a window's visibility from what was published last, and defers the
1060
+ // frames of a window it cannot see until an event says otherwise. The event
1061
+ // that usually says so is AppKit's own — the move that follows ordering the
1062
+ // window in — but a window AppKit constrains to the screen is resized and
1063
+ // moved while it is still being ordered in, before it is visible, and
1064
+ // nothing follows. Its frames waited for good, and a `<glarea>` in it never
1065
+ // drew a frame.
1057
1066
  static Napi::Value ShowWindowFn(const Napi::CallbackInfo& info) {
1058
1067
  bool activate = info.Length() > 1 && info[1].ToBoolean().Value();
1059
1068
  OnWindow(info[0], ^(NSWindow* win) {
@@ -1064,6 +1073,7 @@ static Napi::Value ShowWindowFn(const Napi::CallbackInfo& info) {
1064
1073
  [win orderFrontRegardless];
1065
1074
  }
1066
1075
  PublishWindow(win);
1076
+ CALEmit(WindowEvent(win, "window-shown"));
1067
1077
  });
1068
1078
  return info.Env().Undefined();
1069
1079
  }
@@ -5105,7 +5115,11 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5105
5115
  double maxWidth = BNumOr(o, "maxWidth", 0);
5106
5116
  bool bounded = maxWidth > 0 && std::isfinite(maxWidth);
5107
5117
  double flush = BNumOr(o, "align", 0);
5108
- 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;
5109
5123
  long maxLines = (long)BNumOr(o, "maxLines", 0);
5110
5124
  bool ellipsis = BBoolOr(o, "ellipsis", false);
5111
5125
  bool rtl = BBoolOr(o, "rtl", false);
@@ -5170,8 +5184,22 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5170
5184
  }
5171
5185
  CGFloat ascent = 0, descent = 0, leading = 0;
5172
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);
5173
5193
  double natural = ascent + descent + leading;
5174
- 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;
5175
5203
  CALLine L;
5176
5204
  L.line = line;
5177
5205
  L.width = lw;
@@ -5179,7 +5207,7 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
5179
5207
  L.ascent = ascent;
5180
5208
  L.descent = descent;
5181
5209
  L.y = y;
5182
- L.baseline = y + ascent;
5210
+ L.baseline = y + halfLeading + ascent;
5183
5211
  L.start = start;
5184
5212
  L.end = lineEnd;
5185
5213
  if (lineEnd > start) {