xbintsc 0.6.8 → 0.6.10

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.
Files changed (71) hide show
  1. package/dist/src/cli/help.d.ts +1 -1
  2. package/dist/src/cli/main.js +1 -0
  3. package/dist/src/cli/main.js.map +1 -1
  4. package/dist/src/driver/config.js +1 -0
  5. package/dist/src/driver/config.js.map +1 -1
  6. package/dist/src/driver/toolchain.d.ts +10 -0
  7. package/dist/src/driver/toolchain.js +69 -8
  8. package/dist/src/driver/toolchain.js.map +1 -1
  9. package/dist/src/driver/version.d.ts +1 -1
  10. package/dist/src/driver/version.js +1 -1
  11. package/dist/src/driver/version.js.map +1 -1
  12. package/dist/tests/driver/config.test.js +15 -2
  13. package/dist/tests/driver/config.test.js.map +1 -1
  14. package/dist/tests/driver/toolchain.test.js +23 -2
  15. package/dist/tests/driver/toolchain.test.js.map +1 -1
  16. package/dist/tests/e2e/gui-helpers.d.ts +2 -0
  17. package/dist/tests/e2e/gui-helpers.js +1 -0
  18. package/dist/tests/e2e/gui-helpers.js.map +1 -1
  19. package/dist/tests/e2e/gui-layout.test.js +47 -0
  20. package/dist/tests/e2e/gui-layout.test.js.map +1 -1
  21. package/dist/tests/e2e/gui-paint.test.js +108 -0
  22. package/dist/tests/e2e/gui-paint.test.js.map +1 -1
  23. package/dist/tests/e2e/gui-unsupported.test.d.ts +6 -0
  24. package/dist/tests/e2e/gui-unsupported.test.js +123 -0
  25. package/dist/tests/e2e/gui-unsupported.test.js.map +1 -0
  26. package/doc/ai/extensions.md +7 -4
  27. package/doc/ai/zh-CN/extensions.md +6 -3
  28. package/doc/gui/dom.md +69 -1
  29. package/doc/gui/known-issues.md +12 -5
  30. package/doc/gui/layout.md +19 -6
  31. package/doc/gui/rendering.md +16 -9
  32. package/doc/requirements.md +5 -3
  33. package/doc/zh-CN/gui/dom.md +61 -1
  34. package/doc/zh-CN/gui/known-issues.md +11 -4
  35. package/doc/zh-CN/gui/layout.md +14 -4
  36. package/doc/zh-CN/gui/rendering.md +13 -10
  37. package/doc/zh-CN/requirements.md +5 -2
  38. package/package.json +7 -7
  39. package/runtime/ext_gui/clip_values.cpp +11 -0
  40. package/runtime/ext_gui/css.cpp +27 -2
  41. package/runtime/ext_gui/css_selector.cpp +23 -0
  42. package/runtime/ext_gui/css_sheet.cpp +7 -0
  43. package/runtime/ext_gui/document.cpp +3 -0
  44. package/runtime/ext_gui/document_animation.cpp +4 -1
  45. package/runtime/ext_gui/dom_api.cpp +3 -0
  46. package/runtime/ext_gui/dom_parse.cpp +4 -0
  47. package/runtime/ext_gui/effect_values.cpp +28 -7
  48. package/runtime/ext_gui/gradient_values.cpp +25 -5
  49. package/runtime/ext_gui/inline_svg.cpp +3 -0
  50. package/runtime/ext_gui/layout_flow.cpp +12 -2
  51. package/runtime/ext_gui/layout_inline.cpp +80 -7
  52. package/runtime/ext_gui/media_query.cpp +7 -1
  53. package/runtime/ext_gui/paint.cpp +58 -23
  54. package/runtime/ext_gui/paint.h +7 -4
  55. package/runtime/ext_gui/paint_clip.cpp +74 -19
  56. package/runtime/ext_gui/paint_internal.h +7 -1
  57. package/runtime/ext_gui/renderer_clip.cpp +19 -17
  58. package/runtime/ext_gui/style.cpp +5 -1
  59. package/runtime/ext_gui/style.h +5 -0
  60. package/runtime/ext_gui/style_cascade.cpp +2 -0
  61. package/runtime/ext_gui/style_internal.h +7 -2
  62. package/runtime/ext_gui/style_print.cpp +3 -0
  63. package/runtime/ext_gui/style_text.cpp +11 -0
  64. package/runtime/ext_gui/style_values.cpp +89 -90
  65. package/runtime/ext_gui/transform.cpp +2 -0
  66. package/runtime/ext_gui/warnings.cpp +300 -0
  67. package/runtime/ext_gui/warnings.h +59 -0
  68. package/src/cli/main.ts +1 -0
  69. package/src/driver/config.ts +1 -0
  70. package/src/driver/toolchain.ts +79 -8
  71. package/src/driver/version.ts +1 -1
@@ -4,6 +4,8 @@
4
4
 
5
5
  #include "inline_svg.h"
6
6
 
7
+ #include "warnings.h"
8
+
7
9
  #include <cctype>
8
10
  #include <cstdio>
9
11
  #include <string>
@@ -239,6 +241,7 @@ void serializeStyleText(const Node *node, const std::unordered_map<const Node *,
239
241
  void serializeNode(const Node *node, const std::unordered_map<const Node *, XtStyle> *styles,
240
242
  std::string *out) {
241
243
  if (node == nullptr || !node->isElement()) return;
244
+ xt_warn_unsupported_svg_element(node->tag);
242
245
  const XtStyle *computed = nullptr;
243
246
  if (styles != nullptr) {
244
247
  auto found = styles->find(node);
@@ -390,6 +390,16 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
390
390
  if (block->style->display == Display::Grid)
391
391
  return layoutGrid(block, contentWidth, definiteHeight);
392
392
 
393
+ /* A percentage height on a child resolves against this block's *content*
394
+ * height. `definiteHeight` is that height when it is known (an explicit
395
+ * `height`, a clamp()/aspect-ratio result, or a flex/grid stretch); a box
396
+ * whose height came from `clamp()` must hand that value down, because the
397
+ * `availableHeight` it received is only the containing block's height from
398
+ * further up (or -1 when that chain is indefinite). Without this, a
399
+ * `height: 100%` portrait inside a sized frame was treated as `auto` and
400
+ * collapsed to its zero-height absolutely positioned artwork. */
401
+ float childHeight = definiteHeight >= 0 ? definiteHeight : availableHeight;
402
+
393
403
  float y = block->content_y;
394
404
  float startY = y;
395
405
  /* The bottom margin of the last in-flow block, waiting to collapse with the
@@ -458,7 +468,7 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
458
468
  : block->content_x + contentWidth - outerWidth;
459
469
  setContainingBlock(child.get(), containingBlockAncestor(block));
460
470
  float height =
461
- layoutBlock(child.get(), floatX, y, contentWidth, availableHeight, contentW);
471
+ layoutBlock(child.get(), floatX, y, contentWidth, childHeight, contentW);
462
472
  ActiveFloat entry;
463
473
  entry.left = childStyle->float_side == FloatSide::Left;
464
474
  entry.x = child->x;
@@ -489,7 +499,7 @@ float Layouter::layoutChildren(LayoutBox *block, float contentWidth, float avail
489
499
  }
490
500
  y = desired;
491
501
  setContainingBlock(child.get(), containingBlockAncestor(block));
492
- y += layoutBlock(child.get(), block->content_x, y, contentWidth, availableHeight);
502
+ y += layoutBlock(child.get(), block->content_x, y, contentWidth, childHeight);
493
503
  pending = child->margin_bottom;
494
504
  hasBlock = true;
495
505
  } else {
@@ -8,6 +8,8 @@
8
8
 
9
9
  #include "layout_flow_internal.h"
10
10
 
11
+ #include <utility>
12
+
11
13
  namespace xtgui {
12
14
  namespace layout_flow_detail {
13
15
 
@@ -24,12 +26,23 @@ void Layouter::flattenInline(LayoutBox *box, float contentWidth,
24
26
  const std::string &text = box->text;
25
27
  size_t i = 0;
26
28
  while (i < text.size()) {
27
- if (text[i] == '\n') {
28
- InlineItem br;
29
- br.box = box;
30
- br.style = &style;
31
- br.force_break = true;
32
- out.push_back(std::move(br));
29
+ if (text[i] == '\n' || text[i] == '\r') {
30
+ /* `nowrap` collapses a source newline to a space; the other modes keep
31
+ * the engine's existing forced break (notably `pre`, which must). */
32
+ bool preserveNewline = style.white_space != WhiteSpace::NoWrap;
33
+ InlineItem item;
34
+ item.box = box;
35
+ item.style = &style;
36
+ if (preserveNewline) {
37
+ item.force_break = true;
38
+ } else {
39
+ item.text = " ";
40
+ item.is_space = true;
41
+ item.width = textWidth(" ", style);
42
+ item.height = height;
43
+ item.ascent = ascent;
44
+ }
45
+ out.push_back(std::move(item));
33
46
  i++;
34
47
  continue;
35
48
  }
@@ -143,12 +156,34 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
143
156
  for (LayoutBox *box : run) computeInlineGeometry(box);
144
157
  return height;
145
158
  }
159
+ /* `nowrap`/`pre` keep the run on one line (a preserved newline still breaks
160
+ * it); without that, `text-overflow: ellipsis` would never see an overflowing
161
+ * line on ordinary prose. */
162
+ const bool wrap = containerStyle.white_space == WhiteSpace::Normal ||
163
+ containerStyle.white_space == WhiteSpace::PreWrap ||
164
+ containerStyle.white_space == WhiteSpace::PreLine;
165
+ const bool ellipsis = containerStyle.text_overflow == TextOverflow::Ellipsis &&
166
+ containerStyle.overflow != Overflow::Visible;
146
167
  float cursorY = y;
147
168
  std::vector<InlineItem *> line;
148
169
  float lineWidth = 0;
149
170
  float lineAscent = 0;
150
171
  float lineDescent = 0;
151
172
 
173
+ /* Byte length of the longest UTF-8 prefix of `text` that fits in `budget`
174
+ * when measured with `style`, without splitting a multi-byte code point. */
175
+ auto fittingPrefix = [&](const std::string &text, const XtStyle &style, float budget) {
176
+ size_t best = 0;
177
+ for (size_t i = 0; i < text.size();) {
178
+ size_t next = i + 1;
179
+ while (next < text.size() && ((unsigned char)text[next] & 0xC0) == 0x80) next++;
180
+ if (textWidth(text.substr(0, next), style) > budget + 0.001f) break;
181
+ best = next;
182
+ i = next;
183
+ }
184
+ return best;
185
+ };
186
+
152
187
  /* Horizontal band left free by the floats overlapping [top, top + height). */
153
188
  auto band = [&](float top, float height, float *x0, float *x1) {
154
189
  *x0 = container->content_x;
@@ -171,6 +206,44 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
171
206
  float x1 = 0;
172
207
  band(cursorY, height, &x0, &x1);
173
208
  float available = x1 - x0;
209
+ if (ellipsis && lineWidth > available + 0.001f) {
210
+ /* Replace the part of the line that does not fit with one ellipsis. The
211
+ * ellipsis gets the style of the run it terminates, so a smaller/larger
212
+ * inline span keeps its own metrics. */
213
+ const std::string dots = "\xE2\x80\xA6"; // U+2026 HORIZONTAL ELLIPSIS
214
+ float dotsWidth = textWidth(dots, containerStyle);
215
+ float budget = available - dotsWidth;
216
+ if (budget < 0.0f) budget = 0.0f;
217
+ std::vector<InlineItem *> kept;
218
+ float used = 0.0f;
219
+ for (InlineItem *item : line) {
220
+ if (used + item->width <= budget + 0.001f) {
221
+ kept.push_back(item);
222
+ used += item->width;
223
+ continue;
224
+ }
225
+ if (item->atomic) {
226
+ /* An atomic inline box cannot carry the ellipsis itself; append it to
227
+ * the last text run when one still fits, otherwise drop the box. */
228
+ if (!kept.empty() && !kept.back()->atomic && !kept.back()->is_space) {
229
+ kept.back()->text += dots;
230
+ kept.back()->width += dotsWidth;
231
+ }
232
+ break;
233
+ }
234
+ size_t prefix = fittingPrefix(item->text, *item->style, budget - used);
235
+ std::string text = item->text.substr(0, prefix);
236
+ while (!text.empty() && (text.back() == ' ' || text.back() == '\t')) text.pop_back();
237
+ item->text = text + dots;
238
+ item->width = textWidth(text, *item->style) + dotsWidth;
239
+ kept.push_back(item);
240
+ break;
241
+ }
242
+ line = std::move(kept);
243
+ lineWidth = 0.0f;
244
+ for (InlineItem *item : line) lineWidth += item->width;
245
+ if (line.empty()) return;
246
+ }
174
247
  float x = x0;
175
248
  if (containerStyle.text_align == TextAlign::Center) {
176
249
  x += (available - lineWidth) / 2.0f;
@@ -213,7 +286,7 @@ float Layouter::layoutInlineRun(LayoutBox *container, const std::vector<LayoutBo
213
286
  float x1 = 0;
214
287
  band(cursorY, pendingHeight, &x0, &x1);
215
288
  float available = x1 - x0;
216
- if (lineWidth + item.width > available && !line.empty()) finalize();
289
+ if (wrap && lineWidth + item.width > available && !line.empty()) finalize();
217
290
  if (item.is_space && line.empty()) continue;
218
291
  line.push_back(&item);
219
292
  lineWidth += item.width;
@@ -9,6 +9,8 @@
9
9
  */
10
10
  #include "css_internal.h"
11
11
 
12
+ #include "warnings.h"
13
+
12
14
  #include <cmath>
13
15
  #include <string>
14
16
  #include <vector>
@@ -113,7 +115,10 @@ bool evaluateRange(const std::string &inner, float vw, float vh, bool *matched)
113
115
  float actual = 0.0f;
114
116
  if (feature == "width") actual = vw;
115
117
  else if (feature == "height") actual = vh;
116
- else return false;
118
+ else {
119
+ xt_warn_unsupported_media_feature(feature);
120
+ return false;
121
+ }
117
122
  float value = 0.0f;
118
123
  if (!mediaLength(valueText, vw, vh, &value)) return false;
119
124
  if (flipped) {
@@ -159,6 +164,7 @@ bool evaluateFeature(const std::string &inner, float vw, float vh) {
159
164
  if (name == "prefers-contrast") return value == "no-preference";
160
165
  if (name == "scripting") return value == "enabled";
161
166
  if (name == "display-mode") return value == "browser";
167
+ xt_warn_unsupported_media_feature(name);
162
168
  return false;
163
169
  }
164
170
 
@@ -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
- * transformed box clips to the bounding box of its transformed padding box. */
69
- PaintClip clipForChildren(const LayoutBox *box, const PaintClip &parent) {
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 x = box->x + box->border_left;
72
- float y = box->y + box->border_top;
73
- float width = box->width - box->border_left - box->border_right;
74
- float height = box->height - box->border_top - box->border_bottom;
75
- if (width < 0) width = 0;
76
- if (height < 0) height = 0;
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
- return result;
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, own, viewportWidth,
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) {
@@ -254,7 +288,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
254
288
  image.height = box->content_height;
255
289
  image.canvas_id = box->canvas_id;
256
290
  image.transform = matrix;
257
- paint_detail::addImage(out, image, own, chain);
291
+ paint_detail::addImage(out, image, contentClip, chain);
258
292
  } else if (box->is_media && box->media_id != 0 && box->content_width > 0.0f &&
259
293
  box->content_height > 0.0f) {
260
294
  PaintImage image;
@@ -264,7 +298,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
264
298
  image.height = box->content_height;
265
299
  image.media_id = box->media_id;
266
300
  image.transform = matrix;
267
- paint_detail::addImage(out, image, own, chain);
301
+ paint_detail::addImage(out, image, contentClip, chain);
268
302
  } else if (box->is_inline_svg && !box->svg_markup.empty() && box->content_width > 0.0f &&
269
303
  box->content_height > 0.0f) {
270
304
  PaintImage image;
@@ -274,7 +308,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
274
308
  image.height = box->content_height;
275
309
  image.svg = box->svg_markup;
276
310
  image.transform = matrix;
277
- paint_detail::addImage(out, image, own, chain);
311
+ paint_detail::addImage(out, image, contentClip, chain);
278
312
  } else if (box->is_image && !box->image_src.empty() && box->content_width > 0.0f &&
279
313
  box->content_height > 0.0f) {
280
314
  PaintImage image;
@@ -284,7 +318,7 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
284
318
  image.height = box->content_height;
285
319
  image.src = box->image_src;
286
320
  image.transform = matrix;
287
- paint_detail::addImage(out, image, own, chain);
321
+ paint_detail::addImage(out, image, contentClip, chain);
288
322
  }
289
323
  }
290
324
  }
@@ -293,7 +327,8 @@ void paintBoxInner(const LayoutBox *box, DisplayList &out, const PaintClip &clip
293
327
  * already been emitted, so descendants must not repeat it. */
294
328
  paint_detail::FilterChain childChain = chain;
295
329
  childChain.shadows.clear();
296
- paintChildren(box, out, clipForChildren(box, own), childChain, viewportWidth, viewportHeight);
330
+ paintChildren(box, out, clipForChildren(box, own, out), childChain, viewportWidth,
331
+ viewportHeight);
297
332
  }
298
333
 
299
334
  /** Paint one box, wrapping it in a `mix-blend-mode` group when it declares one.
@@ -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`; at most
160
- * two nested `clip-path` shapes are kept (CSS would intersect every ancestor;
161
- * deeper nesting is rare and the outermost two are the ones a UI uses). */
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[2] = {-1, -1};
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
- ClipPathGeometry geometry;
242
- geometry.points.reserve(points.size() * 2);
243
- for (Point &point : points) {
244
- float x = point.x;
245
- float y = point.y;
246
- box.world.apply(point.x, point.y, &x, &y);
247
- geometry.points.push_back(x);
248
- geometry.points.push_back(y);
249
- }
250
- if (points.size() >= 3) {
251
- std::vector<Point> device;
252
- device.reserve(points.size());
253
- for (size_t i = 0; i + 1 < geometry.points.size(); i += 2)
254
- device.push_back({geometry.points[i], geometry.points[i + 1]});
255
- triangulate(device, &geometry.triangles);
256
- }
257
- out.clip_paths.push_back(std::move(geometry));
258
- return (int)(out.clip_paths.size() - 1);
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 < 2) clip.paths[clip.path_count++] = index;
318
+ if (clip.path_count < PaintClip::kMaxPaths) clip.paths[clip.path_count++] = index;
264
319
  return clip;
265
320
  }
266
321
 
@@ -107,7 +107,13 @@ bool addBackdropFilter(DisplayList &out, const LayoutBox &box, const XtStyle &st
107
107
  int addClipPathForBox(DisplayList &out, const LayoutBox &box, const XtStyle &style,
108
108
  float viewportWidth, float viewportHeight);
109
109
 
110
- /** Push `index` onto a clip chain (at most two survive). */
110
+ /** Resolve the rounded padding box an `overflow` clip uses into a device-space
111
+ * triangulated polygon, approximating each corner with short chords. The
112
+ * corners stay round after a transform because every point is mapped. */
113
+ int addRoundedClipPath(DisplayList &out, const Matrix2D &world, float x, float y, float width,
114
+ float height, float radius);
115
+
116
+ /** Push `index` onto a clip chain (at most `PaintClip::kMaxPaths` survive). */
111
117
  PaintClip addClipPath(PaintClip clip, int index);
112
118
 
113
119
  } // namespace paint_detail
@@ -10,6 +10,7 @@
10
10
  #include "renderer_internal.h"
11
11
 
12
12
  #include <algorithm>
13
+ #include <utility>
13
14
  #include <vector>
14
15
 
15
16
  namespace xtgui {
@@ -86,26 +87,27 @@ uint32_t appendClipped(std::vector<V> &out, const std::vector<V> &quad, const Pa
86
87
  appendFan(quad, &out);
87
88
  return 6;
88
89
  }
89
- const ClipPathGeometry *first = pathAt(list, clip.paths[0]);
90
- if (first == nullptr || first->triangles.empty()) return 0;
91
- uint32_t before = (uint32_t)out.size();
92
- if (clip.path_count == 1) {
93
- for (const ClipTriangle &triangle : first->triangles) {
94
- std::vector<V> clipped = clipToTriangle(quad, triangle, mix);
95
- if (clipped.size() >= 3) appendFan(clipped, &out);
96
- }
97
- } else {
98
- const ClipPathGeometry *second = pathAt(list, clip.paths[1]);
99
- if (second == nullptr || second->triangles.empty()) return 0;
100
- for (const ClipTriangle &outer : first->triangles) {
101
- std::vector<V> firstClip = clipToTriangle(quad, outer, mix);
102
- if (firstClip.size() < 3) continue;
103
- for (const ClipTriangle &inner : second->triangles) {
104
- std::vector<V> secondClip = clipToTriangle(firstClip, inner, mix);
105
- if (secondClip.size() >= 3) appendFan(secondClip, &out);
90
+ /* Start with the convex quad and clip it by every path in turn. Each path is
91
+ * a triangulated (possibly concave) polygon, so intersecting a convex piece
92
+ * with its triangles partitions it correctly; the result may be several
93
+ * convex pieces, which the next path clips independently. */
94
+ std::vector<std::vector<V>> pieces;
95
+ pieces.push_back(quad);
96
+ for (int p = 0; p < clip.path_count; p++) {
97
+ const ClipPathGeometry *path = pathAt(list, clip.paths[p]);
98
+ if (path == nullptr || path->triangles.empty()) return 0;
99
+ std::vector<std::vector<V>> next;
100
+ for (const std::vector<V> &piece : pieces) {
101
+ for (const ClipTriangle &triangle : path->triangles) {
102
+ std::vector<V> clipped = clipToTriangle(piece, triangle, mix);
103
+ if (clipped.size() >= 3) next.push_back(std::move(clipped));
106
104
  }
107
105
  }
106
+ pieces = std::move(next);
107
+ if (pieces.empty()) return 0;
108
108
  }
109
+ uint32_t before = (uint32_t)out.size();
110
+ for (const std::vector<V> &piece : pieces) appendFan(piece, &out);
109
111
  return (uint32_t)out.size() - before;
110
112
  }
111
113
 
@@ -10,6 +10,7 @@
10
10
 
11
11
  #include "css_internal.h"
12
12
  #include "perf.h"
13
+ #include "warnings.h"
13
14
 
14
15
  #include <algorithm>
15
16
  #include <cctype>
@@ -241,7 +242,9 @@ void applyCandidates(XtStyle *style, std::vector<Candidate> *candidates,
241
242
  if (xt_css_lower(value).find("current") != std::string::npos) {
242
243
  value = xt_style_replace_current_color(value, style->color);
243
244
  }
244
- xt_style_apply_declaration(style, property, value, nodeContext);
245
+ if (!xt_style_apply_declaration(style, property, value, nodeContext)) {
246
+ xt_warn_unsupported_property(property);
247
+ }
245
248
  }
246
249
  }
247
250
 
@@ -359,6 +362,7 @@ std::string resolveContent(const Node *origin, const std::string &raw, bool *gen
359
362
  }
360
363
  if (i < value.size() && value[i] == '(') {
361
364
  /* Unsupported function (`counter`, `counters`, `url`, …): skip it. */
365
+ xt_warn_unsupported_function("content", token);
362
366
  int depth = 0;
363
367
  for (; i < value.size(); i++) {
364
368
  if (value[i] == '(') depth++;
@@ -33,6 +33,8 @@ enum class AlignContent { Stretch, FlexStart, FlexEnd, Center, SpaceBetween, Spa
33
33
  enum class FloatSide { None, Left, Right };
34
34
  enum class Clear { None, Left, Right, Both };
35
35
  enum class TextAlign { Start, Center, End, Justify };
36
+ /** `text-overflow` on an overflowing line; the engine signals it with U+2026. */
37
+ enum class TextOverflow { Clip, Ellipsis };
36
38
  enum class WhiteSpace { Normal, NoWrap, Pre, PreWrap, PreLine };
37
39
  enum class Overflow { Visible, Hidden, Scroll, Auto };
38
40
  enum class BorderStyle { None, Solid, Dashed, Dotted };
@@ -304,6 +306,9 @@ struct XtStyle {
304
306
  Length line_height; // Auto = normal; Number = multiplier
305
307
 
306
308
  TextAlign text_align = TextAlign::Start; // inherited
309
+ /** `text-overflow`; not inherited. Only meaningful when the box clips
310
+ * (`overflow` other than `visible`). */
311
+ TextOverflow text_overflow = TextOverflow::Clip;
307
312
  WhiteSpace white_space = WhiteSpace::Normal; // inherited
308
313
  TextTransform text_transform = TextTransform::None; // inherited
309
314
  /** Resolved to pixels in the cascade (em is the element's own font size). */
@@ -18,6 +18,8 @@ void xt_style_apply_inherit(XtStyle *style, const XtStyle *parent, const std::st
18
18
  if (parent == nullptr) return;
19
19
  if (property == "color") {
20
20
  style->color = parent->color;
21
+ } else if (property == "text-overflow") {
22
+ style->text_overflow = parent->text_overflow;
21
23
  } else if (property == "clip-path") {
22
24
  style->clip_path = parent->clip_path;
23
25
  } else if (property == "font") {
@@ -36,8 +36,13 @@ void xt_style_apply_user_agent(const Node *node, XtStyle *style);
36
36
  float xt_style_border_radius_px(const Length &radius, float width, float height, float em,
37
37
  float root, float vw, float vh);
38
38
 
39
- /** Apply a parsed declaration to a computed style. */
40
- void xt_style_apply_declaration(XtStyle *style, const std::string &property,
39
+ /** Apply a parsed declaration to a computed style.
40
+ *
41
+ * Returns false only when the *property name* is not part of the engine's
42
+ * subset; a recognised property with an unparsable value returns true (the
43
+ * declaration is simply a no-op), so callers can warn about unknown properties
44
+ * without mistaking bad values for unsupported ones. */
45
+ bool xt_style_apply_declaration(XtStyle *style, const std::string &property,
41
46
  const std::string &rawValue, const ApplyContext &context);
42
47
 
43
48
  } // namespace xtgui
@@ -274,6 +274,9 @@ std::string xt_style_property_to_string(const XtStyle &style, const std::string
274
274
  }
275
275
  if (property == "text-align") return alignTextNames[(int)style.text_align];
276
276
  if (property == "text-transform") return textTransformNames[(int)style.text_transform];
277
+ if (property == "text-overflow") {
278
+ return style.text_overflow == TextOverflow::Ellipsis ? "ellipsis" : "clip";
279
+ }
277
280
  if (property == "letter-spacing") return formatLength(style.letter_spacing);
278
281
  if (property == "writing-mode") return writingModeNames[(int)style.writing_mode];
279
282
  if (property == "vertical-align") return formatLength(style.vertical_align);