diff options
Diffstat (limited to 'svgio/source/svgreader/svgstylenode.cxx')
-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) |