summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-06-19 23:52:58 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-06-22 14:14:27 +0200
commit99f8e8aa0ccb741c2b5ede6cab75798c1793d899 (patch)
tree58b487ac3364685a01a7a8bb8c7386fde12fbb26 /svgio
parent29252e78627db79662d89919f77746824c6563c3 (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')
-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)