[Libreoffice-commits] core.git: Branch 'aoo/trunk' - svgio/source
Armin Le Grand
alg at apache.org
Wed Jul 23 09:07:38 PDT 2014
svgio/source/svgreader/svgnode.cxx | 93 ++++++++++++++++++++++----------
svgio/source/svgreader/svgtspannode.cxx | 5 +
2 files changed, 69 insertions(+), 29 deletions(-)
New commits:
commit 7fc272837995079247594e173d977a2e541a7042
Author: Armin Le Grand <alg at apache.org>
Date: Wed Jul 23 15:09:02 2014 +0000
i125292, i125293 enhanced CssStyle handling in SVG import
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 03e2795..78cb1e1 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -55,6 +55,32 @@ namespace svgio
if(rDocument.hasSvgStyleAttributesById())
{
+ // #125293# If we have CssStyles we need to buuild a linked list of SvgStyleAttributes
+ // which represent this for the current object. There are various methods to
+ // specify CssStyles which need to be taken into account in a given order:
+ // - 'id' element
+ // - 'class' element(s)
+ // - type-dependent elements (e..g. 'rect' for all rect elements)
+ // - local firect attributes (rOriginal)
+ // - inherited attributes (up the hierarchy)
+ // The first three will be collected in maCssStyleVector for the current element
+ // (once, this will not change) and be linked in the needed order using the
+ // get/setCssStyleParent at the SvgStyleAttributes which will be used preferred in
+ // member evaluation over the existing parent hierarchy
+
+ // check for 'id' references
+ if(getId())
+ {
+ // search for CSS style equal to Id
+ const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(*getId());
+
+ if(pNew)
+ {
+ const_cast< SvgNode* >(this)->maCssStyleVector.push_back(pNew);
+ }
+ }
+
+ // check for 'class' references
if(getClass())
{
// find all referenced CSS styles, a list of entries is allowed
@@ -94,20 +120,10 @@ namespace svgio
}
}
- 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() && rClassStr.getLength())
+ // check for class-dependent references to CssStyles
+ if(rClassStr.getLength())
{
- // if none found, search for CSS style equal to class type
+ // search for CSS style equal to class type
const SvgStyleAttributes* pNew = rDocument.findSvgStyleAttributesById(rClassStr);
if(pNew)
@@ -118,29 +134,50 @@ namespace svgio
}
}
- if(!maCssStyleVector.empty())
+ if(maCssStyleVector.empty())
{
- // #123510# if CSS styles were found, create a linked list with rOriginal as parent
- // and all CSS styles as linked children, so that the style attribute has
- // priority over the CSS style. If there is no style attribute this means that
- // no values are set at rOriginal, thus it is still correct to have that order.
- // 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++)
+ // return original if no CssStlyes found
+ return &rOriginal;
+ }
+ else
+ {
+ // #125293# rOriginal will be the last element in the linked list; use no CssStyleParent
+ // there (reset it) to ensure that the parent hierarchy will be used when it's base
+ // is referenced. This new chaning inserts the CssStyles before the original style,
+ // this makes the whole process much safer since the original style when used will
+ // be not different to the situation without CssStyles; thus loops which may be caused
+ // by trying to use the parent hierarchy of the owner of the style will be avoided
+ // already in this mechanism. It's still good to keep the supportsParentStyle
+ // from #125258# in place, though.
+ // This chain building using pointers will be done every time when checkForCssStyle
+ // is used (not the search, only the chaining). This is needed since the CssStyles
+ // themselves will be potentially used multiple times. It is not expensive since it's
+ // only changing some pointers.
+ // The alternative would be to create the style hierarchy for every element (or even
+ // for the element containing the hierarchy) in a vector of pointers and to use that.
+ // Resetting the CssStyleParent on rOriginal is probably not needeed
+ // but simply safer to do.
+ const_cast< SvgStyleAttributes& >(rOriginal).setCssStyleParent(0);
+
+ // loop over the existing CssStyles and link them. There is a first one, take
+ // as current
+ SvgStyleAttributes* pCurrent = const_cast< SvgStyleAttributes* >(maCssStyleVector[0]);
+
+ for(sal_uInt32 a(1); a < maCssStyleVector.size(); a++)
{
SvgStyleAttributes* pNext = const_cast< SvgStyleAttributes* >(maCssStyleVector[a]);
pCurrent->setCssStyleParent(pNext);
pCurrent = pNext;
- pCurrent->setCssStyleParent(0);
}
- }
- return &rOriginal;
+ // pCurrent is the last used CssStyle, let it point to the original style
+ pCurrent->setCssStyleParent(&rOriginal);
+
+ // return 1st CssStyle as style chain start element (only for the
+ // local element, still no hierarchy used here)
+ return maCssStyleVector[0];
+ }
}
SvgNode::SvgNode(
diff --git a/svgio/source/svgreader/svgtspannode.cxx b/svgio/source/svgreader/svgtspannode.cxx
index 69243e1..6d4b188 100644
--- a/svgio/source/svgreader/svgtspannode.cxx
+++ b/svgio/source/svgreader/svgtspannode.cxx
@@ -45,7 +45,10 @@ namespace svgio
const SvgStyleAttributes* SvgTspanNode::getSvgStyleAttributes() const
{
- return &maSvgStyleAttributes;
+ // #125293# Need to support CssStyles in tspan text sections
+ static rtl::OUString aClassStr(rtl::OUString::createFromAscii("tspan"));
+
+ return checkForCssStyle(aClassStr, maSvgStyleAttributes);
}
void SvgTspanNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
More information about the Libreoffice-commits
mailing list