diff options
Diffstat (limited to 'svgio/source')
-rw-r--r-- | svgio/source/svgreader/svgdocumenthandler.cxx | 9 | ||||
-rw-r--r-- | svgio/source/svgreader/svgnode.cxx | 44 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 36 | ||||
-rw-r--r-- | svgio/source/svgreader/svgswitchnode.cxx | 129 | ||||
-rw-r--r-- | svgio/source/svgreader/svgtoken.cxx | 1 |
5 files changed, 198 insertions, 21 deletions
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx index 5e89edad6c..8d2cc8849c 100644 --- a/svgio/source/svgreader/svgdocumenthandler.cxx +++ b/svgio/source/svgreader/svgdocumenthandler.cxx @@ -27,6 +27,7 @@ #include <svgrectnode.hxx> #include <svggradientnode.hxx> #include <svggradientstopnode.hxx> +#include <svgswitchnode.hxx> #include <svgsymbolnode.hxx> #include <svgusenode.hxx> #include <svgcirclenode.hxx> @@ -199,7 +200,13 @@ namespace mpTarget->parseAttributes(xAttribs); break; } - case SVGToken::Switch: //TODO: Support switch element + case SVGToken::Switch: + { + /// new node for Switch + mpTarget = new SvgSwitchNode(maDocument, mpTarget); + mpTarget->parseAttributes(xAttribs); + break; + } case SVGToken::Defs: case SVGToken::G: { diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx index 0ae4e80363..7a45c681f1 100644 --- a/svgio/source/svgreader/svgnode.cxx +++ b/svgio/source/svgreader/svgnode.cxx @@ -367,17 +367,13 @@ namespace { mpParent(pParent), mpAlternativeParent(nullptr), maXmlSpace(XmlSpace::NotSet), - maDisplay(Display::Inline), + maDisplay(maType == SVGToken::Unknown ? Display::None : Display::Inline), // tdf#150124: do not display unknown nodes mbDecomposing(false), mbCssStyleVectorBuilt(false) { if (pParent) { - // tdf#150124 ignore when parent is unknown - if (pParent->getType() != SVGToken::Unknown) - pParent->maChildren.emplace_back(this); - else - mrDocument.addOrphanNode(this); + pParent->maChildren.emplace_back(this); } } @@ -527,6 +523,14 @@ namespace { } break; } + case SVGToken::SystemLanguage: + { + if(!aContent.isEmpty()) + { + setSystemLanguage(aContent); + } + break; + } case SVGToken::XmlSpace: { if(!aContent.isEmpty()) @@ -752,6 +756,34 @@ namespace { mrDocument.addSvgNodeToMapper(*mpClass, *this); } + void SvgNode::setSystemLanguage(OUString const & rSystemClass) + { + const sal_Int32 nLen(rSystemClass.getLength()); + sal_Int32 nPos(0); + OUStringBuffer aToken; + + // split into single tokens (currently only comma separator) + while(nPos < nLen) + { + const sal_Int32 nInitPos(nPos); + copyToLimiter(rSystemClass, u',', nPos, aToken, nLen); + skip_char(rSystemClass, u',', nPos, nLen); + const OUString aLang(o3tl::trim(aToken)); + aToken.setLength(0); + + if(!aLang.isEmpty()) + { + maSystemLanguage.push_back(aLang); + } + + if(nInitPos == nPos) + { + OSL_ENSURE(false, "Could not interpret on current position (!)"); + nPos++; + } + } + } + XmlSpace SvgNode::getXmlSpace() const { if(maXmlSpace != XmlSpace::NotSet) diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 19070989bb..58bdb9add8 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1287,18 +1287,9 @@ namespace svgio::svgreader maBaselineShift(BaselineShift::Baseline), maBaselineShiftNumber(0), maDominantBaseline(DominantBaseline::Auto), - maResolvingParent(31, 0), - mbIsClipPathContent(SVGToken::ClipPathNode == mrOwner.getType()), + maResolvingParent(32, 0), mbStrokeDasharraySet(false) { - const SvgStyleAttributes* pParentStyle = getParentStyle(); - if(!mbIsClipPathContent) - { - if(pParentStyle) - { - mbIsClipPathContent = pParentStyle->mbIsClipPathContent; - } - } } SvgStyleAttributes::~SvgStyleAttributes() @@ -2005,10 +1996,27 @@ namespace svgio::svgreader } } + bool SvgStyleAttributes::isClipPathContent() const + { + if (SVGToken::ClipPathNode == mrOwner.getType()) + return true; + + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + if (pSvgStyleAttributes && maResolvingParent[31] < nStyleDepthLimit) + { + ++maResolvingParent[31]; + bool ret = pSvgStyleAttributes->isClipPathContent(); + --maResolvingParent[31]; + return ret; + } + + return false; + } + // #i125258# ask if fill is a direct hard attribute (no hierarchy) bool SvgStyleAttributes::isFillSet() const { - if(mbIsClipPathContent) + if(isClipPathContent()) { return false; } @@ -2042,7 +2050,7 @@ namespace svgio::svgreader { return &maFill.getBColor(); } - else if(mbIsClipPathContent) + else if(isClipPathContent()) { const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); @@ -2066,7 +2074,7 @@ namespace svgio::svgreader const basegfx::BColor* pFill = pSvgStyleAttributes->getFill(); --maResolvingParent[0]; - if(mbIsClipPathContent) + if(isClipPathContent()) { if (pFill) { @@ -2269,7 +2277,7 @@ namespace svgio::svgreader return ret; } - if(mbIsClipPathContent) + if(isClipPathContent()) { return SvgNumber(0.0); } diff --git a/svgio/source/svgreader/svgswitchnode.cxx b/svgio/source/svgreader/svgswitchnode.cxx new file mode 100644 index 0000000000..bbad79a3b5 --- /dev/null +++ b/svgio/source/svgreader/svgswitchnode.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <svgswitchnode.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <drawinglayer/primitive2d/transformprimitive2d.hxx> +#include <unotools/syslocaleoptions.hxx> + +namespace svgio::svgreader +{ +SvgSwitchNode::SvgSwitchNode(SvgDocument& rDocument, SvgNode* pParent) + : SvgNode(SVGToken::Switch, rDocument, pParent) + , maSvgStyleAttributes(*this) +{ +} + +SvgSwitchNode::~SvgSwitchNode() {} + +const SvgStyleAttributes* SvgSwitchNode::getSvgStyleAttributes() const +{ + return checkForCssStyle(maSvgStyleAttributes); +} + +void SvgSwitchNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent) +{ + // call parent + SvgNode::parseAttribute(aSVGToken, aContent); + + // read style attributes + maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent); + + // parse own + switch (aSVGToken) + { + case SVGToken::Style: + { + readLocalCssStyle(aContent); + break; + } + case SVGToken::Transform: + { + const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this)); + + if (!aMatrix.isIdentity()) + { + setTransform(aMatrix); + } + break; + } + default: + { + break; + } + } +} + +void SvgSwitchNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, + bool bReferenced) const +{ + // #i125258# for SVGTokenG decompose children + const SvgStyleAttributes* pStyle = getSvgStyleAttributes(); + + if (pStyle) + { + drawinglayer::primitive2d::Primitive2DContainer aContent; + + const auto& rChildren = getChildren(); + const sal_uInt32 nCount(rChildren.size()); + OUString sLanguage(SvtSysLocaleOptions().GetRealUILanguageTag().getLanguage()); + + SvgNode* pNodeToDecompose = nullptr; + for (sal_uInt32 a(0); a < nCount; a++) + { + SvgNode* pCandidate = rChildren[a].get(); + + if (pCandidate && Display::None != pCandidate->getDisplay()) + { + std::vector<OUString> aSystemLanguage = pCandidate->getSystemLanguage(); + if (!sLanguage.isEmpty() && !aSystemLanguage.empty()) + { + for (const OUString& sSystemLang : aSystemLanguage) + { + if (sSystemLang == sLanguage) + { + pNodeToDecompose = pCandidate; + break; + } + } + } + else + { + pNodeToDecompose = pCandidate; + } + } + + if (pNodeToDecompose) + { + pNodeToDecompose->decomposeSvgNode(aContent, bReferenced); + // break once it's descomposed + break; + } + } + + if (!aContent.empty()) + { + pStyle->add_postProcess(rTarget, std::move(aContent), getTransform()); + } + } +} + +} // end of namespace svgio::svgreader + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx index 968ead0483..642fba085f 100644 --- a/svgio/source/svgreader/svgtoken.cxx +++ b/svgio/source/svgreader/svgtoken.cxx @@ -107,6 +107,7 @@ constexpr auto aSVGTokenMap = frozen::make_unordered_map<std::u16string_view, SV { u"patternContentUnits", SVGToken::PatternContentUnits }, { u"patternTransform", SVGToken::PatternTransform }, { u"opacity", SVGToken::Opacity }, + { u"systemLanguage", SVGToken::SystemLanguage }, { u"visibility", SVGToken::Visibility }, { u"title", SVGToken::Title }, { u"desc", SVGToken::Desc }, |