summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2012-08-02 10:35:23 +0000
committerXisco Fauli <anistenis@gmail.com>2013-04-14 17:52:34 +0200
commit5bdba378d6fc9f18f618967ec37d07efed2afee4 (patch)
treeea5c9753d5abc12889e81cd620344d07e1a40c7a /svgio
parentbc589d57f083279b6d619904b937fae706ece493 (diff)
#120435# Corrected CSS style detection to be executed only once per node
Diffstat (limited to 'svgio')
-rw-r--r--svgio/source/svgreader/svgnode.cxx93
1 files changed, 50 insertions, 43 deletions
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 81a47c7ddf12..ff44050c0473 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -37,68 +37,71 @@ namespace svgio
const SvgStyleAttributes* SvgNode::checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const
{
- const SvgDocument& rDocument = getDocument();
-
- if(rDocument.hasSvgStyleAttributesById())
+ if(maCssStyleVector.empty()) // #120435# Evaluate for CSS styles only once, this cannot change
{
- if(getClass())
- {
- // find all referenced CSS styles, a list of entries is allowed
- const rtl::OUString* pClassList = getClass();
- const sal_Int32 nLen(pClassList->getLength());
- sal_Int32 nPos(0);
- const SvgStyleAttributes* pNew = 0;
+ const SvgDocument& rDocument = getDocument();
- skip_char(*pClassList, sal_Unicode(' '), nPos, nLen);
-
- while(nPos < nLen)
+ if(rDocument.hasSvgStyleAttributesById())
+ {
+ if(getClass())
{
- rtl::OUStringBuffer aTokenValue;
+ // find all referenced CSS styles, a list of entries is allowed
+ const rtl::OUString* pClassList = getClass();
+ const sal_Int32 nLen(pClassList->getLength());
+ sal_Int32 nPos(0);
+ const SvgStyleAttributes* pNew = 0;
- copyToLimiter(*pClassList, sal_Unicode(' '), nPos, aTokenValue, nLen);
skip_char(*pClassList, sal_Unicode(' '), nPos, nLen);
- rtl::OUString aId(rtl::OUString::createFromAscii("."));
- const rtl::OUString aOUTokenValue(aTokenValue.makeStringAndClear());
+ while(nPos < nLen)
+ {
+ rtl::OUStringBuffer aTokenValue;
- // look for CSS style common to token
- aId = aId + aOUTokenValue;
- pNew = rDocument.findSvgStyleAttributesById(aId);
+ copyToLimiter(*pClassList, sal_Unicode(' '), nPos, aTokenValue, nLen);
+ skip_char(*pClassList, sal_Unicode(' '), nPos, nLen);
- if(!pNew && rClassStr.getLength())
- {
- // look for CSS style common to class.token
- aId = rClassStr + aId;
+ rtl::OUString aId(rtl::OUString::createFromAscii("."));
+ const rtl::OUString aOUTokenValue(aTokenValue.makeStringAndClear());
+ // look for CSS style common to token
+ aId = aId + aOUTokenValue;
pNew = rDocument.findSvgStyleAttributesById(aId);
+
+ if(!pNew && rClassStr.getLength())
+ {
+ // look for CSS style common to class.token
+ aId = rClassStr + aId;
+
+ pNew = rDocument.findSvgStyleAttributesById(aId);
+ }
+
+ if(pNew)
+ {
+ const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
+ }
}
+ }
+
+ if(maCssStyleVector.empty() && getId())
+ {
+ // if none found, search for CSS style equal to Id
+ const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId());
if(pNew)
{
const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
}
}
- }
- if(maCssStyleVector.empty() && getId())
- {
- // if none found, search for CSS style equal to Id
- const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId());
-
- if(pNew)
+ if(maCssStyleVector.empty() && rClassStr.getLength())
{
- const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
- }
- }
+ // if none found, search for CSS style equal to class type
+ const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr);
- if(maCssStyleVector.empty() && rClassStr.getLength())
- {
- // if none found, search for CSS style equal to class type
- const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr);
-
- if(pNew)
- {
- const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
+ if(pNew)
+ {
+ const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
+ }
}
}
}
@@ -110,8 +113,12 @@ namespace svgio
else
{
// set CssStyleParent at maCssStyleVector members to hang them in front of
- // the existing style
+ // the existing style. Build a style chain, reset parent of original for security.
+ // Repeated style requests should only be issued from sub-Text nodes and I'm not
+ // sure if in-between text nodes may build other chains (should not happen). But
+ // it's only a re-chaining with pointers (cheap), so allow to do it every time.
SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(&rOriginal);
+ pCurrent->setCssStyleParent(0);
for(sal_uInt32 a(0); a < maCssStyleVector.size(); a++)
{