diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-26 19:15:03 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-06-26 22:45:12 +0200 |
commit | 930eb99a712a3ad9b76e9edb68bbcea68af36656 (patch) | |
tree | 66829fb3b3486e044a42ccf1076196bd1f2ba373 /svgio/source | |
parent | 897fce4abd0c731bf697ca1e38a8049f66f9ac7c (diff) |
tdf#156038, tdf#78232: support css child combinator
Change-Id: I874c368f66db97017357030867f1255551996228
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153626
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source')
-rw-r--r-- | svgio/source/svgreader/svgnode.cxx | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx index 399b92231543..37b34deff0f6 100644 --- a/svgio/source/svgreader/svgnode.cxx +++ b/svgio/source/svgreader/svgnode.cxx @@ -184,6 +184,100 @@ namespace { } } + void SvgNode::fillCssStyleVectorUsingParent(const SvgNode& rCurrent) + { + const SvgDocument& rDocument = getDocument(); + + if(!rDocument.hasGlobalCssStyleAttributes()) + return; + + const SvgNode* pParent = rCurrent.getParent(); + + if (!pParent) + return; + + OUString sParentId; + if (pParent->getId().has_value()) + { + sParentId = pParent->getId().value(); + } + std::vector <OUString> aParentClasses = parseClass(*pParent); + OUString sParentType(SVGTokenToStr(pParent->getType())); + + if(rCurrent.getId()) + { + const OUString& rId = *rCurrent.getId(); + + if(!rId.isEmpty()) + { + if (!sParentId.isEmpty()) + { + const OUString aConcatenated("#" + sParentId + ">#" + rId); + addCssStyle(rDocument, aConcatenated); + } + + for(const auto &aParentClass : aParentClasses) + { + const OUString aConcatenated("." + aParentClass + ">#" + rId); + addCssStyle(rDocument, aConcatenated); + } + + if (!sParentType.isEmpty()) + { + const OUString aConcatenated(sParentType + ">#" + rId); + addCssStyle(rDocument, aConcatenated); + } + } + + } + + std::vector <OUString> aClasses = parseClass(rCurrent); + for(const auto &aClass : aClasses) + { + + if (!sParentId.isEmpty()) + { + const OUString aConcatenated("#" + sParentId + ">." + aClass); + addCssStyle(rDocument, aConcatenated); + } + + for(const auto &aParentClass : aParentClasses) + { + const OUString aConcatenated("." + aParentClass + ">." + aClass); + addCssStyle(rDocument, aConcatenated); + } + + if (!sParentType.isEmpty()) + { + const OUString aConcatenated(sParentType + ">." + aClass); + addCssStyle(rDocument, aConcatenated); + } + } + + OUString sCurrentType(SVGTokenToStr(getType())); + + if(!sCurrentType.isEmpty()) + { + if (!sParentId.isEmpty()) + { + const OUString aConcatenated("#" + sParentId + ">" + sCurrentType); + addCssStyle(rDocument, aConcatenated); + } + + for(const auto &aParentClass : aParentClasses) + { + const OUString aConcatenated("." + aParentClass + ">" + sCurrentType); + addCssStyle(rDocument, aConcatenated); + } + + if (!sParentType.isEmpty()) + { + const OUString aConcatenated(sParentType + ">" + sCurrentType); + addCssStyle(rDocument, aConcatenated); + } + } + } + void SvgNode::fillCssStyleVector(const SvgStyleAttributes& rOriginal) { OSL_ENSURE(!mbCssStyleVectorBuilt, "OOps, fillCssStyleVector called double ?!?"); @@ -211,9 +305,13 @@ namespace { maCssStyleVector.push_back(mpLocalCssStyle.get()); } + // tdf#156038 check for child combinator + fillCssStyleVectorUsingParent(*this); + // check the hierarchy for concatenated patterns of Selectors fillCssStyleVectorUsingHierarchyAndSelectors(*this, OUString()); + // tdf#99115, Add css selector '*' style only if the element is on top of the hierarchy // meaning its parent is <svg> const SvgNode* pParent = this->getParent(); |