mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27:45 +00:00
LibWeb: Layout SVG <text> elements during layout (not while painting)
Previously, all SVG <text> elements were zero-sized boxes, that were only actually positioned and sized during painting. This led to a number of problems, the most visible of which being that text could not be scaled based on the viewBox. Which this patch, <text> elements get a correctly sized layout box, that can be hit-tested and respects the SVG viewBox. To share code with SVGGeometryElement's the PathData (from the prior commit) has been split into a computed path and computed transforms. The computed path is specific to geometry elements, but the computed transforms are shared between all SVG graphics elements.
This commit is contained in:
parent
dc9cb449b1
commit
c93d367d95
16 changed files with 209 additions and 173 deletions
|
@ -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 (9,9) content-size 0x0 children: inline
|
||||
SVGTextBox <text> at (29,9) content-size 198.90625x80 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
Box <math> at (319,51) content-size 0x108 children: not-inline
|
||||
|
|
30
Tests/LibWeb/Layout/expected/svg-text-with-viewbox.txt
Normal file
30
Tests/LibWeb/Layout/expected/svg-text-with-viewbox.txt
Normal file
|
@ -0,0 +1,30 @@
|
|||
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||
BlockContainer <html> at (0,0) content-size 800x600 [BFC] children: not-inline
|
||||
BlockContainer <body> at (8,8) content-size 784x261.328125 children: inline
|
||||
line 0 width: 784, height: 261.328125, bottom: 261.328125, baseline: 261.328125
|
||||
frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 784x261.328125]
|
||||
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
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.heavy> at (138.6875,24.328125) content-size 153.703125x98 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.small> at (187.671875,145.1875) content-size 36.90625x42.46875 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
SVGTextBox <text.Rrrrr> at (220.34375,57) content-size 526.609375x130.65625 children: inline
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
TextNode <#text>
|
||||
|
||||
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]
|
|
@ -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 0x0 children: not-inline
|
||||
SVGTextBox <text> at (8,-8) content-size 0x16 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]
|
||||
SVGTextPaintable (SVGTextBox<text>) [8,8 0x0]
|
||||
SVGSVGPaintable (SVGSVGBox<svg>) [8,8 300x150] overflow: [8,-8 300x166]
|
||||
SVGTextPaintable (SVGTextBox<text>) [8,-8 0x16]
|
||||
|
|
20
Tests/LibWeb/Layout/input/svg-text-with-viewbox.html
Normal file
20
Tests/LibWeb/Layout/input/svg-text-with-viewbox.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
<svg viewBox="0 0 240 80" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.small {
|
||||
font: italic 13px sans-serif;
|
||||
}
|
||||
.heavy {
|
||||
font: bold 30px sans-serif;
|
||||
}
|
||||
|
||||
.Rrrrr {
|
||||
font: italic 40px serif;
|
||||
fill: red;
|
||||
}
|
||||
</style>
|
||||
|
||||
<text x="20" y="35" class="small">My</text>
|
||||
<text x="40" y="35" class="heavy">cat</text>
|
||||
<text x="55" y="55" class="small">is</text>
|
||||
<text x="65" y="55" class="Rrrrr">Grumpy!</text>
|
||||
</svg>
|
After Width: | Height: | Size: 457 B |
Loading…
Add table
Add a link
Reference in a new issue