diff options
author | offtkp <parisoplop@gmail.com> | 2022-06-19 23:52:58 +0300 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-06-22 14:14:27 +0200 |
commit | 99f8e8aa0ccb741c2b5ede6cab75798c1793d899 (patch) | |
tree | 58b487ac3364685a01a7a8bb8c7386fde12fbb26 /svgio/source/svgreader | |
parent | 29252e78627db79662d89919f77746824c6563c3 (diff) |
tdf#149449 Don't ignore CSS class redefinition inside SVGs
Previously if a css class was redefined like so:
.cls2,.cls3{fill:#fff;}.cls-2{opacity:0.1;}
the second definition of .cls-2 would get ignored and opacity would
remain 1.
This patch keeps track of the names of each previously defined class and
makes sure to append the future redefinition instead of ignoring it.
Change-Id: I20b55aea247d11774cd743505a90f1466f622b1e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136109
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r-- | svgio/source/svgreader/svgstylenode.cxx | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/svgio/source/svgreader/svgstylenode.cxx b/svgio/source/svgreader/svgstylenode.cxx index 89f6200138bd..f9d33d61ced3 100644 --- a/svgio/source/svgreader/svgstylenode.cxx +++ b/svgio/source/svgreader/svgstylenode.cxx @@ -31,15 +31,6 @@ namespace svgio::svgreader { } - SvgStyleNode::~SvgStyleNode() - { - while(!maSvgStyleAttributes.empty()) - { - delete *(maSvgStyleAttributes.end() - 1); - maSvgStyleAttributes.pop_back(); - } - } - // #i125258# no parent when we are a CssStyle holder to break potential loops because // when using CssStyles we jump uncontrolled inside the node tree hierarchy bool SvgStyleNode::supportsParentStyle() const @@ -148,13 +139,6 @@ namespace svgio::svgreader if(aSelectors.isEmpty() || aContent.isEmpty()) return; - // create new style and add to local list (for ownership control) - SvgStyleAttributes* pNewStyle = new SvgStyleAttributes(*this); - maSvgStyleAttributes.push_back(pNewStyle); - - // fill with content - pNewStyle->readCssStyle(aContent); - // comma-separated split (Css abbreviation for same style for multiple selectors) const sal_Int32 nLen(aSelectors.getLength()); sal_Int32 nPos(0); @@ -168,9 +152,22 @@ namespace svgio::svgreader const OUString aSingleName(aToken.makeStringAndClear().trim()); + // add the current css class only if wasn't previously added + auto [aIterator, bIsNew] = maSvgStyleAttributes.try_emplace(aSingleName); + if (bIsNew) + { + // create new style and add to local list (for ownership control) and + // in case it's written to again in future classes to prevent overwrites + aIterator->second = std::make_unique<SvgStyleAttributes>(*this); + } + const std::unique_ptr<SvgStyleAttributes>& pCurrentStyle = aIterator->second; + + // fill with content + pCurrentStyle->readCssStyle(aContent); + if(aSingleName.getLength()) { - addCssStyleSheet(aSingleName, *pNewStyle); + addCssStyleSheet(aSingleName, *pCurrentStyle); } if(nInitPos == nPos) |