diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-03-27 11:38:44 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2024-03-27 23:44:40 +0100 |
commit | 0a2535ceb06bb9233bc2eeee9158d4c9d2513abd (patch) | |
tree | f0ed107eec0a819474abbc529534183feeb478e8 /svgio/source/svgreader | |
parent | 6b15374d1850de13e977cf4bb2106d38e74a030a (diff) |
tdf#160386: Add support for switch element
For now, only use language tag, meaning if
there is a file like in the unittest with
<text systemLanguage="en-us">Howdy!</text>
<text systemLanguage="en-gb">Wotcha!</text>
<text systemLanguage="en-au">G'day!</text>
<text systemLanguage="en">Hello!</text>
"Hello!" with be displayed in a en_AU system locale
This patch partially reverts 13a41e7a12598c7896d6dc8d34aba6af5b80b83c
"tdf#150124: do nothing when parent is of unkown type"
making 0dfd8288a87b58e503bb3a41be6137485fbf3f68
"ofz#60384 Direct-leak" no longer necessary
Change-Id: Ifc73bc69aa997088dc0a2b11d7d30446303fa3b3
Change-Id: I885ef0f2c44b86196881fe55a963db2e5c7eb1be
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165394
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio/source/svgreader')
-rw-r--r-- | svgio/source/svgreader/svgdocumenthandler.cxx | 9 | ||||
-rw-r--r-- | svgio/source/svgreader/svgnode.cxx | 44 | ||||
-rw-r--r-- | svgio/source/svgreader/svgswitchnode.cxx | 129 | ||||
-rw-r--r-- | svgio/source/svgreader/svgtoken.cxx | 1 |
4 files changed, 176 insertions, 7 deletions
diff --git a/svgio/source/svgreader/svgdocumenthandler.cxx b/svgio/source/svgreader/svgdocumenthandler.cxx index 6e31aaf8fdf0..85a54448e7d9 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> @@ -203,7 +204,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 c372184b1e37..20a48de25977 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()) @@ -751,6 +755,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/svgswitchnode.cxx b/svgio/source/svgreader/svgswitchnode.cxx new file mode 100644 index 000000000000..bbad79a3b5d9 --- /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 b6e22b63c547..3f5ac5c7a306 100644 --- a/svgio/source/svgreader/svgtoken.cxx +++ b/svgio/source/svgreader/svgtoken.cxx @@ -114,6 +114,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 }, |