summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgstylenode.hxx4
-rw-r--r--svgio/source/svgreader/svgstylenode.cxx31
2 files changed, 16 insertions, 19 deletions
diff --git a/svgio/inc/svgstylenode.hxx b/svgio/inc/svgstylenode.hxx
index 320b4fa17dcc..1a5a43ca858c 100644
--- a/svgio/inc/svgstylenode.hxx
+++ b/svgio/inc/svgstylenode.hxx
@@ -19,6 +19,7 @@
#pragma once
+#include <unordered_map>
#include "svgnode.hxx"
#include "svgstyleattributes.hxx"
@@ -28,7 +29,7 @@ namespace svgio::svgreader
{
private:
/// use styles
- std::vector< SvgStyleAttributes* > maSvgStyleAttributes;
+ std::unordered_map< OUString, std::unique_ptr<SvgStyleAttributes> > maSvgStyleAttributes;
bool mbTextCss : 1; // true == type is 'text/css'
@@ -36,7 +37,6 @@ namespace svgio::svgreader
SvgStyleNode(
SvgDocument& rDocument,
SvgNode* pParent);
- virtual ~SvgStyleNode() override;
/// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
virtual bool supportsParentStyle() const override;
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)