From 7f79208759f7b788cde8aeeeec4ff0cdb34171db Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 17 Apr 2023 12:34:00 +0200 Subject: [PATCH] LibWeb: Support implicit lineto commands after moveto in SVG paths Per SVG2, any coordinate pairs following a moveto command should be treated as implicit lineto commands with the same absoluteness as the moveto command. --- .../expected/svg/svg-path-with-implicit-lineto.txt | 7 +++++++ .../input/svg/svg-path-with-implicit-lineto.html | 6 ++++++ Userland/Libraries/LibWeb/SVG/AttributeParser.cpp | 11 +++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/svg/svg-path-with-implicit-lineto.txt create mode 100644 Tests/LibWeb/Layout/input/svg/svg-path-with-implicit-lineto.html diff --git a/Tests/LibWeb/Layout/expected/svg/svg-path-with-implicit-lineto.txt b/Tests/LibWeb/Layout/expected/svg/svg-path-with-implicit-lineto.txt new file mode 100644 index 00000000000..0ab32ff1f72 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/svg/svg-path-with-implicit-lineto.txt @@ -0,0 +1,7 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x116 children: not-inline + BlockContainer at (8,8) content-size 784x100 children: inline + line 0 width: 100, height: 100, bottom: 100, baseline: 60 + frag 0 from SVGSVGBox start: 0, length: 0, rect: [8,8 100x100] + SVGSVGBox at (8,8) content-size 100x100 children: not-inline + SVGGeometryBox at (28,28) content-size 60x60 children: not-inline diff --git a/Tests/LibWeb/Layout/input/svg/svg-path-with-implicit-lineto.html b/Tests/LibWeb/Layout/input/svg/svg-path-with-implicit-lineto.html new file mode 100644 index 00000000000..8b5bca1ee8d --- /dev/null +++ b/Tests/LibWeb/Layout/input/svg/svg-path-with-implicit-lineto.html @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp b/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp index 644f2843a51..64ccd31c445 100644 --- a/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp +++ b/Userland/Libraries/LibWeb/SVG/AttributeParser.cpp @@ -130,12 +130,19 @@ void AttributeParser::parse_drawto() } } +// https://www.w3.org/TR/SVG2/paths.html#PathDataMovetoCommands void AttributeParser::parse_moveto() { bool absolute = consume() == 'M'; parse_whitespace(); - for (auto& pair : parse_coordinate_pair_sequence()) - m_instructions.append({ PathInstructionType::Move, absolute, pair }); + + bool is_first = true; + for (auto& pair : parse_coordinate_pair_sequence()) { + // NOTE: "M 1 2 3 4" is equivalent to "M 1 2 L 3 4". + auto type = is_first ? PathInstructionType::Move : PathInstructionType::Line; + m_instructions.append({ type, absolute, pair }); + is_first = false; + } } void AttributeParser::parse_closepath()