xbintsc 0.6.9 → 0.6.12
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/dist/src/checker/globals.js +2 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +1 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/state.js +3 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +3 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/compiler.js +1 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.js +1 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/driver/version.js.map +1 -1
- package/dist/src/extensions/node/crypto/index.js +12 -1
- package/dist/src/extensions/node/crypto/index.js.map +1 -1
- package/dist/tests/driver/config.test.js +15 -2
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +26 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-node.test.js +37 -1
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/crypto-random.test.d.ts +9 -0
- package/dist/tests/e2e/crypto-random.test.js +63 -0
- package/dist/tests/e2e/crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/date-parse.test.js +27 -1
- package/dist/tests/e2e/date-parse.test.js.map +1 -1
- package/dist/tests/e2e/gui-css-coverage.test.js +1 -1
- package/dist/tests/e2e/gui-dom.test.js +29 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-form.test.d.ts +9 -0
- package/dist/tests/e2e/gui-form.test.js +359 -0
- package/dist/tests/e2e/gui-form.test.js.map +1 -0
- package/dist/tests/e2e/gui-helpers.d.ts +2 -0
- package/dist/tests/e2e/gui-helpers.js +1 -0
- package/dist/tests/e2e/gui-helpers.js.map +1 -1
- package/dist/tests/e2e/gui-layout.test.js +47 -0
- package/dist/tests/e2e/gui-layout.test.js.map +1 -1
- package/dist/tests/e2e/gui-paint.test.js +108 -0
- package/dist/tests/e2e/gui-paint.test.js.map +1 -1
- package/dist/tests/e2e/gui-script-import-order.test.js +6 -1
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/gui-style.test.js +82 -0
- package/dist/tests/e2e/gui-style.test.js.map +1 -1
- package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
- package/dist/tests/e2e/gui-unsupported.test.js +124 -0
- package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
- package/dist/tests/e2e/json-parse-errors.test.d.ts +9 -0
- package/dist/tests/e2e/json-parse-errors.test.js +48 -0
- package/dist/tests/e2e/json-parse-errors.test.js.map +1 -0
- package/doc/ai/extensions.md +7 -4
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/zh-CN/extensions.md +6 -3
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/gui/api.md +8 -2
- package/doc/gui/dom.md +81 -4
- package/doc/gui/input.md +74 -3
- package/doc/gui/known-issues.md +12 -5
- package/doc/gui/layout.md +19 -6
- package/doc/gui/rendering.md +16 -9
- package/doc/implemented/node/crypto.md +8 -0
- package/doc/implemented/node/fs.md +1 -1
- package/doc/implemented/stdlib.md +10 -2
- package/doc/zh-CN/gui/api.md +8 -2
- package/doc/zh-CN/gui/dom.md +70 -4
- package/doc/zh-CN/gui/input.md +65 -4
- package/doc/zh-CN/gui/known-issues.md +11 -4
- package/doc/zh-CN/gui/layout.md +14 -4
- package/doc/zh-CN/gui/rendering.md +13 -10
- package/doc/zh-CN/implemented/node/crypto.md +6 -0
- package/doc/zh-CN/implemented/node/fs.md +1 -1
- package/doc/zh-CN/implemented/stdlib.md +10 -2
- package/package.json +7 -7
- package/runtime/ext_gui/clip_values.cpp +11 -0
- package/runtime/ext_gui/css.cpp +27 -2
- package/runtime/ext_gui/css_match.cpp +21 -1
- package/runtime/ext_gui/css_selector.cpp +23 -0
- package/runtime/ext_gui/css_sheet.cpp +7 -0
- package/runtime/ext_gui/document.cpp +15 -0
- package/runtime/ext_gui/document_animation.cpp +4 -1
- package/runtime/ext_gui/dom.h +41 -2
- package/runtime/ext_gui/dom_api.cpp +3 -0
- package/runtime/ext_gui/dom_api_document.cpp +28 -0
- package/runtime/ext_gui/dom_api_events.cpp +17 -14
- package/runtime/ext_gui/dom_api_form.cpp +567 -0
- package/runtime/ext_gui/dom_api_internal.h +46 -214
- package/runtime/ext_gui/dom_api_mutation.cpp +1 -1
- package/runtime/ext_gui/dom_api_node.cpp +10 -3
- package/runtime/ext_gui/dom_api_node_read.cpp +1 -1
- package/runtime/ext_gui/dom_api_proto.cpp +45 -0
- package/runtime/ext_gui/dom_api_webgl_methods.h +217 -0
- package/runtime/ext_gui/dom_parse.cpp +118 -1
- package/runtime/ext_gui/effect_values.cpp +28 -7
- package/runtime/ext_gui/form_focus.cpp +293 -0
- package/runtime/ext_gui/form_input.cpp +448 -0
- package/runtime/ext_gui/form_internal.h +30 -0
- package/runtime/ext_gui/form_shared.cpp +126 -0
- package/runtime/ext_gui/form_state.cpp +536 -0
- package/runtime/ext_gui/form_state.h +97 -0
- package/runtime/ext_gui/gradient_values.cpp +25 -5
- package/runtime/ext_gui/gui_engine.h +40 -4
- package/runtime/ext_gui/gui_events.cpp +63 -48
- package/runtime/ext_gui/inline_svg.cpp +3 -0
- package/runtime/ext_gui/layout.cpp +6 -0
- package/runtime/ext_gui/layout.h +4 -0
- package/runtime/ext_gui/layout_flow.cpp +35 -3
- package/runtime/ext_gui/layout_inline.cpp +80 -7
- package/runtime/ext_gui/media_query.cpp +7 -1
- package/runtime/ext_gui/paint.cpp +62 -24
- package/runtime/ext_gui/paint.h +7 -4
- package/runtime/ext_gui/paint_clip.cpp +74 -19
- package/runtime/ext_gui/paint_form.cpp +389 -0
- package/runtime/ext_gui/paint_internal.h +13 -1
- package/runtime/ext_gui/renderer_clip.cpp +19 -17
- package/runtime/ext_gui/style.cpp +5 -1
- package/runtime/ext_gui/style.h +5 -0
- package/runtime/ext_gui/style_cascade.cpp +2 -0
- package/runtime/ext_gui/style_internal.h +7 -2
- package/runtime/ext_gui/style_print.cpp +33 -0
- package/runtime/ext_gui/style_text.cpp +11 -0
- package/runtime/ext_gui/style_ua.cpp +42 -0
- package/runtime/ext_gui/style_values.cpp +89 -90
- package/runtime/ext_gui/transform.cpp +2 -0
- package/runtime/ext_gui/warnings.cpp +298 -0
- package/runtime/ext_gui/warnings.h +59 -0
- package/runtime/ext_gui/window.cpp +31 -55
- package/runtime/ext_gui/window_diagnostics.cpp +58 -0
- package/runtime/ext_gui/window_emit.cpp +51 -0
- package/runtime/ext_node/crypto/crypto.c +3 -2
- package/runtime/ext_node/crypto/crypto_hash.h +13 -0
- package/runtime/ext_node/crypto/crypto_random.c +339 -0
- package/runtime/ext_node/fs/async_worker.c +1 -1
- package/runtime/ext_node/fs/fs_ops.c +1 -1
- package/runtime/ext_node/fs/parts/platform.inc +65 -0
- package/runtime/rt.h +27 -0
- package/runtime/xt_crypto.c +132 -0
- package/runtime/xt_random.c +143 -0
- package/runtime/xt_regex/matcher.inc +9 -28
- package/runtime/xt_regex/parser.inc +65 -2
- package/runtime/xt_regex/types.inc +11 -1
- package/runtime/xt_regex.h +6 -2
- package/runtime/xt_stdlib/dispatch.inc +2 -0
- package/runtime/xt_stdlib/math.inc +1 -1
- package/runtime/xt_stdlib2/date.inc +204 -4
- package/runtime/xt_stdlib2/json.inc +4 -546
- package/runtime/xt_stdlib2/json_parse.inc +347 -0
- package/runtime/xt_stdlib2/json_stringify.inc +368 -0
- package/runtime/xt_stdlib2/regexp-match.inc +6 -11
- package/runtime/xt_stdlib2.c +0 -4
- package/runtime/xt_typed_array/elements.inc +6 -1
- package/src/checker/globals.ts +2 -0
- package/src/cli/main.ts +1 -0
- package/src/codegen/generator/state.ts +3 -0
- package/src/codegen/generator/tables.ts +3 -0
- package/src/driver/compiler.ts +1 -1
- package/src/driver/config.ts +1 -0
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/node/crypto/index.ts +12 -1
|
@@ -65,15 +65,22 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
65
65
|
|
|
66
66
|
/** The clip a box imposes on its content: its padding box, intersected with the
|
|
67
67
|
* clip already in effect. Only `overflow: hidden/scroll/auto` clips. A
|
|
68
|
-
*
|
|
69
|
-
|
|
68
|
+
* `border-radius` makes that clip a rounded rectangle, exactly as a browser
|
|
69
|
+
* rounds `overflow` (the GPU scissor stays the bounding box; the rounded shape
|
|
70
|
+
* joins the `clip-path` polygons the renderer intersects). A transformed box
|
|
71
|
+
* clips to the bounding box of its transformed padding box. */
|
|
72
|
+
PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent, DisplayList &out) {
|
|
70
73
|
if (box->style == nullptr || box->style->overflow == Overflow::Visible) return parent;
|
|
71
|
-
float
|
|
72
|
-
float
|
|
73
|
-
float
|
|
74
|
-
float
|
|
75
|
-
if (
|
|
76
|
-
if (
|
|
74
|
+
float padding_x = box->x + box->border_left;
|
|
75
|
+
float padding_y = box->y + box->border_top;
|
|
76
|
+
float padding_width = box->width - box->border_left - box->border_right;
|
|
77
|
+
float padding_height = box->height - box->border_top - box->border_bottom;
|
|
78
|
+
if (padding_width < 0) padding_width = 0;
|
|
79
|
+
if (padding_height < 0) padding_height = 0;
|
|
80
|
+
float x = padding_x;
|
|
81
|
+
float y = padding_y;
|
|
82
|
+
float width = padding_width;
|
|
83
|
+
float height = padding_height;
|
|
77
84
|
if (box->has_transform) {
|
|
78
85
|
LayoutRect bounds = xt_layout_transform_rect(box->world, x, y, width, height);
|
|
79
86
|
x = bounds.x;
|
|
@@ -88,16 +95,28 @@ PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent) {
|
|
|
88
95
|
result.y = y;
|
|
89
96
|
result.width = width;
|
|
90
97
|
result.height = height;
|
|
91
|
-
|
|
98
|
+
} else {
|
|
99
|
+
float x0 = std::max(x, parent.x);
|
|
100
|
+
float y0 = std::max(y, parent.y);
|
|
101
|
+
float x1 = std::min(x + width, parent.x + parent.width);
|
|
102
|
+
float y1 = std::min(y + height, parent.y + parent.height);
|
|
103
|
+
result.x = x0;
|
|
104
|
+
result.y = y0;
|
|
105
|
+
result.width = std::max(0.0f, x1 - x0);
|
|
106
|
+
result.height = std::max(0.0f, y1 - y0);
|
|
107
|
+
}
|
|
108
|
+
/* The radius belongs to the border box, so the padding box's inner radius is
|
|
109
|
+
* reduced by the widest border (CSS 8.1). The polygon is built from the
|
|
110
|
+
* *untransformed* padding box and mapped point by point, so a rotated box
|
|
111
|
+
* keeps a round circle instead of a rounded AABB. */
|
|
112
|
+
if (box->border_radius > 0.0f && padding_width > 0.0f && padding_height > 0.0f) {
|
|
113
|
+
float inset = std::max(std::max(box->border_left, box->border_right),
|
|
114
|
+
std::max(box->border_top, box->border_bottom));
|
|
115
|
+
float radius = box->border_radius - inset;
|
|
116
|
+
int index = paint_detail::addRoundedClipPath(out, box->world, padding_x, padding_y,
|
|
117
|
+
padding_width, padding_height, radius);
|
|
118
|
+
result = paint_detail::addClipPath(result, index);
|
|
92
119
|
}
|
|
93
|
-
float x0 = std::max(x, parent.x);
|
|
94
|
-
float y0 = std::max(y, parent.y);
|
|
95
|
-
float x1 = std::min(x + width, parent.x + parent.width);
|
|
96
|
-
float y1 = std::min(y + height, parent.y + parent.height);
|
|
97
|
-
result.x = x0;
|
|
98
|
-
result.y = y0;
|
|
99
|
-
result.width = std::max(0.0f, x1 - x0);
|
|
100
|
-
result.height = std::max(0.0f, y1 - y0);
|
|
101
120
|
return result;
|
|
102
121
|
}
|
|
103
122
|
|
|
@@ -209,6 +228,21 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
209
228
|
}
|
|
210
229
|
}
|
|
211
230
|
|
|
231
|
+
/* `border-radius` also clips the box's own background images/gradients and
|
|
232
|
+
* replaced content; a solid background is already painted as a rounded
|
|
233
|
+
* rectangle and needs no polygon. An `<img>`/`<svg>` with only a radius
|
|
234
|
+
* (no `overflow: hidden`) gets its corners clipped this way too. */
|
|
235
|
+
PaintClip contentClip = own;
|
|
236
|
+
if (style != nullptr && !box->is_text && box->border_radius > 0.0f && box->width > 0.0f &&
|
|
237
|
+
box->height > 0.0f) {
|
|
238
|
+
bool replaces = box->is_image || box->is_canvas || box->is_media || box->is_inline_svg;
|
|
239
|
+
if (!style->background_layers.empty() || replaces) {
|
|
240
|
+
int index = paint_detail::addRoundedClipPath(out, box->world, box->x, box->y, box->width,
|
|
241
|
+
box->height, box->border_radius);
|
|
242
|
+
contentClip = paint_detail::addClipPath(contentClip, index);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
212
246
|
if (style != nullptr && box->display != Display::None) {
|
|
213
247
|
if (box->is_text) {
|
|
214
248
|
addTextRuns(box, *style, out, own, chain, viewportWidth, viewportHeight);
|
|
@@ -223,7 +257,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
223
257
|
* paint above it. */
|
|
224
258
|
paint_detail::addBoxShadows(out, *box, *style, chain, own, false, viewportWidth,
|
|
225
259
|
viewportHeight);
|
|
226
|
-
paint_detail::paintBackgrounds(out, *box, *style, chain,
|
|
260
|
+
paint_detail::paintBackgrounds(out, *box, *style, chain, contentClip, viewportWidth,
|
|
227
261
|
viewportHeight);
|
|
228
262
|
const Matrix2D &matrix = box->world;
|
|
229
263
|
if (style->border_style != BorderStyle::None && style->has_border_color) {
|
|
@@ -245,7 +279,10 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
245
279
|
paint_detail::addBoxShadows(out, *box, *style, chain, own, true, viewportWidth,
|
|
246
280
|
viewportHeight);
|
|
247
281
|
paint_detail::addOutline(out, *box, *style, chain, own, viewportWidth, viewportHeight);
|
|
248
|
-
if (box->
|
|
282
|
+
if (box->is_control) {
|
|
283
|
+
paint_detail::xt_paint_form_control(*box, *style, out, contentClip, chain, viewportWidth,
|
|
284
|
+
viewportHeight);
|
|
285
|
+
} else if (box->is_canvas && box->canvas_id != 0 && box->content_width > 0.0f &&
|
|
249
286
|
box->content_height > 0.0f) {
|
|
250
287
|
PaintImage image;
|
|
251
288
|
image.x = box->content_x;
|
|
@@ -254,7 +291,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
254
291
|
image.height = box->content_height;
|
|
255
292
|
image.canvas_id = box->canvas_id;
|
|
256
293
|
image.transform = matrix;
|
|
257
|
-
paint_detail::addImage(out, image,
|
|
294
|
+
paint_detail::addImage(out, image, contentClip, chain);
|
|
258
295
|
} else if (box->is_media && box->media_id != 0 && box->content_width > 0.0f &&
|
|
259
296
|
box->content_height > 0.0f) {
|
|
260
297
|
PaintImage image;
|
|
@@ -264,7 +301,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
264
301
|
image.height = box->content_height;
|
|
265
302
|
image.media_id = box->media_id;
|
|
266
303
|
image.transform = matrix;
|
|
267
|
-
paint_detail::addImage(out, image,
|
|
304
|
+
paint_detail::addImage(out, image, contentClip, chain);
|
|
268
305
|
} else if (box->is_inline_svg && !box->svg_markup.empty() && box->content_width > 0.0f &&
|
|
269
306
|
box->content_height > 0.0f) {
|
|
270
307
|
PaintImage image;
|
|
@@ -274,7 +311,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
274
311
|
image.height = box->content_height;
|
|
275
312
|
image.svg = box->svg_markup;
|
|
276
313
|
image.transform = matrix;
|
|
277
|
-
paint_detail::addImage(out, image,
|
|
314
|
+
paint_detail::addImage(out, image, contentClip, chain);
|
|
278
315
|
} else if (box->is_image && !box->image_src.empty() && box->content_width > 0.0f &&
|
|
279
316
|
box->content_height > 0.0f) {
|
|
280
317
|
PaintImage image;
|
|
@@ -284,7 +321,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
284
321
|
image.height = box->content_height;
|
|
285
322
|
image.src = box->image_src;
|
|
286
323
|
image.transform = matrix;
|
|
287
|
-
paint_detail::addImage(out, image,
|
|
324
|
+
paint_detail::addImage(out, image, contentClip, chain);
|
|
288
325
|
}
|
|
289
326
|
}
|
|
290
327
|
}
|
|
@@ -293,7 +330,8 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
|
|
|
293
330
|
* already been emitted, so descendants must not repeat it. */
|
|
294
331
|
paint_detail::FilterChain childChain = chain;
|
|
295
332
|
childChain.shadows.clear();
|
|
296
|
-
paintChildren(box, out, clipForChildren(box, own), childChain, viewportWidth,
|
|
333
|
+
paintChildren(box, out, clipForChildren(box, own, out), childChain, viewportWidth,
|
|
334
|
+
viewportHeight);
|
|
297
335
|
}
|
|
298
336
|
|
|
299
337
|
/** Paint one box, wrapping it in a `mix-blend-mode` group when it declares one.
|
package/runtime/ext_gui/paint.h
CHANGED
|
@@ -156,17 +156,20 @@ struct ClipPathGeometry {
|
|
|
156
156
|
|
|
157
157
|
/** The clip rectangle in effect for a painted shape (device-space logical
|
|
158
158
|
* pixels — a transformed subtree contributes the bounding box of its clip).
|
|
159
|
-
* `width <= 0` means "no clip". `paths` index `DisplayList::clip_paths
|
|
160
|
-
*
|
|
161
|
-
*
|
|
159
|
+
* `width <= 0` means "no clip". `paths` index `DisplayList::clip_paths`: the
|
|
160
|
+
* `clip-path` shapes and the rounded padding boxes of `overflow` ancestors
|
|
161
|
+
* intersected down the tree. Four nested shapes are kept (CSS would intersect
|
|
162
|
+
* every ancestor; deeper nesting is rare and the outermost four are the ones a
|
|
163
|
+
* shape has to satisfy). */
|
|
162
164
|
struct PaintClip {
|
|
165
|
+
static constexpr int kMaxPaths = 4;
|
|
163
166
|
bool active = false;
|
|
164
167
|
float x = 0;
|
|
165
168
|
float y = 0;
|
|
166
169
|
float width = 0;
|
|
167
170
|
float height = 0;
|
|
168
171
|
int path_count = 0;
|
|
169
|
-
int paths[
|
|
172
|
+
int paths[kMaxPaths] = {-1, -1, -1, -1};
|
|
170
173
|
};
|
|
171
174
|
|
|
172
175
|
enum class PaintKind { Rect, Text, Image, LayerBegin, LayerEnd, Backdrop };
|
|
@@ -215,6 +215,49 @@ void triangulate(std::vector<Point> points, std::vector<ClipTriangle> *triangles
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/** Transform a box-local polygon into device space, triangulate it and store it
|
|
219
|
+
* on the display list. A polygon with fewer than three points is kept as an
|
|
220
|
+
* empty clip: a valid `clip-path` that hides everything must not degrade into
|
|
221
|
+
* "no clip". `convex` lets a caller that knows the shape (a rounded rectangle)
|
|
222
|
+
* skip ear clipping and emit a fan. */
|
|
223
|
+
int storeClipPolygon(DisplayList &out, const std::vector<Point> &points, const Matrix2D &world,
|
|
224
|
+
bool convex) {
|
|
225
|
+
ClipPathGeometry geometry;
|
|
226
|
+
geometry.points.reserve(points.size() * 2);
|
|
227
|
+
for (const Point &point : points) {
|
|
228
|
+
float x = point.x;
|
|
229
|
+
float y = point.y;
|
|
230
|
+
world.apply(point.x, point.y, &x, &y);
|
|
231
|
+
geometry.points.push_back(x);
|
|
232
|
+
geometry.points.push_back(y);
|
|
233
|
+
}
|
|
234
|
+
if (points.size() >= 3) {
|
|
235
|
+
if (convex) {
|
|
236
|
+
/* A convex outline is triangulated by a fan from its first vertex; the
|
|
237
|
+
* rounded-overflow shape (the common case) has ~68 points and this keeps
|
|
238
|
+
* its cost linear. */
|
|
239
|
+
for (size_t i = 1; i + 1 < points.size(); i++) {
|
|
240
|
+
ClipTriangle triangle;
|
|
241
|
+
triangle.x[0] = geometry.points[0];
|
|
242
|
+
triangle.y[0] = geometry.points[1];
|
|
243
|
+
triangle.x[1] = geometry.points[i * 2];
|
|
244
|
+
triangle.y[1] = geometry.points[i * 2 + 1];
|
|
245
|
+
triangle.x[2] = geometry.points[(i + 1) * 2];
|
|
246
|
+
triangle.y[2] = geometry.points[(i + 1) * 2 + 1];
|
|
247
|
+
geometry.triangles.push_back(triangle);
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
std::vector<Point> device;
|
|
251
|
+
device.reserve(points.size());
|
|
252
|
+
for (size_t i = 0; i + 1 < geometry.points.size(); i += 2)
|
|
253
|
+
device.push_back({geometry.points[i], geometry.points[i + 1]});
|
|
254
|
+
triangulate(device, &geometry.triangles);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
out.clip_paths.push_back(std::move(geometry));
|
|
258
|
+
return (int)(out.clip_paths.size() - 1);
|
|
259
|
+
}
|
|
260
|
+
|
|
218
261
|
} // namespace
|
|
219
262
|
|
|
220
263
|
int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &style,
|
|
@@ -238,29 +281,41 @@ int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &sty
|
|
|
238
281
|
/* An empty but valid shape (`inset(50%)`, `circle(0)`) clips everything away;
|
|
239
282
|
* it must not fall back to "no clip". The paint walk keeps the empty geometry
|
|
240
283
|
* and the renderer emits no geometry for ops that reference it. */
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
284
|
+
return storeClipPolygon(out, points, box.world, false);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
int addRoundedClipPath(DisplayList &out, const Matrix2D &world, float x, float y, float width,
|
|
288
|
+
float height, float radius) {
|
|
289
|
+
if (width <= 0.0f || height <= 0.0f || radius <= 0.0f) return -1;
|
|
290
|
+
/* CSS never lets a corner arc exceed half of the shorter side. */
|
|
291
|
+
float limit = std::min(width, height) * 0.5f;
|
|
292
|
+
if (radius > limit) radius = limit;
|
|
293
|
+
if (radius <= 0.0f) return -1;
|
|
294
|
+
/* Sixteen chords per quarter circle keep a large (176px) preview avatar
|
|
295
|
+
* visually round — the chord error at that radius is under half a pixel —
|
|
296
|
+
* and stay cheap to clip quads against. The `inset(... round ...)` outline
|
|
297
|
+
* keeps its coarser six-segment construction. */
|
|
298
|
+
constexpr int kSegments = 16;
|
|
299
|
+
std::vector<Point> points;
|
|
300
|
+
points.reserve((size_t)(kSegments + 1) * 4);
|
|
301
|
+
auto arc = [&](float centerX, float centerY, float start) {
|
|
302
|
+
for (int i = 0; i <= kSegments; i++) {
|
|
303
|
+
float angle = start + (float)i / (float)kSegments * (kPi * 0.5f);
|
|
304
|
+
appendPoint(&points,
|
|
305
|
+
{centerX + std::cos(angle) * radius, centerY + std::sin(angle) * radius});
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
/* Clockwise from the top-left corner, matching `insetOutline`. */
|
|
309
|
+
arc(x + radius, y + radius, kPi);
|
|
310
|
+
arc(x + width - radius, y + radius, kPi * 1.5f);
|
|
311
|
+
arc(x + width - radius, y + height - radius, 0.0f);
|
|
312
|
+
arc(x + radius, y + height - radius, kPi * 0.5f);
|
|
313
|
+
return storeClipPolygon(out, points, world, true);
|
|
259
314
|
}
|
|
260
315
|
|
|
261
316
|
PaintClip addClipPath(PaintClip clip, int index) {
|
|
262
317
|
if (index < 0) return clip;
|
|
263
|
-
if (clip.path_count <
|
|
318
|
+
if (clip.path_count < PaintClip::kMaxPaths) clip.paths[clip.path_count++] = index;
|
|
264
319
|
return clip;
|
|
265
320
|
}
|
|
266
321
|
|