mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
LibWeb: Support transforms, stroking, gradients, etc for SVG <text>
This makes use of the new Gfx::Path::text() to handle SVG text elements, with this text is just a regular path, and can be manipulated like any other graphics element. This removes the SVGTextPaintable and makes both <text> and geometry elements use a new (shared) SVGPathPaintable. This is identical to the old SVGGeometryPaintable. This simplifies painting as once something is resolved to a Gfx::Path, the painting logic is the same.
This commit is contained in:
parent
50d33f79fa
commit
4c5d48f861
Notes:
sideshowbarker
2024-07-17 06:51:10 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/4c5d48f861 Pull-request: https://github.com/SerenityOS/serenity/pull/21785 Reviewed-by: https://github.com/kalenikaliaksandr ✅
@ -9,7 +9,7 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
frag 2 from Box start: 0, length: 0, rect: [319,51 0x108]
|
||||
SVGSVGBox <svg> at (9,9) content-size 300x150 [SVG] children: inline
|
||||
InlineNode <a>
|
||||
SVGTextBox <text> at (29,9) content-size 198.90625x80 children: inline
|
||||
SVGTextBox <text> at (29,25.015625) content-size 193.59375x67.578125 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
Box <math> at (319,51) content-size 0x108 children: not-inline
|
||||
|
@ -8,4 +8,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x100]
|
||||
PaintableBox (Box<BODY>) [0,0 800x100]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [0,0 200x100]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [0,0 200x100]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [0,0 200x100]
|
||||
|
@ -8,4 +8,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x16]
|
||||
PaintableBox (Box<BODY>) [8,8 784x0]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [400,8 0x0]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [400,8 0x0]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [400,8 0x0]
|
||||
|
@ -108,39 +108,39 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x257.46875]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [34,84 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [34,84 50x50]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [118,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [119,84 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [119,84 50x50]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [228,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [279,84 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [279,84 50x50]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [338,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [339,84 100x100]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [339,84 100x100]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [448,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [449,59 100x100]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [449,59 100x100]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [558,83 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [559,34 100x100]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [559,34 100x100]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [668,8 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [669,9 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [669,9 50x50]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [728,8 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [729,46.5 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [729,46.5 50x50]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,135 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [9,211 50x50]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [9,211 50x50]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [68,135 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [69,136 125x125]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [69,136 125x125]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [128,135 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [91.5,136 125x125]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [91.5,136 125x125]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [188,135 52x127]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [114,136 125x125]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [114,136 125x125]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [248,200 162x62]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [299,201 60x60]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [299,201 60x60]
|
||||
|
@ -6,16 +6,16 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
SVGSVGBox <svg> at (8,8) content-size 784x261.328125 [SVG] children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.small> at (73.34375,79.859375) content-size 50.265625x42.46875 children: inline
|
||||
SVGTextBox <text.small> at (73.34375,88.359375) content-size 48.109375x37.484375 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.heavy> at (138.6875,24.328125) content-size 153.703125x98 children: inline
|
||||
SVGTextBox <text.heavy> at (138.6875,43.953125) content-size 148.234375x79.71875 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.small> at (187.671875,145.1875) content-size 36.90625x42.46875 children: inline
|
||||
SVGTextBox <text.small> at (187.671875,153.703125) content-size 34.59375x34.703125 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.Rrrrr> at (220.34375,57) content-size 526.609375x130.65625 children: inline
|
||||
SVGTextBox <text.Rrrrr> at (220.34375,83.15625) content-size 519.34375x115.359375 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
@ -24,7 +24,7 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x261.328125]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x261.328125]
|
||||
SVGTextPaintable (SVGTextBox<text>.small) [73.34375,79.859375 50.265625x42.46875]
|
||||
SVGTextPaintable (SVGTextBox<text>.heavy) [138.6875,24.328125 153.703125x98]
|
||||
SVGTextPaintable (SVGTextBox<text>.small) [187.671875,145.1875 36.90625x42.46875]
|
||||
SVGTextPaintable (SVGTextBox<text>.Rrrrr) [220.34375,57 526.609375x130.65625]
|
||||
SVGPathPaintable (SVGTextBox<text>.small) [73.34375,88.359375 48.109375x37.484375]
|
||||
SVGPathPaintable (SVGTextBox<text>.heavy) [138.6875,43.953125 148.234375x79.71875]
|
||||
SVGPathPaintable (SVGTextBox<text>.small) [187.671875,153.703125 34.59375x34.703125]
|
||||
SVGPathPaintable (SVGTextBox<text>.Rrrrr) [220.34375,83.15625 519.34375x115.359375]
|
||||
|
@ -100,33 +100,33 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x700]
|
||||
PaintableWithLines (BlockContainer<BODY>) [50,50 700x600]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [50,150 200x100]
|
||||
SVGGraphicsPaintable (SVGGraphicsBox<g>) [45.6875,199.828125 118.78125x47.453125]
|
||||
SVGGeometryPaintable (SVGGeometryBox<path>) [45.6875,199.828125 118.78125x47.453125]
|
||||
SVGPathPaintable (SVGGeometryBox<path>) [45.6875,199.828125 118.78125x47.453125]
|
||||
SVGGraphicsPaintable (SVGGraphicsBox<g>) [84.5,159.5 81x81]
|
||||
SVGGeometryPaintable (SVGGeometryBox<path>) [84.5,159.5 81x81]
|
||||
SVGPathPaintable (SVGGeometryBox<path>) [84.5,159.5 81x81]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [258,50 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [268,60 30x20]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [288,130 110x90]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [268,60 30x20]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [288,130 110x90]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [466,50 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [506,90 120x120]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [471.359375,90 189.28125x120]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [506,90 120x120]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [471.359375,90 189.28125x120]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [50,250 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [120.59375,320.59375 58.828125x58.828125]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [52.4375,310.375 68.140625x68.140625]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [179.40625,321.484375 68.140625x68.140625]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [120.59375,320.59375 58.828125x58.828125]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [52.4375,310.375 68.140625x68.140625]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [179.40625,321.484375 68.140625x68.140625]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [258,250 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [278,270 160x160]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [338,270 40x160]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [278,330 160x40]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [338,330 40x40]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [278,270 160x160]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [338,270 40x160]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [278,330 160x40]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [338,330 40x40]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [466,250 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [506,290 120x120]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [506,255.359375 120x189.28125]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [506,290 120x120]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [506,255.359375 120x189.28125]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [50,450 200x200]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [60,460 80x80]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [160,460 80x80]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [60,560 80x80]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [160,560 80x80]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [60,460 80x80]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [160,460 80x80]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [60,560 80x80]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [160,560 80x80]
|
||||
|
@ -13,4 +13,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x784]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x784]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [47.1875,47.1875 548.796875x548.796875]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [47.1875,47.1875 548.796875x548.796875]
|
||||
|
@ -10,4 +10,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x784]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x784]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [8,8 784x784]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [8,8 784x784]
|
||||
|
@ -19,5 +19,5 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x784]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x784]
|
||||
SVGGraphicsPaintable (SVGGraphicsBox<g>) [121.671875,121.671875 556.65625x556.65625]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [121.671875,121.671875 399.84375x399.84375]
|
||||
SVGGeometryPaintable (SVGGeometryBox<circle>) [278.484375,278.484375 399.84375x399.84375]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [121.671875,121.671875 399.84375x399.84375]
|
||||
SVGPathPaintable (SVGGeometryBox<circle>) [278.484375,278.484375 399.84375x399.84375]
|
||||
|
@ -15,4 +15,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 24x24]
|
||||
SVGGraphicsPaintable (SVGGraphicsBox<g>) [8,8 24x24]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 24x24]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [8,8 24x24]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [8,8 24x24]
|
||||
|
@ -10,6 +10,6 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x170]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x154]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 102x52]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [21.5,21.5 75x25]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [21.5,21.5 75x25]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,60 202x102]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [34,86 150x50]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [34,86 150x50]
|
||||
|
@ -10,4 +10,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x116]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x100]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 100x100]
|
||||
SVGGeometryPaintable (SVGGeometryBox<path>) [8,10 100x48]
|
||||
SVGPathPaintable (SVGGeometryBox<path>) [8,10 100x48]
|
||||
|
@ -10,4 +10,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x116]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x100]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 100x100]
|
||||
SVGGeometryPaintable (SVGGeometryBox<path>) [28,28 60x60]
|
||||
SVGPathPaintable (SVGGeometryBox<path>) [28,28 60x60]
|
||||
|
@ -27,4 +27,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
|
||||
PaintableBox (Box<use>) [8,8 0x0]
|
||||
PaintableBox (Box<symbol>#braces) [8,8 0x0]
|
||||
SVGGeometryPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]
|
||||
SVGPathPaintable (SVGGeometryBox<path>) [92.375,26.75 131.25x112.15625]
|
||||
|
@ -10,4 +10,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x118]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x102]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 102x102]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [29,29 60x60]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [29,29 60x60]
|
||||
|
@ -8,4 +8,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600] overflow: [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x800]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x784]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 784x784]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [8,8 784x784]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [8,8 784x784]
|
||||
|
@ -26,4 +26,4 @@ ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
ImagePaintable (ImageBox<IMG>) [8,21 0x0]
|
||||
TextPaintable (TextNode<#text>)
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [16,21 0x0]
|
||||
SVGGeometryPaintable (SVGGeometryBox<rect>) [16,21 1x1]
|
||||
SVGPathPaintable (SVGGeometryBox<rect>) [16,21 1x1]
|
||||
|
@ -4,11 +4,11 @@ Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
line 0 width: 300, height: 150, bottom: 150, baseline: 150
|
||||
frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 300x150]
|
||||
SVGSVGBox <svg> at (8,8) content-size 300x150 [SVG] children: not-inline
|
||||
SVGTextBox <text> at (8,-8) content-size 0x16 children: not-inline
|
||||
SVGTextBox <text> at (8,8) content-size 0x0 children: not-inline
|
||||
TextNode <#text>
|
||||
|
||||
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<HTML>) [0,0 800x600]
|
||||
PaintableWithLines (BlockContainer<BODY>) [8,8 784x150]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150] overflow: [8,-8 300x166]
|
||||
SVGTextPaintable (SVGTextBox<text>) [8,-8 0x16]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150]
|
||||
SVGPathPaintable (SVGTextBox<text>) [8,8 0x0]
|
||||
|
BIN
Tests/LibWeb/Ref/reference/images/svg-text-effects-ref.png
Normal file
BIN
Tests/LibWeb/Ref/reference/images/svg-text-effects-ref.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
15
Tests/LibWeb/Ref/reference/svg-text-effects-ref.html
Normal file
15
Tests/LibWeb/Ref/reference/svg-text-effects-ref.html
Normal file
@ -0,0 +1,15 @@
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
}
|
||||
body {
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
<!-- To rebase:
|
||||
1. Open svg-text-effects.html in Ladybird
|
||||
2. Resize the window till there's x and y scrollbars
|
||||
3. Right click > "Take Full Screenshot"
|
||||
4. Update the image below:
|
||||
-->
|
||||
<img src="./images/svg-text-effects-ref.png">
|
31
Tests/LibWeb/Ref/svg-text-effects.html
Normal file
31
Tests/LibWeb/Ref/svg-text-effects.html
Normal file
@ -0,0 +1,31 @@
|
||||
<link rel="match" href="reference/svg-text-effects-ref.html" />
|
||||
<svg height="200" width="350" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.text {
|
||||
font: italic 40px serif;
|
||||
}
|
||||
|
||||
.thakis {
|
||||
font: bold 70px sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: white;
|
||||
}
|
||||
</style>
|
||||
<linearGradient id="gradient">
|
||||
<stop offset="0%" stop-color="rgba(255, 0, 0, 1)"/>
|
||||
<stop offset="10%" stop-color="rgba(255, 154, 0, 1)"/>
|
||||
<stop offset="20%" stop-color="rgba(208, 222, 33, 1)"/>
|
||||
<stop offset="30%" stop-color="rgba(79, 220, 74, 1)"/>
|
||||
<stop offset="40%" stop-color="rgba(63, 218, 216, 1)"/>
|
||||
<stop offset="50%" stop-color="rgba(47, 201, 226, 1)"/>
|
||||
<stop offset="60%" stop-color="rgba(28, 127, 238, 1)"/>
|
||||
<stop offset="70%" stop-color="rgba(95, 21, 242, 1)"/>
|
||||
<stop offset="80%" stop-color="rgba(186, 12, 248, 1)"/>
|
||||
<stop offset="90%" stop-color="rgba(251, 7, 217, 1)"/>
|
||||
<stop offset="100%" stop-color="rgba(255, 0, 0, 1)"/>
|
||||
</linearGradient>
|
||||
<text x="20" y="105" class="text" transform="rotate(-10 50 100)">There you go :^)</text>
|
||||
<text x="90" y="220" class="thakis" fill="url(#gradient)" transform="rotate(-10 50 100) skewY(-10)">thakis</text>
|
||||
</svg>
|
@ -491,11 +491,10 @@ set(SOURCES
|
||||
Painting/ProgressPaintable.cpp
|
||||
Painting/RadioButtonPaintable.cpp
|
||||
Painting/RecordingPainter.cpp
|
||||
Painting/SVGGeometryPaintable.cpp
|
||||
Painting/SVGPathPaintable.cpp
|
||||
Painting/SVGGraphicsPaintable.cpp
|
||||
Painting/SVGPaintable.cpp
|
||||
Painting/SVGSVGPaintable.cpp
|
||||
Painting/SVGTextPaintable.cpp
|
||||
Painting/ShadowPainting.cpp
|
||||
Painting/StackingContext.cpp
|
||||
Painting/TableBordersPainting.cpp
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include <LibWeb/Layout/LayoutState.h>
|
||||
#include <LibWeb/Layout/TextNode.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
#include <LibWeb/Painting/SVGGeometryPaintable.h>
|
||||
#include <LibWeb/Painting/SVGPathPaintable.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
|
||||
@ -272,8 +272,8 @@ void LayoutState::commit(Box& root)
|
||||
svg_graphics_paintable.set_computed_transforms(*used_values.computed_svg_transforms());
|
||||
}
|
||||
|
||||
if (used_values.computed_svg_path().has_value() && is<Painting::SVGGeometryPaintable>(paintable_box)) {
|
||||
auto& svg_geometry_paintable = static_cast<Painting::SVGGeometryPaintable&>(paintable_box);
|
||||
if (used_values.computed_svg_path().has_value() && is<Painting::SVGPathPaintable>(paintable_box)) {
|
||||
auto& svg_geometry_paintable = static_cast<Painting::SVGPathPaintable&>(paintable_box);
|
||||
svg_geometry_paintable.set_computed_path(move(*used_values.computed_svg_path()));
|
||||
}
|
||||
}
|
||||
|
@ -196,27 +196,20 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
||||
graphics_box_state.set_computed_svg_transforms(Painting::SVGGraphicsPaintable::ComputedTransforms(viewbox_transform, svg_transform));
|
||||
auto to_css_pixels_transform = Gfx::AffineTransform {}.multiply(viewbox_transform).multiply(svg_transform);
|
||||
|
||||
Gfx::Path path;
|
||||
if (is<SVGGeometryBox>(descendant)) {
|
||||
auto path = static_cast<SVG::SVGGeometryElement&>(dom_node).get_path();
|
||||
auto path_bounding_box = to_css_pixels_transform.map(path.bounding_box()).to_type<CSSPixels>();
|
||||
// Stroke increases the path's size by stroke_width/2 per side.
|
||||
CSSPixels stroke_width = CSSPixels::nearest_value_for(graphics_box.dom_node().visible_stroke_width() * viewbox_transform.x_scale());
|
||||
path_bounding_box.inflate(stroke_width, stroke_width);
|
||||
graphics_box_state.set_content_offset(path_bounding_box.top_left());
|
||||
graphics_box_state.set_content_width(path_bounding_box.width());
|
||||
graphics_box_state.set_content_height(path_bounding_box.height());
|
||||
graphics_box_state.set_computed_svg_path(move(path));
|
||||
path = static_cast<SVG::SVGGeometryElement&>(dom_node).get_path();
|
||||
} else if (is<SVGTextBox>(descendant)) {
|
||||
auto& text_element = static_cast<SVG::SVGTextPositioningElement&>(dom_node);
|
||||
|
||||
// FIXME: Support arbitrary path transforms for fonts.
|
||||
// FIMXE: This assumes transform->x_scale() == transform->y_scale().
|
||||
auto& scaled_font = graphics_box.scaled_font(to_css_pixels_transform.x_scale());
|
||||
auto& font = graphics_box.font();
|
||||
auto text_contents = text_element.text_contents();
|
||||
Utf8View text_utf8 { text_contents };
|
||||
auto text_width = font.width(text_utf8);
|
||||
|
||||
auto text_offset = text_element.get_offset().transformed(to_css_pixels_transform).to_type<CSSPixels>();
|
||||
auto text_width = CSSPixels::nearest_value_for(scaled_font.width(Utf8View { text_contents }));
|
||||
|
||||
auto text_offset = text_element.get_offset();
|
||||
// https://svgwg.org/svg2-draft/text.html#TextAnchoringProperties
|
||||
switch (text_element.text_anchor().value_or(SVG::TextAnchor::Start)) {
|
||||
case SVG::TextAnchor::Start:
|
||||
@ -240,11 +233,18 @@ void SVGFormattingContext::run(Box const& box, LayoutMode layout_mode, Available
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
auto text_height = CSSPixels::nearest_value_for(scaled_font.pixel_size());
|
||||
graphics_box_state.set_content_offset(text_offset.translated(0, -text_height));
|
||||
graphics_box_state.set_content_width(text_width);
|
||||
graphics_box_state.set_content_height(text_height);
|
||||
path.move_to(text_offset);
|
||||
path.text(text_utf8, font);
|
||||
}
|
||||
|
||||
auto path_bounding_box = to_css_pixels_transform.map(path.bounding_box()).to_type<CSSPixels>();
|
||||
// Stroke increases the path's size by stroke_width/2 per side.
|
||||
CSSPixels stroke_width = CSSPixels::nearest_value_for(graphics_box.dom_node().visible_stroke_width() * viewbox_transform.x_scale());
|
||||
path_bounding_box.inflate(stroke_width, stroke_width);
|
||||
graphics_box_state.set_content_offset(path_bounding_box.top_left());
|
||||
graphics_box_state.set_content_width(path_bounding_box.width());
|
||||
graphics_box_state.set_content_height(path_bounding_box.height());
|
||||
graphics_box_state.set_computed_svg_path(move(path));
|
||||
} else if (is<SVGSVGBox>(descendant)) {
|
||||
SVGFormattingContext nested_context(m_state, static_cast<SVGSVGBox const&>(descendant), this);
|
||||
nested_context.run(static_cast<SVGSVGBox const&>(descendant), layout_mode, available_space);
|
||||
|
@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <LibWeb/Layout/SVGGeometryBox.h>
|
||||
#include <LibWeb/Painting/SVGGeometryPaintable.h>
|
||||
#include <LibWeb/Painting/SVGPathPaintable.h>
|
||||
#include <LibWeb/SVG/SVGPathElement.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
@ -19,7 +19,7 @@ SVGGeometryBox::SVGGeometryBox(DOM::Document& document, SVG::SVGGeometryElement&
|
||||
|
||||
JS::GCPtr<Painting::Paintable> SVGGeometryBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGGeometryPaintable::create(*this);
|
||||
return Painting::SVGPathPaintable::create(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
#include <LibWeb/Layout/SVGTextBox.h>
|
||||
#include <LibWeb/Painting/SVGTextPaintable.h>
|
||||
#include <LibWeb/Painting/SVGPathPaintable.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
namespace Web::Layout {
|
||||
@ -17,7 +17,7 @@ SVGTextBox::SVGTextBox(DOM::Document& document, SVG::SVGTextPositioningElement&
|
||||
|
||||
JS::GCPtr<Painting::Paintable> SVGTextBox::create_paintable() const
|
||||
{
|
||||
return Painting::SVGTextPaintable::create(*this);
|
||||
return Painting::SVGPathPaintable::create(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,27 +6,27 @@
|
||||
*/
|
||||
|
||||
#include <LibGfx/AntiAliasingPainter.h>
|
||||
#include <LibWeb/Painting/SVGGeometryPaintable.h>
|
||||
#include <LibWeb/Painting/SVGPathPaintable.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
JS::NonnullGCPtr<SVGGeometryPaintable> SVGGeometryPaintable::create(Layout::SVGGeometryBox const& layout_box)
|
||||
JS::NonnullGCPtr<SVGPathPaintable> SVGPathPaintable::create(Layout::SVGGraphicsBox const& layout_box)
|
||||
{
|
||||
return layout_box.heap().allocate_without_realm<SVGGeometryPaintable>(layout_box);
|
||||
return layout_box.heap().allocate_without_realm<SVGPathPaintable>(layout_box);
|
||||
}
|
||||
|
||||
SVGGeometryPaintable::SVGGeometryPaintable(Layout::SVGGeometryBox const& layout_box)
|
||||
SVGPathPaintable::SVGPathPaintable(Layout::SVGGraphicsBox const& layout_box)
|
||||
: SVGGraphicsPaintable(layout_box)
|
||||
{
|
||||
}
|
||||
|
||||
Layout::SVGGeometryBox const& SVGGeometryPaintable::layout_box() const
|
||||
Layout::SVGGraphicsBox const& SVGPathPaintable::layout_box() const
|
||||
{
|
||||
return static_cast<Layout::SVGGeometryBox const&>(layout_node());
|
||||
return static_cast<Layout::SVGGraphicsBox const&>(layout_node());
|
||||
}
|
||||
|
||||
Optional<HitTestResult> SVGGeometryPaintable::hit_test(CSSPixelPoint position, HitTestType type) const
|
||||
Optional<HitTestResult> SVGPathPaintable::hit_test(CSSPixelPoint position, HitTestType type) const
|
||||
{
|
||||
auto result = SVGGraphicsPaintable::hit_test(position, type);
|
||||
if (!result.has_value() || !computed_path().has_value())
|
||||
@ -49,7 +49,7 @@ static Gfx::Painter::WindingRule to_gfx_winding_rule(SVG::FillRule fill_rule)
|
||||
}
|
||||
}
|
||||
|
||||
void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
void SVGPathPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
{
|
||||
if (!is_visible() || !computed_path().has_value())
|
||||
return;
|
@ -6,22 +6,22 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Layout/SVGGeometryBox.h>
|
||||
#include <LibWeb/Layout/SVGGraphicsBox.h>
|
||||
#include <LibWeb/Painting/SVGGraphicsPaintable.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
class SVGGeometryPaintable final : public SVGGraphicsPaintable {
|
||||
JS_CELL(SVGGeometryPaintable, SVGGraphicsPaintable);
|
||||
class SVGPathPaintable final : public SVGGraphicsPaintable {
|
||||
JS_CELL(SVGPathPaintable, SVGGraphicsPaintable);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
||||
static JS::NonnullGCPtr<SVGPathPaintable> create(Layout::SVGGraphicsBox const&);
|
||||
|
||||
virtual Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const override;
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
Layout::SVGGeometryBox const& layout_box() const;
|
||||
Layout::SVGGraphicsBox const& layout_box() const;
|
||||
|
||||
void set_computed_path(Gfx::Path path)
|
||||
{
|
||||
@ -31,7 +31,7 @@ public:
|
||||
Optional<Gfx::Path> const& computed_path() const { return m_computed_path; }
|
||||
|
||||
protected:
|
||||
SVGGeometryPaintable(Layout::SVGGeometryBox const&);
|
||||
SVGPathPaintable(Layout::SVGGraphicsBox const&);
|
||||
|
||||
Optional<Gfx::Path> m_computed_path = {};
|
||||
};
|
@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Painting/SVGTextPaintable.h>
|
||||
#include <LibWeb/SVG/SVGSVGElement.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
JS::NonnullGCPtr<SVGTextPaintable> SVGTextPaintable::create(Layout::SVGTextBox const& layout_box)
|
||||
{
|
||||
return layout_box.heap().allocate_without_realm<SVGTextPaintable>(layout_box);
|
||||
}
|
||||
|
||||
SVGTextPaintable::SVGTextPaintable(Layout::SVGTextBox const& layout_box)
|
||||
: SVGGraphicsPaintable(layout_box)
|
||||
{
|
||||
}
|
||||
|
||||
void SVGTextPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||
{
|
||||
if (!is_visible())
|
||||
return;
|
||||
|
||||
if (!layout_node().computed_values().fill().has_value())
|
||||
return;
|
||||
|
||||
if (layout_node().computed_values().fill()->is_url()) {
|
||||
dbgln("FIXME: Using url() as fill is not supported for svg text");
|
||||
return;
|
||||
}
|
||||
|
||||
SVGGraphicsPaintable::paint(context, phase);
|
||||
|
||||
if (phase != PaintPhase::Foreground)
|
||||
return;
|
||||
|
||||
auto& painter = context.painter();
|
||||
auto const& dom_node = layout_box().dom_node();
|
||||
auto paint_transform = computed_transforms().svg_to_device_pixels_transform(context);
|
||||
auto& scaled_font = layout_box().scaled_font(paint_transform.x_scale());
|
||||
auto text_rect = context.enclosing_device_rect(absolute_rect()).to_type<int>();
|
||||
auto text_contents = dom_node.text_contents();
|
||||
|
||||
painter.draw_text_run(text_rect.bottom_left(), Utf8View { text_contents }, scaled_font, layout_node().computed_values().fill()->as_color(), text_rect);
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Layout/SVGTextBox.h>
|
||||
#include <LibWeb/Painting/SVGGraphicsPaintable.h>
|
||||
|
||||
namespace Web::Painting {
|
||||
|
||||
class SVGTextPaintable final : public SVGGraphicsPaintable {
|
||||
JS_CELL(SVGTextPaintable, SVGGraphicsPaintable);
|
||||
|
||||
public:
|
||||
static JS::NonnullGCPtr<SVGTextPaintable> create(Layout::SVGTextBox const&);
|
||||
|
||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||
|
||||
Layout::SVGTextBox const& layout_box() const
|
||||
{
|
||||
return static_cast<Layout::SVGTextBox const&>(layout_node());
|
||||
}
|
||||
|
||||
protected:
|
||||
SVGTextPaintable(Layout::SVGTextBox const&);
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user