@windowkit/appkit 0.15.0 → 0.15.1
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": "@windowkit/appkit",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.1",
|
|
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",
|
|
Binary file
|
|
Binary file
|
package/src/backend.mm
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
#include <string>
|
|
33
33
|
#include <unordered_map>
|
|
34
34
|
#include <vector>
|
|
35
|
+
#include <vector>
|
|
35
36
|
|
|
36
37
|
#include "channel.h"
|
|
37
38
|
|
|
@@ -5091,6 +5092,41 @@ static Napi::Value ReleaseTypesetter(const Napi::CallbackInfo& info) {
|
|
|
5091
5092
|
return env.Undefined();
|
|
5092
5093
|
}
|
|
5093
5094
|
|
|
5095
|
+
// The advance of the spaces, tabs and line breaks a line ends on — what
|
|
5096
|
+
// hangs past it, as ntk and CSS hang white space. CTLineGetTrailingWhitespace
|
|
5097
|
+
// Width counts everything CoreText calls white space, the no-break space
|
|
5098
|
+
// among it, where CSS measures a no-break space wherever it stands: ` `
|
|
5099
|
+
// at the end of a cell or a span is there to take room. So the run is found
|
|
5100
|
+
// in the text, and its glyphs' advances summed, whichever way the line reads.
|
|
5101
|
+
static double HangingWhitespaceWidth(CTLineRef line, NSString* text,
|
|
5102
|
+
long start, long end) {
|
|
5103
|
+
long hang = end;
|
|
5104
|
+
while (hang > start) {
|
|
5105
|
+
unichar c = [text characterAtIndex:(NSUInteger)(hang - 1)];
|
|
5106
|
+
if (c != ' ' && c != '\t' && c != '\n' && c != '\r' && c != 0x2028 &&
|
|
5107
|
+
c != 0x2029)
|
|
5108
|
+
break;
|
|
5109
|
+
hang--;
|
|
5110
|
+
}
|
|
5111
|
+
if (hang == end) return 0;
|
|
5112
|
+
double width = 0;
|
|
5113
|
+
CFArrayRef runs = CTLineGetGlyphRuns(line);
|
|
5114
|
+
CFIndex n = CFArrayGetCount(runs);
|
|
5115
|
+
for (CFIndex i = 0; i < n; i++) {
|
|
5116
|
+
CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex(runs, i);
|
|
5117
|
+
CFIndex count = CTRunGetGlyphCount(run);
|
|
5118
|
+
if (count <= 0) continue;
|
|
5119
|
+
std::vector<CGSize> advances((size_t)count);
|
|
5120
|
+
std::vector<CFIndex> indices((size_t)count);
|
|
5121
|
+
CTRunGetAdvances(run, CFRangeMake(0, 0), advances.data());
|
|
5122
|
+
CTRunGetStringIndices(run, CFRangeMake(0, 0), indices.data());
|
|
5123
|
+
for (CFIndex g = 0; g < count; g++) {
|
|
5124
|
+
if (indices[g] >= hang && indices[g] < end) width += advances[g].width;
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
return width;
|
|
5128
|
+
}
|
|
5129
|
+
|
|
5094
5130
|
// createLayout({ spans: [{text, font (handle), color:[r,g,b,a]}],
|
|
5095
5131
|
// maxWidth?, align: 0 left | 0.5 center | 1 right,
|
|
5096
5132
|
// lineHeight?, maxLines?, ellipsis?, rtl?,
|
|
@@ -5161,7 +5197,9 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
|
|
|
5161
5197
|
bool more = start + count < total;
|
|
5162
5198
|
CTLineRef line = nullptr;
|
|
5163
5199
|
long lineEnd = start + count;
|
|
5200
|
+
bool elided = false;
|
|
5164
5201
|
if (lastAllowed && more && ellipsis && lastAttrs) {
|
|
5202
|
+
elided = true;
|
|
5165
5203
|
// shape the whole remainder, then truncate it into the width
|
|
5166
5204
|
CTLineRef whole =
|
|
5167
5205
|
CTTypesetterCreateLine(ts, CFRangeMake(start, total - start));
|
|
@@ -5188,8 +5226,10 @@ static Napi::Value CreateLayout(const Napi::CallbackInfo& info) {
|
|
|
5188
5226
|
// ends on hangs past it. CoreText counts that space in, so a paragraph
|
|
5189
5227
|
// ending in one measured a space wider here than on X11 — and a box
|
|
5190
5228
|
// sized to it grew by one — and every wrapped line counted the space
|
|
5191
|
-
// it broke at. Flush alignment already leaves it out.
|
|
5192
|
-
|
|
5229
|
+
// it broke at. Flush alignment already leaves it out. An elided line
|
|
5230
|
+
// ends on its ellipsis, whose glyph is no part of the text.
|
|
5231
|
+
lw -= elided ? CTLineGetTrailingWhitespaceWidth(line)
|
|
5232
|
+
: HangingWhitespaceWidth(line, as.string, start, lineEnd);
|
|
5193
5233
|
double natural = ascent + descent + leading;
|
|
5194
5234
|
double advance = natural * lineHeight;
|
|
5195
5235
|
// Half-leading, where ntk and CSS put a line's glyphs: whatever the
|