drawnui-react 0.1.0-preview.3 → 0.1.0-preview.31
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 +15 -1
- package/SKIPPED.md +32 -25
- package/dist/controls/AnimatedFramesRenderer.d.ts +7 -0
- package/dist/controls/AnimatedFramesRenderer.js +16 -1
- package/dist/controls/DrawnGame.d.ts +40 -0
- package/dist/controls/DrawnGame.js +64 -0
- package/dist/controls/GridStructure.d.ts +16 -2
- package/dist/controls/GridStructure.js +40 -4
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +15 -1
- package/dist/controls/SkiaButton.js +21 -4
- package/dist/controls/SkiaCarousel.d.ts +21 -2
- package/dist/controls/SkiaCarousel.js +49 -5
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +0 -6
- package/dist/controls/SkiaDrawer.d.ts +2 -0
- package/dist/controls/SkiaDrawer.js +2 -0
- package/dist/controls/SkiaEditor.d.ts +38 -1
- package/dist/controls/SkiaEditor.js +223 -49
- package/dist/controls/SkiaGif.d.ts +3 -0
- package/dist/controls/SkiaGif.js +12 -2
- package/dist/controls/SkiaImage.js +15 -10
- package/dist/controls/SkiaLabel.d.ts +91 -7
- package/dist/controls/SkiaLabel.js +420 -71
- package/dist/controls/SkiaLabelFps.d.ts +16 -0
- package/dist/controls/SkiaLabelFps.js +41 -0
- package/dist/controls/SkiaLayout.d.ts +97 -9
- package/dist/controls/SkiaLayout.js +387 -22
- package/dist/controls/SkiaLottie.js +4 -2
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +6 -3
- package/dist/controls/SkiaRadioButton.js +4 -3
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +35 -5
- package/dist/controls/SkiaScroll.js +234 -23
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +5 -0
- package/dist/controls/SkiaShaderCarousel.js +5 -0
- package/dist/controls/SkiaShape.d.ts +13 -2
- package/dist/controls/SkiaShape.js +50 -10
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +59 -5
- package/dist/controls/SkiaSprite.d.ts +1 -0
- package/dist/controls/SkiaSprite.js +4 -0
- package/dist/controls/SkiaSvg.js +1 -1
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +0 -6
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +19 -1
- package/dist/core/Accessibility.d.ts +80 -0
- package/dist/core/Accessibility.js +421 -8
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +108 -7
- package/dist/core/Canvas.js +353 -29
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +34 -2
- package/dist/core/Gestures.js +84 -3
- package/dist/core/Hover.d.ts +47 -0
- package/dist/core/Hover.js +134 -0
- package/dist/core/KeyboardManager.d.ts +13 -0
- package/dist/core/KeyboardManager.js +18 -0
- package/dist/core/ScrollAnimators.js +9 -0
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +209 -9
- package/dist/core/SkiaControl.js +500 -59
- package/dist/core/SkiaEffect.d.ts +17 -0
- package/dist/core/SkiaEffect.js +43 -8
- package/dist/core/SkiaImageManager.js +1 -1
- package/dist/core/Super.d.ts +22 -2
- package/dist/core/Super.js +47 -3
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/react/SkiaShell.js +33 -14
- package/dist/react/index.d.ts +17 -4
- package/dist/react/index.js +103 -15
- package/dist/react/reconciler.js +33 -13
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +42 -3
|
@@ -3,6 +3,7 @@ import { ControlTappedEventArgs } from "../core/Gestures";
|
|
|
3
3
|
import { Super } from "../core/Super";
|
|
4
4
|
import { Colors, ScaledSize, SKRect, Thickness, } from "../core/Types";
|
|
5
5
|
import { TextSpan } from "./TextSpan";
|
|
6
|
+
import { BidiRuns, HasCodePoint, IsRtl, JoinsPrevious, NeedsShaping, Shape } from "../core/Shaping";
|
|
6
7
|
/**
|
|
7
8
|
* Mirrors DrawnUi SkiaLabel: multi-line text with word wrapping, MaxLines + tail ellipsis, horizontal /
|
|
8
9
|
* vertical alignment, LineSpacing / LineHeight, weights and attributes resolved through the font registry,
|
|
@@ -24,6 +25,8 @@ export class SkiaLabel extends SkiaControl {
|
|
|
24
25
|
verticalTextAlignment = "Start";
|
|
25
26
|
lineSpacing = 1;
|
|
26
27
|
lineHeight = 1;
|
|
28
|
+
paragraphSpacing = 0;
|
|
29
|
+
characterSpacing = 1;
|
|
27
30
|
textTransform = "None";
|
|
28
31
|
padding = Thickness.Zero;
|
|
29
32
|
/** Styled fragments; when not empty they replace `Text` (same precedence as C#). */
|
|
@@ -43,12 +46,17 @@ export class SkiaLabel extends SkiaControl {
|
|
|
43
46
|
this[key] = v;
|
|
44
47
|
this.Update();
|
|
45
48
|
} }
|
|
49
|
+
/** A property that changes only the look (a color): no layout change, see UpdateDraw. */
|
|
50
|
+
SetLook(key, v) { if (this[key] !== v) {
|
|
51
|
+
this[key] = v;
|
|
52
|
+
this.UpdateDraw();
|
|
53
|
+
} }
|
|
46
54
|
get Text() { return this.text; }
|
|
47
55
|
set Text(v) { this.Set("text", v); }
|
|
48
56
|
get FontSize() { return this.fontSize; }
|
|
49
57
|
set FontSize(v) { this.Set("fontSize", v); }
|
|
50
58
|
get TextColor() { return this.textColor; }
|
|
51
|
-
set TextColor(v) { this.
|
|
59
|
+
set TextColor(v) { this.SetLook("textColor", v); }
|
|
52
60
|
get FontFamily() { return this.fontFamily; }
|
|
53
61
|
set FontFamily(v) { this.Set("fontFamily", v); }
|
|
54
62
|
/**
|
|
@@ -74,10 +82,22 @@ export class SkiaLabel extends SkiaControl {
|
|
|
74
82
|
/** Multiplier applied to the natural line height (ascent + descent). */
|
|
75
83
|
get LineHeight() { return this.lineHeight; }
|
|
76
84
|
set LineHeight(v) { this.Set("lineHeight", v); }
|
|
85
|
+
/**
|
|
86
|
+
* Space above every paragraph after the first, in lines (C# ParagraphSpacing; 0 here as DrawnUi.Rust, C# 0.25). A
|
|
87
|
+
* paragraph starts after "\n"; U+2028 breaks the line inside a paragraph.
|
|
88
|
+
*/
|
|
89
|
+
get ParagraphSpacing() { return this.paragraphSpacing; }
|
|
90
|
+
set ParagraphSpacing(v) { this.Set("paragraphSpacing", v); }
|
|
91
|
+
/**
|
|
92
|
+
* C# CharacterSpacing: 1 = the font's own spacing; every glyph is followed by (CharacterSpacing - 1) points more
|
|
93
|
+
* (less below 1), the line measures and wraps at the width it draws (C# 7cf1007c, DrawnUi.Rust label).
|
|
94
|
+
*/
|
|
95
|
+
get CharacterSpacing() { return this.characterSpacing; }
|
|
96
|
+
set CharacterSpacing(v) { this.Set("characterSpacing", v); }
|
|
77
97
|
get TextTransform() { return this.textTransform; }
|
|
78
98
|
set TextTransform(v) { this.Set("textTransform", v); }
|
|
79
99
|
get Padding() { return this.padding; }
|
|
80
|
-
set Padding(v) { this.Set("padding", v); }
|
|
100
|
+
set Padding(v) { this.Set("padding", Thickness.From(v)); }
|
|
81
101
|
/** Number of laid-out lines after the last measure. */
|
|
82
102
|
get LinesCount() { return this.lines.length; }
|
|
83
103
|
// ---- spans as children (reconciler AddSubView / InsertSubView / RemoveSubView) ----
|
|
@@ -85,8 +105,14 @@ export class SkiaLabel extends SkiaControl {
|
|
|
85
105
|
InsertSubView(index, control) {
|
|
86
106
|
if (!(control instanceof TextSpan))
|
|
87
107
|
throw new Error("DrawnUi: SkiaLabel children must be <TextSpan>");
|
|
108
|
+
const at = control.Parent === this ? this.Spans.indexOf(control) : -1; // already a span: a move, never a 2nd copy
|
|
109
|
+
if (at >= 0) {
|
|
110
|
+
this.Spans.splice(at, 1);
|
|
111
|
+
if (at < index)
|
|
112
|
+
index--;
|
|
113
|
+
}
|
|
88
114
|
control.Parent = this;
|
|
89
|
-
this.Spans.splice(index, 0, control);
|
|
115
|
+
this.Spans.splice(Math.min(Math.max(0, index), this.Spans.length), 0, control);
|
|
90
116
|
this.Update();
|
|
91
117
|
}
|
|
92
118
|
RemoveSubView(control) {
|
|
@@ -102,6 +128,8 @@ export class SkiaLabel extends SkiaControl {
|
|
|
102
128
|
mainFonts;
|
|
103
129
|
fontsCache = new Map();
|
|
104
130
|
runCache = new Map();
|
|
131
|
+
/** CharacterSpacing in pixels at the measured scale: added after every glyph of a run (its Width includes them). */
|
|
132
|
+
glyphSpacing = 0;
|
|
105
133
|
ResolveFonts(family, weight, italic, sizePx) {
|
|
106
134
|
const key = `${family}|${this.fontFamilyFallback}|${weight}|${italic}|${sizePx}`;
|
|
107
135
|
let f = this.fontsCache.get(key);
|
|
@@ -110,7 +138,7 @@ export class SkiaLabel extends SkiaControl {
|
|
|
110
138
|
const main = Super.GetFont(family, weight, italic, sizePx);
|
|
111
139
|
const m = main.getMetrics();
|
|
112
140
|
f = {
|
|
113
|
-
Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent,
|
|
141
|
+
Key: key, Main: main, SizePx: sizePx, Ascent: -m.ascent, Descent: m.descent, Italic: italic,
|
|
114
142
|
Fallbacks: this.fontFamilyFallback
|
|
115
143
|
? this.fontFamilyFallback.split(",").map((a) => a.trim()).filter(Boolean).map((a) => Super.GetFont(a, weight, italic, sizePx))
|
|
116
144
|
: [],
|
|
@@ -131,15 +159,35 @@ export class SkiaLabel extends SkiaControl {
|
|
|
131
159
|
const weight = span.FontWeight > 0 ? span.FontWeight : span.IsBold ? 700 : this.fontWeight > 0 ? this.fontWeight : bold ? 700 : 0;
|
|
132
160
|
return this.ResolveFonts(span.FontFamily ?? this.fontFamily, weight, italic, (span.FontSize ?? this.fontSize) * scale);
|
|
133
161
|
}
|
|
134
|
-
static
|
|
162
|
+
static NeedsShapingOrRtl(cp) { return NeedsShaping(cp) || IsRtl(cp); }
|
|
163
|
+
/** Width of a text in one font: the shaped glyphs where the text needs shaping (Arabic joins, emoji sequences), else glyph by glyph. */
|
|
164
|
+
Advance(font, text) {
|
|
165
|
+
if (HasCodePoint(text, SkiaLabel.NeedsShapingOrRtl)) {
|
|
166
|
+
const shaped = Shape(font, text, HasCodePoint(text, IsRtl), this.glyphSpacing);
|
|
167
|
+
if (shaped)
|
|
168
|
+
return shaped.Width;
|
|
169
|
+
}
|
|
135
170
|
let w = 0;
|
|
136
171
|
for (const adv of font.getGlyphWidths(font.getGlyphIDs(text)))
|
|
137
|
-
w += adv;
|
|
172
|
+
w += adv + this.glyphSpacing;
|
|
138
173
|
return w;
|
|
139
174
|
}
|
|
175
|
+
static Ignorable = /[\u200B-\u200F\u2060-\u2064\uFE00-\uFE0F\u{E0000}-\u{E0FFF}]/u;
|
|
176
|
+
/**
|
|
177
|
+
* Default-ignorable code points (zero width space, joiners, direction marks, word joiners, variation selectors such
|
|
178
|
+
* as U+FE0F after an emoji, tags) that none of the fonts has draw nothing and take no room, never the missing-glyph
|
|
179
|
+
* box (DrawnUi.Rust label_ignorables; text is not shaped here, C# hides them by shaping).
|
|
180
|
+
*/
|
|
181
|
+
static DropIgnorables(text, main, fallbacks) {
|
|
182
|
+
if (!SkiaLabel.Ignorable.test(text))
|
|
183
|
+
return text;
|
|
184
|
+
const has = (cp) => main.getGlyphIDs(cp)[0] !== 0 || fallbacks.some((f) => f.getGlyphIDs(cp)[0] !== 0);
|
|
185
|
+
return Array.from(text).filter((cp) => !SkiaLabel.Ignorable.test(cp) || has(cp)).join("");
|
|
186
|
+
}
|
|
140
187
|
/**
|
|
141
188
|
* Splits text into runs by glyph availability: the main font, or the first fallback that has a glyph where the
|
|
142
|
-
* main font has glyph 0. Spaces always stay on the main font (fallback faces often carry very wide spaces).
|
|
189
|
+
* main font has glyph 0. Spaces always stay on the main font (fallback faces often carry very wide spaces). A joiner,
|
|
190
|
+
* a variation selector, a skin tone or a tag keeps the font of the glyph before it: an emoji sequence is one run.
|
|
143
191
|
*/
|
|
144
192
|
Segment(text, fonts, span) {
|
|
145
193
|
if (text.length === 0)
|
|
@@ -150,8 +198,13 @@ export class SkiaLabel extends SkiaControl {
|
|
|
150
198
|
const main = fonts.Main;
|
|
151
199
|
const fbs = fonts.Fallbacks;
|
|
152
200
|
cached = [];
|
|
201
|
+
text = SkiaLabel.DropIgnorables(text, main, fbs);
|
|
202
|
+
if (text.length === 0) {
|
|
203
|
+
this.runCache.set(cacheKey, cached);
|
|
204
|
+
return cached;
|
|
205
|
+
}
|
|
153
206
|
if (fbs.length === 0) {
|
|
154
|
-
cached.push({ Text: text, Font: main, Width:
|
|
207
|
+
cached.push({ Text: text, Font: main, Width: this.Advance(main, text), Fonts: fonts });
|
|
155
208
|
}
|
|
156
209
|
else {
|
|
157
210
|
const cps = Array.from(text);
|
|
@@ -167,16 +220,16 @@ export class SkiaLabel extends SkiaControl {
|
|
|
167
220
|
};
|
|
168
221
|
let start = 0, current = fontFor(0);
|
|
169
222
|
for (let i = 1; i < cps.length; i++) {
|
|
170
|
-
const f = fontFor(i);
|
|
223
|
+
const f = JoinsPrevious(cps[i].codePointAt(0)) ? current : fontFor(i);
|
|
171
224
|
if (f !== current) {
|
|
172
225
|
const t = cps.slice(start, i).join("");
|
|
173
|
-
cached.push({ Text: t, Font: current, Width:
|
|
226
|
+
cached.push({ Text: t, Font: current, Width: this.Advance(current, t), Fonts: fonts });
|
|
174
227
|
start = i;
|
|
175
228
|
current = f;
|
|
176
229
|
}
|
|
177
230
|
}
|
|
178
231
|
const t = cps.slice(start).join("");
|
|
179
|
-
cached.push({ Text: t, Font: current, Width:
|
|
232
|
+
cached.push({ Text: t, Font: current, Width: this.Advance(current, t), Fonts: fonts });
|
|
180
233
|
}
|
|
181
234
|
this.runCache.set(cacheKey, cached);
|
|
182
235
|
}
|
|
@@ -184,6 +237,76 @@ export class SkiaLabel extends SkiaControl {
|
|
|
184
237
|
}
|
|
185
238
|
Width(runs) { let w = 0; for (const r of runs)
|
|
186
239
|
w += r.Width; return w; }
|
|
240
|
+
/** A line never starts with these (closing punctuation, small kana, the long vowel mark): JIS X 4051 kinsoku (C#). */
|
|
241
|
+
static NoBreakBefore = "、。,.・:;?!゛゜ヽヾゝゞ々〻ー」』)〕]}〉》】〗〙〟⦆»’”‐゠–〜~ぁぃぅぇぉっゃゅょゎゕゖァィゥェォッャュョヮヵヶㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ。」、・ーァィゥェォャュョッ)]},.!?:;%";
|
|
242
|
+
/** A line never ends with these (opening brackets and quotes). */
|
|
243
|
+
static NoBreakAfter = "「『(〔[{〈《【〖〘〝⦅«‘“「([{";
|
|
244
|
+
/** Chinese / Japanese: ideographs, kana, CJK punctuation, full-width forms (C# IsCjkAt). Korean breaks at spaces only. */
|
|
245
|
+
static Cjk = /[\u3000-\u312F\u3190-\u33FF\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF\u{20000}-\u{3FFFF}]/u;
|
|
246
|
+
static CanBreakBetween(before, after) {
|
|
247
|
+
return (SkiaLabel.Cjk.test(before) || SkiaLabel.Cjk.test(after)) && !SkiaLabel.NoBreakBefore.includes(after) && !SkiaLabel.NoBreakAfter.includes(before);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* C# CanBreakInsideWord: whether a line may break between text[index - 1] and text[index] (UTF-16 indexes) inside a
|
|
251
|
+
* space-free run: next to a Chinese or Japanese character, never before closing punctuation or small kana, never
|
|
252
|
+
* after an opening bracket, never inside a surrogate pair.
|
|
253
|
+
*/
|
|
254
|
+
static CanBreakInsideWord(text, index) {
|
|
255
|
+
if (index <= 0 || index >= text.length)
|
|
256
|
+
return false;
|
|
257
|
+
const hi = (k) => { const c = text.charCodeAt(k); return c >= 0xD800 && c <= 0xDBFF; };
|
|
258
|
+
if (hi(index - 1))
|
|
259
|
+
return false; // inside a surrogate pair
|
|
260
|
+
const before = String.fromCodePoint(text.codePointAt(hi(index - 2) && index >= 2 ? index - 2 : index - 1));
|
|
261
|
+
const after = String.fromCodePoint(text.codePointAt(index));
|
|
262
|
+
return SkiaLabel.CanBreakBetween(before, after);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* C# FitAtBreak: the last place inside the word where a Chinese / Japanese line may break and `prefix` plus the word
|
|
266
|
+
* up to there still fits; code points from the word's start, 0 = none.
|
|
267
|
+
*/
|
|
268
|
+
FitCjk(word, prefix, maxWidth) {
|
|
269
|
+
if (!word.some((r) => SkiaLabel.Cjk.test(r.Text)))
|
|
270
|
+
return 0;
|
|
271
|
+
const sp = this.glyphSpacing;
|
|
272
|
+
let x = prefix, best = 0, before = "", k = 0;
|
|
273
|
+
for (const r of word) {
|
|
274
|
+
const cps = Array.from(r.Text), widths = r.Font.getGlyphWidths(r.Font.getGlyphIDs(r.Text, cps.length));
|
|
275
|
+
for (let i = 0; i < cps.length; i++) {
|
|
276
|
+
if (k > 0 && SkiaLabel.CanBreakBetween(before, cps[i])) {
|
|
277
|
+
if (x - sp > maxWidth)
|
|
278
|
+
return best;
|
|
279
|
+
best = k;
|
|
280
|
+
}
|
|
281
|
+
x += widths[i] + sp;
|
|
282
|
+
before = cps[i];
|
|
283
|
+
k++;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return best;
|
|
287
|
+
}
|
|
288
|
+
/** The word cut after `count` code points: the head goes on a line, the rest follows. */
|
|
289
|
+
SplitWord(word, count) {
|
|
290
|
+
const head = [], rest = [];
|
|
291
|
+
let left = count;
|
|
292
|
+
for (const r of word) {
|
|
293
|
+
const cps = Array.from(r.Text);
|
|
294
|
+
if (left >= cps.length) {
|
|
295
|
+
head.push(r);
|
|
296
|
+
left -= cps.length;
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (left > 0) {
|
|
300
|
+
const a = cps.slice(0, left).join(""), b = cps.slice(left).join("");
|
|
301
|
+
head.push({ ...r, Text: a, Width: this.Advance(r.Font, a) });
|
|
302
|
+
rest.push({ ...r, Text: b, Width: this.Advance(r.Font, b) });
|
|
303
|
+
left = 0;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
rest.push(r);
|
|
307
|
+
}
|
|
308
|
+
return [head, rest];
|
|
309
|
+
}
|
|
187
310
|
Transform(text) {
|
|
188
311
|
switch (this.textTransform) {
|
|
189
312
|
case "Uppercase": return text.toUpperCase();
|
|
@@ -199,10 +322,16 @@ export class SkiaLabel extends SkiaControl {
|
|
|
199
322
|
Tokenize(scale) {
|
|
200
323
|
const paragraphs = [[]];
|
|
201
324
|
const add = (text, fonts, span) => {
|
|
202
|
-
|
|
325
|
+
// "\n" starts a paragraph, U+2028 breaks the line inside one
|
|
326
|
+
const pieces = this.Transform(text).split(/(\n|\u2028)/);
|
|
327
|
+
const parts = pieces.filter((_, i) => i % 2 === 0), seps = pieces.filter((_, i) => i % 2 === 1);
|
|
203
328
|
for (let p = 0; p < parts.length; p++) {
|
|
204
|
-
if (p > 0)
|
|
205
|
-
|
|
329
|
+
if (p > 0) {
|
|
330
|
+
const next = [];
|
|
331
|
+
if (seps[p - 1] === "\u2028")
|
|
332
|
+
next.LineBreak = true;
|
|
333
|
+
paragraphs.push(next);
|
|
334
|
+
}
|
|
206
335
|
const para = paragraphs[paragraphs.length - 1];
|
|
207
336
|
const words = parts[p].split(" ");
|
|
208
337
|
for (let w = 0; w < words.length; w++) {
|
|
@@ -222,11 +351,11 @@ export class SkiaLabel extends SkiaControl {
|
|
|
222
351
|
else if (this.text) {
|
|
223
352
|
add(this.text, this.mainFonts);
|
|
224
353
|
}
|
|
225
|
-
// a fragment ending with a space puts
|
|
354
|
+
// a fragment ending with a space puts that space, in its own style, before the NEXT token
|
|
226
355
|
for (const para of paragraphs) {
|
|
227
356
|
for (let i = 0; i < para.length; i++) {
|
|
228
357
|
if (para[i].TrailingSpace && i + 1 < para.length)
|
|
229
|
-
para[i + 1].
|
|
358
|
+
para[i + 1].Carried = { Fonts: para[i].Fonts, Span: para[i].Span };
|
|
230
359
|
}
|
|
231
360
|
}
|
|
232
361
|
return paragraphs;
|
|
@@ -248,63 +377,100 @@ export class SkiaLabel extends SkiaControl {
|
|
|
248
377
|
line.Descent = r.Fonts.Descent;
|
|
249
378
|
}
|
|
250
379
|
}
|
|
251
|
-
/**
|
|
252
|
-
|
|
380
|
+
/**
|
|
381
|
+
* Word-wraps tokens into lines that fit maxWidth (Infinity = no wrap); keeps the lines that fit maxHeight (at least one)
|
|
382
|
+
* and MaxLines, the last kept one ending with a tail ellipsis (C# / DrawnUi.Rust: a label in a box too short for its
|
|
383
|
+
* text cuts it, not only MaxLines).
|
|
384
|
+
*/
|
|
385
|
+
LayoutLines(maxWidth, scale, maxHeight = Infinity) {
|
|
253
386
|
const wrap = this.lineBreakMode !== "NoWrap" && isFinite(maxWidth);
|
|
387
|
+
// run widths carry the gap after every glyph; the one after a line's last glyph is not drawn
|
|
388
|
+
const sp = this.glyphSpacing;
|
|
254
389
|
const out = [];
|
|
255
390
|
const empty = (fonts) => { const l = this.NewLine(); l.Ascent = fonts.Ascent; l.Descent = fonts.Descent; return l; };
|
|
256
391
|
for (const para of this.Tokenize(scale)) {
|
|
257
392
|
let line = this.NewLine();
|
|
393
|
+
if (out.length > 0 && !para.LineBreak)
|
|
394
|
+
line.Para = true;
|
|
258
395
|
let lastFonts = this.mainFonts;
|
|
259
396
|
for (let i = 0; i < para.length; i++) {
|
|
260
397
|
const tok = para[i];
|
|
261
398
|
lastFonts = tok.Fonts;
|
|
262
399
|
// glued fragments (no space between spans) wrap as one word
|
|
263
400
|
let word = this.Segment(tok.Text, tok.Fonts, tok.Span);
|
|
264
|
-
while (i + 1 < para.length && !para[i + 1].SpaceBefore) {
|
|
401
|
+
while (i + 1 < para.length && !para[i + 1].SpaceBefore && !para[i + 1].Carried) {
|
|
265
402
|
i++;
|
|
266
403
|
word = word.concat(this.Segment(para[i].Text, para[i].Fonts, para[i].Span));
|
|
267
404
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
405
|
+
for (;;) {
|
|
406
|
+
// the space the fragment before ends with, then the word's own one, each in its style
|
|
407
|
+
const space = line.Runs.length === 0 ? [] : [
|
|
408
|
+
...(tok.Carried ? this.Segment(" ", tok.Carried.Fonts, tok.Carried.Span) : []),
|
|
409
|
+
...(tok.SpaceBefore ? this.Segment(" ", tok.Fonts, tok.Span) : []),
|
|
410
|
+
];
|
|
411
|
+
const spaceW = this.Width(space), wordW = this.Width(word);
|
|
412
|
+
if (!wrap || line.Width + spaceW + wordW - sp <= maxWidth || (line.Runs.length === 0 && wordW - sp <= maxWidth)) {
|
|
413
|
+
this.Append(line, space);
|
|
414
|
+
this.Append(line, word);
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
// Chinese / Japanese: the word fills the line up to its last break that fits (C# FitAtBreak)
|
|
418
|
+
const k = this.FitCjk(word, line.Width + spaceW, maxWidth);
|
|
419
|
+
if (k > 0) {
|
|
420
|
+
const [head, rest] = this.SplitWord(word, k);
|
|
421
|
+
this.Append(line, space);
|
|
422
|
+
this.Append(line, head);
|
|
423
|
+
out.push(line);
|
|
424
|
+
line = this.NewLine();
|
|
425
|
+
word = rest;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (line.Runs.length > 0) {
|
|
429
|
+
out.push(line);
|
|
430
|
+
line = this.NewLine();
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
// word longer than the line: break by code points
|
|
434
|
+
for (const r of word) {
|
|
435
|
+
for (const ch of Array.from(r.Text)) {
|
|
436
|
+
const run = this.Segment(ch, r.Fonts, r.Span);
|
|
437
|
+
const chW = this.Width(run);
|
|
438
|
+
if (line.Runs.length > 0 && line.Width + chW - sp > maxWidth) {
|
|
439
|
+
out.push(line);
|
|
440
|
+
line = this.NewLine();
|
|
441
|
+
}
|
|
442
|
+
this.Append(line, run);
|
|
291
443
|
}
|
|
292
|
-
this.Append(line, run);
|
|
293
444
|
}
|
|
445
|
+
break;
|
|
294
446
|
}
|
|
295
447
|
}
|
|
296
448
|
out.push(line.Runs.length > 0 ? line : empty(lastFonts));
|
|
297
449
|
}
|
|
298
|
-
|
|
299
|
-
|
|
450
|
+
let kept = this.maxLines > 0 ? Math.min(out.length, this.maxLines) : out.length;
|
|
451
|
+
if (isFinite(maxHeight)) {
|
|
452
|
+
let used = 0, fit = 0;
|
|
453
|
+
for (let i = 0; i < out.length; i++) {
|
|
454
|
+
const lh = this.LineHeightPx(out[i]);
|
|
455
|
+
// the block height of the first i + 1 lines: spacing after every line but the last, paragraph space above
|
|
456
|
+
const total = used + lh + (i > 0 ? this.ParagraphSpace(out[i]) : 0);
|
|
457
|
+
if (total > maxHeight && fit > 0)
|
|
458
|
+
break;
|
|
459
|
+
fit++;
|
|
460
|
+
used = total - lh + lh * this.lineSpacing;
|
|
461
|
+
}
|
|
462
|
+
kept = Math.min(kept, fit);
|
|
463
|
+
}
|
|
464
|
+
if (kept < out.length) {
|
|
465
|
+
out.length = kept;
|
|
300
466
|
const truncates = this.lineBreakMode === "TailTruncation" || this.lineBreakMode === "HeadTruncation" || this.lineBreakMode === "MiddleTruncation";
|
|
301
467
|
if (truncates) {
|
|
302
|
-
const last = out[
|
|
468
|
+
const last = out[kept - 1];
|
|
303
469
|
const tailRun = last.Runs[last.Runs.length - 1];
|
|
304
470
|
const fonts = tailRun ? tailRun.Fonts : this.mainFonts;
|
|
305
471
|
const ell = this.Segment("…", fonts, tailRun?.Span);
|
|
306
472
|
const ellW = this.Width(ell);
|
|
307
|
-
while (last.Runs.length > 0 && last.Width + ellW > maxWidth) {
|
|
473
|
+
while (last.Runs.length > 0 && last.Width + ellW - sp > maxWidth) {
|
|
308
474
|
const r = last.Runs[last.Runs.length - 1];
|
|
309
475
|
const cps = Array.from(r.Text);
|
|
310
476
|
cps.pop();
|
|
@@ -316,27 +482,178 @@ export class SkiaLabel extends SkiaControl {
|
|
|
316
482
|
continue;
|
|
317
483
|
}
|
|
318
484
|
r.Text = cps.join("");
|
|
319
|
-
r.Width =
|
|
485
|
+
r.Width = this.Advance(r.Font, r.Text);
|
|
320
486
|
last.Width += r.Width;
|
|
321
487
|
}
|
|
322
488
|
this.Append(last, ell);
|
|
323
489
|
}
|
|
324
490
|
}
|
|
491
|
+
if (sp !== 0)
|
|
492
|
+
for (const l of out)
|
|
493
|
+
if (l.Runs.length > 0)
|
|
494
|
+
l.Width -= sp;
|
|
325
495
|
return out;
|
|
326
496
|
}
|
|
497
|
+
/** A paragraph is right to left when its first strong letter is (DrawnUi.Rust split_bidi). */
|
|
498
|
+
static FirstStrongIsRtl(text) {
|
|
499
|
+
for (const ch of text) {
|
|
500
|
+
const cp = ch.codePointAt(0);
|
|
501
|
+
if (IsRtl(cp))
|
|
502
|
+
return true;
|
|
503
|
+
if (/\p{L}/u.test(ch))
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
return false;
|
|
507
|
+
}
|
|
508
|
+
/** The runs of a line cut where its visual run changes; `map` per UTF-16 index of the line text. */
|
|
509
|
+
SplitByRuns(runs, map) {
|
|
510
|
+
const out = [];
|
|
511
|
+
let at = 0;
|
|
512
|
+
for (const r of runs) {
|
|
513
|
+
const piece = (from, to) => {
|
|
514
|
+
const text = r.Text.slice(from, to);
|
|
515
|
+
out.push({ ...r, Text: text, Width: from === 0 && to === r.Text.length ? r.Width : this.Advance(r.Font, text), Level: map.Rtl[at + from] ? 1 : 0, Rank: map.Rank[at + from], At: at + from, Shaped: undefined, X: undefined });
|
|
516
|
+
};
|
|
517
|
+
let from = 0;
|
|
518
|
+
for (let i = 0; i < r.Text.length;) {
|
|
519
|
+
if (i > 0 && map.Rank[at + i] !== map.Rank[at + from]) {
|
|
520
|
+
piece(from, i);
|
|
521
|
+
from = i;
|
|
522
|
+
}
|
|
523
|
+
i += r.Text.codePointAt(i) > 0xFFFF ? 2 : 1;
|
|
524
|
+
}
|
|
525
|
+
if (r.Text.length > 0)
|
|
526
|
+
piece(from, r.Text.length);
|
|
527
|
+
at += r.Text.length;
|
|
528
|
+
}
|
|
529
|
+
return out;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* After the layout, lines whose text needs shaping or runs right to left (DrawnUi.Rust build_blobs): with
|
|
533
|
+
* right-to-left text every run is cut where its bidirectional run changes (Unicode bidirectional algorithm, ICU, the
|
|
534
|
+
* paragraph direction from its first strong letter); runs that are right to left or need shaping get shaped glyphs;
|
|
535
|
+
* runs are placed in visual order. Lines without such text are left as they are (plain path).
|
|
536
|
+
*/
|
|
537
|
+
ShapeLines(lines) {
|
|
538
|
+
const sp = this.glyphSpacing;
|
|
539
|
+
const lineText = (l) => l.Runs.map((r) => r.Text).join("");
|
|
540
|
+
const anyRtl = lines.some((l) => l.Runs.some((r) => HasCodePoint(r.Text, IsRtl)));
|
|
541
|
+
let rtlParagraph = false;
|
|
542
|
+
for (let li = 0; li < lines.length; li++) {
|
|
543
|
+
const line = lines[li];
|
|
544
|
+
let bidi = false;
|
|
545
|
+
if (anyRtl) {
|
|
546
|
+
if (li === 0 || line.Para) {
|
|
547
|
+
let end = li + 1;
|
|
548
|
+
while (end < lines.length && !lines[end].Para)
|
|
549
|
+
end++;
|
|
550
|
+
rtlParagraph = SkiaLabel.FirstStrongIsRtl(lines.slice(li, end).map(lineText).join(""));
|
|
551
|
+
}
|
|
552
|
+
line.Rtl = rtlParagraph;
|
|
553
|
+
const map = BidiRuns(lineText(line), rtlParagraph);
|
|
554
|
+
if (map) {
|
|
555
|
+
line.Runs = this.SplitByRuns(line.Runs, map);
|
|
556
|
+
bidi = line.Runs.some((r) => (r.Level ?? 0) > 0);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
let shaped = false;
|
|
560
|
+
for (const run of line.Runs) {
|
|
561
|
+
const rtl = (run.Level ?? 0) % 2 === 1;
|
|
562
|
+
if (!rtl && !HasCodePoint(run.Text, NeedsShaping))
|
|
563
|
+
continue;
|
|
564
|
+
const s = Shape(run.Font, run.Text, rtl, sp);
|
|
565
|
+
if (s) {
|
|
566
|
+
run.Shaped = s;
|
|
567
|
+
run.Width = s.Width;
|
|
568
|
+
shaped = true;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
if (!shaped && !bidi)
|
|
572
|
+
continue;
|
|
573
|
+
let width = 0;
|
|
574
|
+
for (const run of line.Runs)
|
|
575
|
+
width += run.Width;
|
|
576
|
+
line.Width = line.Runs.length > 0 ? width - sp : 0;
|
|
577
|
+
if (bidi)
|
|
578
|
+
SkiaLabel.PlaceRuns(line.Runs);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Where each run of a line with right-to-left text goes: visual runs left to right; inside a run, pieces (spans, fonts)
|
|
583
|
+
* in logical order, reversed in a right-to-left run.
|
|
584
|
+
*/
|
|
585
|
+
static PlaceRuns(runs) {
|
|
586
|
+
const order = runs.map((_, i) => i).sort((a, b) => {
|
|
587
|
+
const ra = runs[a], rb = runs[b];
|
|
588
|
+
if ((ra.Rank ?? 0) !== (rb.Rank ?? 0))
|
|
589
|
+
return (ra.Rank ?? 0) - (rb.Rank ?? 0);
|
|
590
|
+
return ((ra.Level ?? 0) % 2 === 1 ? -1 : 1) * ((ra.At ?? 0) - (rb.At ?? 0));
|
|
591
|
+
});
|
|
592
|
+
let x = 0;
|
|
593
|
+
for (const k of order) {
|
|
594
|
+
runs[k].X = x;
|
|
595
|
+
x += runs[k].Width;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
327
598
|
LineHeightPx(line) { return (line.Ascent + line.Descent) * this.lineHeight; }
|
|
599
|
+
/** ParagraphSpacing above a line that starts a paragraph (after the first): that many of its lines, with their spacing. */
|
|
600
|
+
ParagraphSpace(line) { return line.Para && this.paragraphSpacing ? this.LineHeightPx(line) * this.lineSpacing * this.paragraphSpacing : 0; }
|
|
328
601
|
BlockHeight() {
|
|
329
602
|
let h = 0;
|
|
330
603
|
for (let i = 0; i < this.lines.length; i++) {
|
|
331
604
|
const lh = this.LineHeightPx(this.lines[i]);
|
|
332
|
-
h += i < this.lines.length - 1 ? lh * this.lineSpacing : lh;
|
|
605
|
+
h += (i < this.lines.length - 1 ? lh * this.lineSpacing : lh) + this.ParagraphSpace(this.lines[i]);
|
|
333
606
|
}
|
|
334
607
|
return h;
|
|
335
608
|
}
|
|
336
|
-
|
|
609
|
+
/** Skew of synthetic italic (Super.GetFont setSkewX -0.25): x moves by 0.25 per pixel above the baseline. */
|
|
610
|
+
static ItalicSkew = 0.25;
|
|
611
|
+
/** Pixels synthetic italic glyphs reach past the line box: right at the ascent, left at the descent. */
|
|
612
|
+
slantRight = 0;
|
|
613
|
+
slantLeft = 0;
|
|
614
|
+
/** The slant of synthetic italic is drawn outside the label's box: caches record that room too (C# / DrawnUi.Rust draw it whole). */
|
|
615
|
+
ComputeEffectsMargin(scale) {
|
|
616
|
+
const m = super.ComputeEffectsMargin(scale);
|
|
617
|
+
if (this.slantRight === 0 && this.slantLeft === 0)
|
|
618
|
+
return m;
|
|
619
|
+
return new Thickness(m.Left + this.slantLeft, m.Top, m.Right + this.slantRight, m.Bottom);
|
|
620
|
+
}
|
|
621
|
+
/**
|
|
622
|
+
* Where a line starts inside [left, right] (drawnui-cross 6am): Start and End follow the paragraph's direction (in a
|
|
623
|
+
* right-to-left paragraph Start is the right edge); Center is centered; Fill* lines are not stretched here and sit
|
|
624
|
+
* at the paragraph's start.
|
|
625
|
+
*/
|
|
626
|
+
LineX(line, left, right, lineW) {
|
|
627
|
+
const a = this.horizontalTextAlignment;
|
|
628
|
+
if (a === "Center")
|
|
629
|
+
return left + (right - left - lineW) / 2;
|
|
630
|
+
const atEnd = a === "End" ? !line.Rtl : !!line.Rtl;
|
|
631
|
+
return atEnd ? right - lineW : left;
|
|
632
|
+
}
|
|
633
|
+
MeasureAbsolute(widthConstraint, heightConstraint, scale) {
|
|
337
634
|
this.mainFonts = this.ResolveMainFonts(scale);
|
|
635
|
+
const glyphSpacing = scale * (this.characterSpacing - 1);
|
|
636
|
+
if (glyphSpacing !== this.glyphSpacing) {
|
|
637
|
+
this.glyphSpacing = glyphSpacing;
|
|
638
|
+
this.runCache.clear();
|
|
639
|
+
}
|
|
338
640
|
const px = this.padding.HorizontalThickness * scale, py = this.padding.VerticalThickness * scale;
|
|
339
|
-
|
|
641
|
+
const extraH = this.EffectsExtra(scale).H;
|
|
642
|
+
this.lines = this.text || this.Spans.length > 0 ? this.LayoutLines(widthConstraint - px, scale, heightConstraint - py - extraH) : [];
|
|
643
|
+
this.ShapeLines(this.lines);
|
|
644
|
+
// synthetic italic leans its glyphs past their advances: drawing room for caches, widths unchanged (DrawnUi.Rust label.rs)
|
|
645
|
+
let slantRight = 0, slantLeft = 0;
|
|
646
|
+
for (const l of this.lines)
|
|
647
|
+
for (const r of l.Runs)
|
|
648
|
+
if (r.Fonts.Italic && r.Text.trim()) {
|
|
649
|
+
slantRight = Math.max(slantRight, SkiaLabel.ItalicSkew * r.Fonts.Ascent);
|
|
650
|
+
slantLeft = Math.max(slantLeft, SkiaLabel.ItalicSkew * r.Fonts.Descent);
|
|
651
|
+
}
|
|
652
|
+
if (slantRight !== this.slantRight || slantLeft !== this.slantLeft) {
|
|
653
|
+
this.slantRight = slantRight;
|
|
654
|
+
this.slantLeft = slantLeft;
|
|
655
|
+
this.InvalidateEffectsMargin();
|
|
656
|
+
}
|
|
340
657
|
let width = 0;
|
|
341
658
|
for (const l of this.lines)
|
|
342
659
|
width = Math.max(width, l.Width);
|
|
@@ -367,13 +684,10 @@ export class SkiaLabel extends SkiaControl {
|
|
|
367
684
|
y += extra.Stroke / 2;
|
|
368
685
|
const out = [];
|
|
369
686
|
for (const line of this.lines) {
|
|
687
|
+
y += this.ParagraphSpace(line);
|
|
370
688
|
const lh = this.LineHeightPx(line);
|
|
371
689
|
const lineW = line.Width + extra.W;
|
|
372
|
-
let x = left;
|
|
373
|
-
if (this.horizontalTextAlignment === "Center")
|
|
374
|
-
x = left + (right - left - lineW) / 2;
|
|
375
|
-
else if (this.horizontalTextAlignment === "End")
|
|
376
|
-
x = right - lineW;
|
|
690
|
+
let x = this.LineX(line, left, right, lineW);
|
|
377
691
|
x += extra.Stroke / 2;
|
|
378
692
|
out.push({ x, y, w: line.Width, h: lh, text: line.Runs.map((r) => r.Text).join("") });
|
|
379
693
|
y += lh * this.lineSpacing;
|
|
@@ -412,16 +726,30 @@ export class SkiaLabel extends SkiaControl {
|
|
|
412
726
|
let start = g.text.length ? this.text.indexOf(g.text, cursor) : cursor;
|
|
413
727
|
if (start < 0)
|
|
414
728
|
start = cursor;
|
|
729
|
+
// boxes in logical order, each at its visual place: a right-to-left run fills from its right edge
|
|
415
730
|
let x = g.x, index = start;
|
|
731
|
+
const sp = this.glyphSpacing;
|
|
416
732
|
for (const run of line.Runs) {
|
|
733
|
+
if (run.X !== undefined)
|
|
734
|
+
x = g.x + run.X;
|
|
417
735
|
const cps = Array.from(run.Text);
|
|
418
|
-
const widths = run.Font.getGlyphWidths(run.Font.getGlyphIDs(run.Text, cps.length));
|
|
736
|
+
const widths = run.Shaped ? run.Shaped.Advances.map((a) => a - sp) : run.Font.getGlyphWidths(run.Font.getGlyphIDs(run.Text, cps.length));
|
|
737
|
+
const rtl = (run.Level ?? 0) % 2 === 1;
|
|
738
|
+
let right = x + run.Width - sp;
|
|
419
739
|
cps.forEach((cp, k) => {
|
|
420
740
|
const w = widths[k] ?? 0;
|
|
421
|
-
|
|
422
|
-
|
|
741
|
+
if (rtl) {
|
|
742
|
+
out.push({ Index: index, Length: cp.length, Line: li, Left: right - w, Top: g.y, Width: w, Height: g.h, Rtl: true });
|
|
743
|
+
right -= w + sp;
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
out.push({ Index: index, Length: cp.length, Line: li, Left: x, Top: g.y, Width: w, Height: g.h });
|
|
747
|
+
x += w + sp;
|
|
748
|
+
}
|
|
423
749
|
index += cp.length;
|
|
424
750
|
});
|
|
751
|
+
if (rtl)
|
|
752
|
+
x += run.Width;
|
|
425
753
|
}
|
|
426
754
|
cursor = start + g.text.length;
|
|
427
755
|
});
|
|
@@ -501,40 +829,61 @@ export class SkiaLabel extends SkiaControl {
|
|
|
501
829
|
return paint;
|
|
502
830
|
};
|
|
503
831
|
const canvas = ctx.Context.Canvas;
|
|
832
|
+
const sp = this.glyphSpacing;
|
|
833
|
+
// spaced text: every glyph placed with the gap after it (C# MeasureLineGlyphs positions)
|
|
834
|
+
const drawRun = (run, rx, ry, paint) => {
|
|
835
|
+
if (run.Shaped) {
|
|
836
|
+
canvas.drawGlyphs(run.Shaped.Glyphs, run.Shaped.Positions, rx, ry, run.Font, paint);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
if (sp === 0) {
|
|
840
|
+
canvas.drawText(run.Text, rx, ry, paint, run.Font);
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
const ids = run.Font.getGlyphIDs(run.Text), widths = run.Font.getGlyphWidths(ids);
|
|
844
|
+
const positions = new Float32Array(ids.length * 2);
|
|
845
|
+
for (let k = 0, gx = 0; k < ids.length; k++) {
|
|
846
|
+
positions[k * 2] = gx;
|
|
847
|
+
gx += widths[k] + sp;
|
|
848
|
+
}
|
|
849
|
+
canvas.drawGlyphs(ids, positions, rx, ry, run.Font, paint);
|
|
850
|
+
};
|
|
504
851
|
const gradient = this.FillGradient;
|
|
505
852
|
const textRect = new SKRect(left, top, right, bottom);
|
|
506
853
|
for (const line of this.lines) {
|
|
854
|
+
y += this.ParagraphSpace(line);
|
|
507
855
|
const lh = this.LineHeightPx(line);
|
|
508
856
|
const lineW = line.Width + extra.W;
|
|
509
|
-
let x = left;
|
|
510
|
-
if (this.horizontalTextAlignment === "Center")
|
|
511
|
-
x = left + (right - left - lineW) / 2;
|
|
512
|
-
else if (this.horizontalTextAlignment === "End")
|
|
513
|
-
x = right - lineW;
|
|
857
|
+
let x = this.LineX(line, left, right, lineW);
|
|
514
858
|
x += extra.Stroke / 2;
|
|
515
859
|
const baseline = y + line.Ascent;
|
|
516
860
|
// C# paintDefault gets the gradient over rectDraw, or over line.Bounds per line (GradientByLines)
|
|
517
861
|
const gradientRect = gradient ? (this.GradientByLines ? new SKRect(x, y, x + line.Width, y + lh) : textRect) : undefined;
|
|
518
862
|
if (strokePaint && this.StrokeGradient)
|
|
519
863
|
this.SetupGradient(strokePaint, this.StrokeGradient, gradientRect ?? new SKRect(x, y, x + line.Width, y + lh));
|
|
864
|
+
const lineX = x;
|
|
520
865
|
for (const run of line.Runs) {
|
|
866
|
+
// a line with right-to-left text places its runs in visual order
|
|
867
|
+
if (run.X !== undefined)
|
|
868
|
+
x = lineX + run.X;
|
|
521
869
|
const span = run.Span;
|
|
870
|
+
const drawnW = run.Width - sp; // the gap after the run's last glyph is not part of it
|
|
522
871
|
if (span) {
|
|
523
|
-
span.Rects.push(new SKRect(x - d.Left, y - d.Top, x +
|
|
872
|
+
span.Rects.push(new SKRect(x - d.Left, y - d.Top, x + drawnW - d.Left, y + lh - d.Top));
|
|
524
873
|
if (span.BackgroundColor)
|
|
525
|
-
canvas.drawRect(CK.LTRBRect(x, y, x +
|
|
874
|
+
canvas.drawRect(CK.LTRBRect(x, y, x + drawnW, y + lh), paintFor(span.BackgroundColor));
|
|
526
875
|
}
|
|
527
876
|
const color = span?.TextColor ?? this.textColor;
|
|
528
877
|
if (run.Text) {
|
|
529
878
|
// C# DrawText order: drop shadow, stroke, fill
|
|
530
879
|
if (shadowPaint)
|
|
531
|
-
|
|
880
|
+
drawRun(run, x + shadowDx, baseline + shadowDy, shadowPaint);
|
|
532
881
|
if (strokePaint)
|
|
533
|
-
|
|
882
|
+
drawRun(run, x, baseline, strokePaint);
|
|
534
883
|
const paint = paintFor(color);
|
|
535
884
|
if (gradient && gradientRect)
|
|
536
885
|
this.SetupGradient(paint, gradient, gradientRect);
|
|
537
|
-
|
|
886
|
+
drawRun(run, x, baseline, paint);
|
|
538
887
|
}
|
|
539
888
|
if (span?.HasDecorations) {
|
|
540
889
|
// same geometry as C# DrawSpanDecorations; CanvasKit exposes no underline/strikeout/x-height metrics,
|
|
@@ -542,11 +891,11 @@ export class SkiaLabel extends SkiaControl {
|
|
|
542
891
|
if (span.Underline && span.UnderlineWidth !== 0) {
|
|
543
892
|
const w = span.UnderlineWidth > 0 ? span.UnderlineWidth * scale : -span.UnderlineWidth;
|
|
544
893
|
const yl = Math.round(baseline + scale);
|
|
545
|
-
canvas.drawLine(x, yl, x +
|
|
894
|
+
canvas.drawLine(x, yl, x + drawnW, yl, paintFor(color, w));
|
|
546
895
|
}
|
|
547
896
|
if (span.Strikeout) {
|
|
548
897
|
const yl = Math.round(baseline - (run.Fonts.SizePx * 0.52) / 2);
|
|
549
|
-
canvas.drawLine(x, yl, x +
|
|
898
|
+
canvas.drawLine(x, yl, x + drawnW, yl, paintFor(span.StrikeoutColor, span.StrikeoutWidth * scale));
|
|
550
899
|
}
|
|
551
900
|
}
|
|
552
901
|
x += run.Width;
|