From 5821c8949e543e672cf55e29001b3e7964d070af Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Sat, 12 Dec 2015 01:30:09 +0100 Subject: [PATCH] tdf#96364 SVG: Parse 'color' and 'style' before the rest of attributes 'fill', 'stroke' and 'stop-color' might depend on them Change-Id: I8b709dafe0ad0423a87911af7f2c83fa81e61cbd Reviewed-on: https://gerrit.libreoffice.org/20653 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- filter/source/svg/svgreader.cxx | 53 ++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx index 7e8a769d75cf..b7a20ba4e1ac 100644 --- a/filter/source/svg/svgreader.cxx +++ b/filter/source/svg/svgreader.cxx @@ -337,12 +337,26 @@ struct AnnotatingVisitor const sal_Int32 nNumAttrs( xAttributes->getLength() ); maGradientStopVector.push_back(GradientStop()); maGradientVector.back().maStops.push_back(maGradientStopVector.size()-1); + + // first parse 'color' as 'stop-color' might depend on it + // if 'stop-color''s value is "currentColor" and parsed previously + uno::Reference xNodeColor(xAttributes->getNamedItem("color")); + if(xNodeColor.is()) + parseGradientStop( maGradientStopVector.back(), + maGradientStopVector.size()-1, + XML_STOP_COLOR, + xNodeColor->getNodeValue() ); + + //now, parse the rest of attributes for( sal_Int32 i=0; iitem(i)->getNodeName()), - xAttributes->item(i)->getNodeValue() ); + const sal_Int32 nTokenId( + getTokenId(xAttributes->item(i)->getNodeName())); + if ( nTokenId != XML_COLOR ) + parseGradientStop( maGradientStopVector.back(), + maGradientStopVector.size()-1, + nTokenId, + xAttributes->item(i)->getNodeValue() ); } break; } @@ -353,29 +367,34 @@ struct AnnotatingVisitor maCurrState.maTransform.identity(); maCurrState.maViewBox.reset(); - // scan for style info + // first parse 'color' and 'style' as 'fill' and 'stroke' might depend on them + // if their values are "currentColor" and parsed previously + uno::Reference xNodeColor(xAttributes->getNamedItem("color")); + if(xNodeColor.is()) + parseAttribute(XML_COLOR, xNodeColor->getNodeValue()); + + uno::Reference xNodeStyle(xAttributes->getNamedItem("style")); + if(xNodeStyle.is()) + parseStyle(xNodeStyle->getNodeValue()); + const sal_Int32 nNumAttrs( xAttributes->getLength() ); OUString sAttributeValue; + //now, parse the rest of attributes for( sal_Int32 i=0; iitem(i)->getNodeValue(); const sal_Int32 nTokenId( getTokenId(xAttributes->item(i)->getNodeName())); - if( XML_STYLE == nTokenId ) - parseStyle(sAttributeValue); - else + if( XML_ID == nTokenId ) { - if( XML_ID == nTokenId ) - { - maElementVector.push_back(xElem); - maElementIdMap.insert(std::make_pair(sAttributeValue, - maElementVector.size() - 1)); - } - else - parseAttribute(nTokenId, - sAttributeValue); + maElementVector.push_back(xElem); + maElementIdMap.insert(std::make_pair(sAttributeValue, + maElementVector.size() - 1)); } + else if ( nTokenId != XML_COLOR || nTokenId != XML_STYLE ) + parseAttribute(nTokenId, + sAttributeValue); } // all attributes parsed, can calc total CTM now