jwmcglynn / donner

[new!] Donner, a modern C++20 SVG2 rendering API with CSS3
https://jwmcglynn.github.io/donner/
ISC License
13 stars 1 forks source link

`<mask>` support #186

Open jwmcglynn opened 2 months ago

jwmcglynn commented 2 months ago

See https://drafts.fxtf.org/css-masking-1/#MaskElement

This enables masking with graphical objects instead of pure clip paths.

jwmcglynn commented 1 month ago

✨✨ Here's an AI-assisted sketch of how you might approach this issue saved by @jwmcglynn using Copilot Workspace v0.22

Topic
Does the code support masking with graphical objects as specified in the CSS Masking Module Level 1?
Before
* No, the code does not support masking with graphical objects as specified in the CSS Masking Module Level 1. * The code includes support for clip paths, as seen in `donner/svg/SVGClipPathElement.h` and `donner/svg/SVGClipPathElement.cc`. * The `clipPathUnits` attribute is implemented in `donner/svg/core/ClipPathUnits.h`. * The `clip-rule` property is implemented in `donner/svg/core/ClipRule.h`. * There is no implementation for the `` element or its attributes in the codebase. * The rendering code in `donner/svg/renderer/RendererSkia.cc` does not handle masking with graphical objects. * Tests in `donner/svg/tests/SVGClipPathElement_tests.cc` focus on clip paths and do not cover masking with graphical objects.
After
* Yes, the code now supports masking with graphical objects as specified in the CSS Masking Module Level 1. * Added support for the `` element and its attributes in `donner/svg/SVGMaskElement.h` and `donner/svg/SVGMaskElement.cc`. » Details of the attributes supported. * Updated `donner/svg/AllSVGElements.h` to include `SVGMaskElement`. * Updated `donner/svg/renderer/RendererSkia.cc` to handle masking with graphical objects. * Added tests in `donner/svg/tests/SVGMaskElement_tests.cc` to cover masking with graphical objects.
Plan
* `donner/svg/AllSVGElements.h` (CHANGE) - Add `SVGMaskElement` to the include list - Add `SVGMaskElement` to the `AllSVGElements` list * `donner/svg/BUILD` (CHANGE) - Add `SVGMaskElement.cc` to `srcs` - Add `SVGMaskElement.h` to `hdrs` * `donner/svg/components/paint/MaskComponent.h` (ADD) - Define `MaskComponent` struct with `maskUnits` and `maskContentUnits` attributes * `donner/svg/renderer/RendererSkia.cc` (CHANGE) - Update `draw` method to handle `mask` attribute on elements - Add logic to apply masks in the rendering process * `donner/svg/SVGMaskElement.h` (ADD) - Define `SVGMaskElement` class with `maskUnits` and `maskContentUnits` attributes - Implement `Create`, `maskUnits`, and `setMaskUnits` methods * `donner/svg/SVGMaskElement.cc` (ADD) - Implement methods defined in `SVGMaskElement.h` * `donner/svg/tests/SVGMaskElement_tests.cc` (ADD) - Add tests for creating `SVGMaskElement` instances - Add tests for `maskUnits` and `maskContentUnits` attributes - Add rendering tests for masked elements
Sketch of implementation
[View the changes](https://copilot-workspace.githubnext.com/jwmcglynn/donner/issues/186?shareId=f2e8a310-fdbd-4c4b-8eab-8901c1bb39bb)
Details
Code analyzed at 9878cefd89604c21da666d348ae5084c30576e15