From 02c7caae9a07abe133c1acc6cfb394a8ee0eb16c Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Thu, 13 Aug 2026 15:11:29 +0300 Subject: [PATCH] svgio: font-variation-settings is an inherited property It is inherited per CSS Fonts, so the children of a group must inherit it when set on the group. Change-Id: I3a7f1c58b249e0d647c3b8a15f9e2043b7d6c891 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/209212 Reviewed-by: Khaled Hosny Tested-by: Jenkins --- svgio/inc/svgstyleattributes.hxx | 2 +- svgio/qa/cppunit/SvgImportTest.cxx | 15 ++++++++++++ .../data/font-variation-settings-inherit.svg | 7 ++++++ svgio/source/svgreader/svgstyleattributes.cxx | 24 ++++++++++++++++++- 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 svgio/qa/cppunit/data/font-variation-settings-inherit.svg diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index e8fbb5245280..57e39bc6417d 100644 --- a/svgio/inc/svgstyleattributes.hxx +++ b/svgio/inc/svgstyleattributes.hxx @@ -422,7 +422,7 @@ namespace svgio::svgreader void setFontWeight(const FontWeight aFontWeight) { maFontWeight = aFontWeight; } /// FontVariations content - const std::vector& getFontVariations() const { return maFontVariations; } + const std::vector& getFontVariations() const; void setFontVariations(std::vector&& rFontVariations) { maFontVariations = std::move(rFontVariations); } /// FontDirection content diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 51f2b17d9d23..17ac10dda2dd 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -2293,6 +2293,21 @@ CPPUNIT_TEST_FIXTURE(Test, testFontVariationSettings) assertXPath(pDocument, "//textsimpleportion[7]", "font-variation-settings", u"\"wght\" 700"); } +CPPUNIT_TEST_FIXTURE(Test, testFontVariationSettingsInherit) +{ + // font-variation-settings is an inherited property. + xmlDocUniquePtr pDocument + = dumpAndParseSvg(u"/svgio/qa/cppunit/data/font-variation-settings-inherit.svg"); + + assertXPath(pDocument, "//textsimpleportion", 3); + // inherited from the group + assertXPath(pDocument, "//textsimpleportion[1]", "font-variation-settings", u"\"wght\" 300"); + // the child's own list replaces the inherited one, it does not merge with it + assertXPath(pDocument, "//textsimpleportion[2]", "font-variation-settings", u"\"wght\" 700"); + // the script of the text makes no difference + assertXPath(pDocument, "//textsimpleportion[3]", "font-variation-settings", u"\"wght\" 300"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/qa/cppunit/data/font-variation-settings-inherit.svg b/svgio/qa/cppunit/data/font-variation-settings-inherit.svg new file mode 100644 index 000000000000..0a050c3be18b --- /dev/null +++ b/svgio/qa/cppunit/data/font-variation-settings-inherit.svg @@ -0,0 +1,7 @@ + + + Inherited + Overridden + مرحبا + + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 0fb77dc8813a..bd3a28c866dc 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1367,7 +1367,7 @@ namespace svgio::svgreader maBaselineShift(BaselineShift::Baseline), maBaselineShiftNumber(0), maDominantBaseline(DominantBaseline::Auto), - maResolvingParent(36, 0), + maResolvingParent(37, 0), mbStrokeDasharraySet(false), mbUseFillFromContextFill(false), mbUseFillFromContextStroke(false), @@ -2843,6 +2843,28 @@ namespace svgio::svgreader return FontStyle::normal; } + const std::vector& SvgStyleAttributes::getFontVariations() const + { + if (!maFontVariations.empty()) + { + return maFontVariations; + } + + const SvgStyleAttributes* pSvgStyleAttributes = getCssStyleOrParentStyle(); + + if (pSvgStyleAttributes && maResolvingParent[36] < nStyleDepthLimit) + { + ++maResolvingParent[36]; + const std::vector& rInherited + = pSvgStyleAttributes->getFontVariations(); + --maResolvingParent[36]; + + return rInherited; + } + + return maFontVariations; + } + FontWeight SvgStyleAttributes::getFontWeight() const { if(maFontWeight != FontWeight::notset)