filter/qa/unit/data/dashedline.fodg | 28 ++++++++++++++++++++++++++++ filter/qa/unit/svg.cxx | 14 ++++++++++++++ filter/source/svg/svgwriter.cxx | 12 ++++++++++++ 3 files changed, 54 insertions(+)
New commits: commit c103d337bd41eaa44b65accabe978fe542e41d06 Author: Mike Kaganski <[email protected]> AuthorDate: Tue Jan 20 12:11:45 2026 +0500 Commit: Mike Kaganski <[email protected]> CommitDate: Tue Jan 20 10:13:30 2026 +0100 tdf#170396: implement SVG export support for dashed lines Commit b71d9a6d15cfb8a50afdea5ac064f40d84c561f8 (do not apply line dashing in drawinglayer (tdf#136957), 2021-04-29) made sure that metafiles pass dashing information in LineInfo of MetaPolyLineAction, instead of altering the polyline itself. Since SVG export ignored dashing information in MetaPolyLineAction, the exported lines were solid since that patch. This patch introduces respective export support, emitting stroke-dasharray attribute. As far as I see, it has exactly the same semantics, and renders correctly in chrome and firefox. It also imports OK into Draw. Ref: https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Attribute/stroke-dasharray Change-Id: Ifb634a4f3608ee5c2c76727ef4416b80f8f90709 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197618 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> diff --git a/filter/qa/unit/data/dashedline.fodg b/filter/qa/unit/data/dashedline.fodg new file mode 100644 index 000000000000..73ca01124945 --- /dev/null +++ b/filter/qa/unit/data/dashedline.fodg @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" office:version="1.4" office:mimetype="application/vnd.oasis.opendocument.graphics"> + <office:styles> + <draw:stroke-dash draw:name="DoubleDashDotDot" draw:style="rect" draw:dots1="1" draw:dots1-length="800%" draw:dots2="2" draw:dots2-length="90%" draw:distance="300%"/> + <style:style style:name="standard" style:family="graphic"> + <style:graphic-properties draw:stroke="solid" svg:stroke-width="1mm" svg:stroke-color="#008000" draw:fill="none" draw:shadow="hidden"/> + </style:style> + </office:styles> + <office:automatic-styles> + <style:page-layout style:name="PM0"> + <style:page-layout-properties fo:margin-top="1cm" fo:margin-bottom="1cm" fo:margin-left="1cm" fo:margin-right="1cm" fo:page-width="14cm" fo:page-height="4cm"/> + </style:page-layout> + <style:style style:name="gr1" style:family="graphic" style:parent-style-name="standard"> + <style:graphic-properties draw:stroke="dash" draw:stroke-dash="DoubleDashDotDot" draw:textarea-vertical-align="middle"/> + </style:style> + </office:automatic-styles> + <office:master-styles> + <style:master-page style:name="Default" style:page-layout-name="PM0"/> + </office:master-styles> + <office:body> + <office:drawing> + <draw:page draw:name="page1" draw:master-page-name="Default"> + <draw:line draw:style-name="gr1" svg:x1="2cm" svg:y1="2cm" svg:x2="12cm" svg:y2="2cm"/> + </draw:page> + </office:drawing> + </office:body> +</office:document> \ No newline at end of file diff --git a/filter/qa/unit/svg.cxx b/filter/qa/unit/svg.cxx index b2f033adcca6..6bcbbb17df02 100644 --- a/filter/qa/unit/svg.cxx +++ b/filter/qa/unit/svg.cxx @@ -397,6 +397,20 @@ CPPUNIT_TEST_FIXTURE(SvgFilterTest, testTdf166789) CPPUNIT_ASSERT_DOUBLES_EQUAL(7000, length.toInt32(), 70); // allow 1% for rounding errors } +CPPUNIT_TEST_FIXTURE(SvgFilterTest, testDashedLine) +{ + // A dashed line + loadFromFile(u"dashedline.fodg"); + + save(TestFilter::SVG_DRAW); + + xmlDocUniquePtr pXmlDoc = parseExportedFile(); + CPPUNIT_ASSERT(pXmlDoc); + + // The result must include 'stroke-dasharray' attribute + assertXPath(pXmlDoc, "/svg:svg/svg:g//svg:path", "stroke-dasharray", u"800,300,90,300,90,300"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx index 7dd1ad527811..407979a21c3e 100644 --- a/filter/source/svg/svgwriter.cxx +++ b/filter/source/svg/svgwriter.cxx @@ -2142,6 +2142,18 @@ void SVGActionWriter::ImplAddLineAttr( const LineInfo &rAttrs ) } } + if (rAttrs.GetStyle() == LineStyle::Dash) + { + OUStringBuffer aDashArrayStr; + for (double x : rAttrs.GetDotDashArray()) + { + if (!aDashArrayStr.isEmpty()) + aDashArrayStr.append(","); + aDashArrayStr.append(x); + } + if (!aDashArrayStr.isEmpty()) + mrExport.AddAttribute(u"stroke-dasharray"_ustr, aDashArrayStr.makeStringAndClear()); + } }
