diff --git a/Tests/LibWeb/Layout/expected/svg/svg-line-with-percentage-values.txt b/Tests/LibWeb/Layout/expected/svg/svg-line-with-percentage-values.txt new file mode 100644 index 00000000000..28c08470301 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/svg-line-with-percentage-values.txt @@ -0,0 +1,23 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x408 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x392 children: inline + frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 784x392] baseline: 392 + SVGSVGBox at (8,8) content-size 784x392 [SVG] children: inline + TextNode <#text> + SVGGeometryBox at (6.046875,135.40625) content-size 787.921875x3.921875 children: not-inline + TextNode <#text> + SVGGeometryBox at (6.046875,264.765625) content-size 787.921875x3.921875 children: not-inline + TextNode <#text> + SVGGeometryBox at (264.765625,6.046875) content-size 3.921875x395.921875 children: not-inline + TextNode <#text> + SVGGeometryBox at (523.484375,6.046875) content-size 3.921875x395.921875 children: not-inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x408] + PaintableWithLines (BlockContainer) [8,8 784x392] + SVGSVGPaintable (SVGSVGBox) [8,8 784x392] + SVGPathPaintable (SVGGeometryBox) [6.046875,135.40625 787.921875x3.921875] + SVGPathPaintable (SVGGeometryBox) [6.046875,264.765625 787.921875x3.921875] + SVGPathPaintable (SVGGeometryBox) [264.765625,6.046875 3.921875x395.921875] + SVGPathPaintable (SVGGeometryBox) [523.484375,6.046875 3.921875x395.921875] diff --git a/Tests/LibWeb/Layout/input/svg/svg-line-with-percentage-values.html b/Tests/LibWeb/Layout/input/svg/svg-line-with-percentage-values.html new file mode 100644 index 00000000000..6a6697273a3 --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/svg-line-with-percentage-values.html @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp index 55e76d80ea2..7c4a04f330d 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp +++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.cpp @@ -30,23 +30,26 @@ void SVGLineElement::attribute_changed(FlyString const& name, Optional c SVGGeometryElement::attribute_changed(name, old_value, value); if (name == SVG::AttributeNames::x1) { - m_x1 = AttributeParser::parse_coordinate(value.value_or(String {})); + m_x1 = AttributeParser::parse_number_percentage(value.value_or(String {})); } else if (name == SVG::AttributeNames::y1) { - m_y1 = AttributeParser::parse_coordinate(value.value_or(String {})); + m_y1 = AttributeParser::parse_number_percentage(value.value_or(String {})); } else if (name == SVG::AttributeNames::x2) { - m_x2 = AttributeParser::parse_coordinate(value.value_or(String {})); + m_x2 = AttributeParser::parse_number_percentage(value.value_or(String {})); } else if (name == SVG::AttributeNames::y2) { - m_y2 = AttributeParser::parse_coordinate(value.value_or(String {})); + m_y2 = AttributeParser::parse_number_percentage(value.value_or(String {})); } } -Gfx::Path SVGLineElement::get_path(CSSPixelSize) +Gfx::Path SVGLineElement::get_path(CSSPixelSize viewport_size) { + auto const viewport_width = viewport_size.width().to_float(); + auto const viewport_height = viewport_size.height().to_float(); + Gfx::Path path; - float x1 = m_x1.value_or(0); - float y1 = m_y1.value_or(0); - float x2 = m_x2.value_or(0); - float y2 = m_y2.value_or(0); + float const x1 = m_x1.value_or({ 0, false }).resolve_relative_to(viewport_width); + float const y1 = m_y1.value_or({ 0, false }).resolve_relative_to(viewport_height); + float const x2 = m_x2.value_or({ 0, false }).resolve_relative_to(viewport_width); + float const y2 = m_y2.value_or({ 0, false }).resolve_relative_to(viewport_height); // 1. perform an absolute moveto operation to absolute location (x1,y1) path.move_to({ x1, y1 }); @@ -62,8 +65,8 @@ JS::NonnullGCPtr SVGLineElement::x1() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_x1.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_x1.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_x1.value_or({ 0, false }).value()); + auto anim_length = SVGLength::create(realm(), 0, m_x1.value_or({ 0, false }).value()); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)); } @@ -72,8 +75,8 @@ JS::NonnullGCPtr SVGLineElement::y1() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_y1.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_y1.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_y1.value_or({ 0, false }).value()); + auto anim_length = SVGLength::create(realm(), 0, m_y1.value_or({ 0, false }).value()); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)); } @@ -82,8 +85,8 @@ JS::NonnullGCPtr SVGLineElement::x2() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_x2.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_x2.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_x2.value_or({ 0, false }).value()); + auto anim_length = SVGLength::create(realm(), 0, m_x2.value_or({ 0, false }).value()); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)); } @@ -92,8 +95,8 @@ JS::NonnullGCPtr SVGLineElement::y2() const { // FIXME: Populate the unit type when it is parsed (0 here is "unknown"). // FIXME: Create a proper animated value when animations are supported. - auto base_length = SVGLength::create(realm(), 0, m_y2.value_or(0)); - auto anim_length = SVGLength::create(realm(), 0, m_y2.value_or(0)); + auto base_length = SVGLength::create(realm(), 0, m_y2.value_or({ 0, false }).value()); + auto anim_length = SVGLength::create(realm(), 0, m_y2.value_or({ 0, false }).value()); return SVGAnimatedLength::create(realm(), move(base_length), move(anim_length)); } diff --git a/Userland/Libraries/LibWeb/SVG/SVGLineElement.h b/Userland/Libraries/LibWeb/SVG/SVGLineElement.h index 4deef429ccc..e8119159c53 100644 --- a/Userland/Libraries/LibWeb/SVG/SVGLineElement.h +++ b/Userland/Libraries/LibWeb/SVG/SVGLineElement.h @@ -32,10 +32,10 @@ private: virtual void initialize(JS::Realm&) override; - Optional m_x1; - Optional m_y1; - Optional m_x2; - Optional m_y2; + Optional m_x1; + Optional m_y1; + Optional m_x2; + Optional m_y2; }; }