Kaydet (Commit) e29639ac authored tarafından Armin Le Grand's avatar Armin Le Grand

#120435# Corrected CSS style detection to be executed only once per node

üst 2a91a539
......@@ -43,68 +43,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);
}
}
}
}
......@@ -116,8 +119,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++)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment