LibreOffice Module svgio (master) 1
svgusenode.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <svgusenode.hxx>
22#include <svgdocument.hxx>
23
24namespace svgio::svgreader
25{
27 SvgDocument& rDocument,
28 SvgNode* pParent)
29 : SvgNode(SVGToken::Use, rDocument, pParent),
30 maSvgStyleAttributes(*this),
31 mbDecomposingSvgNode(false)
32 {
33 }
34
36 {
37 }
38
40 {
42 }
43
44 void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
45 {
46 // call parent
47 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
48
49 // read style attributes
50 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
51
52 // parse own
53 switch(aSVGToken)
54 {
55 case SVGToken::Style:
56 {
57 readLocalCssStyle(aContent);
58 break;
59 }
61 {
62 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
63
64 if(!aMatrix.isIdentity())
65 {
66 setTransform(aMatrix);
67 }
68 break;
69 }
70 case SVGToken::X:
71 {
72 SvgNumber aNum;
73
74 if(readSingleNumber(aContent, aNum))
75 {
76 maX = aNum;
77 }
78 break;
79 }
80 case SVGToken::Y:
81 {
82 SvgNumber aNum;
83
84 if(readSingleNumber(aContent, aNum))
85 {
86 maY = aNum;
87 }
88 break;
89 }
90 case SVGToken::Width:
91 {
92 SvgNumber aNum;
93
94 if(readSingleNumber(aContent, aNum))
95 {
96 if(aNum.isPositive())
97 {
98 maWidth = aNum;
99 }
100 }
101 break;
102 }
103 case SVGToken::Height:
104 {
105 SvgNumber aNum;
106
107 if(readSingleNumber(aContent, aNum))
108 {
109 if(aNum.isPositive())
110 {
111 maHeight = aNum;
112 }
113 }
114 break;
115 }
116 case SVGToken::Href:
118 {
119 readLocalLink(aContent, maXLink);
120 break;
121 }
122 default:
123 {
124 break;
125 }
126 }
127 }
128
130 {
132 basegfx::B2DHomMatrix aTransform;
133
134 // try to access link to content
135 const SvgNode* pXLink = getDocument().findSvgNodeById(maXLink);
136
137 if (pXLink)
138 {
140 return;
141
142 // todo: in case mpXLink is a SVGToken::Svg or SVGToken::Symbol the
143 // SVG docs want the getWidth() and getHeight() from this node
144 // to be valid for the subtree.
146 const_cast< SvgNode* >(pXLink)->setAlternativeParent(this);
147 pXLink->decomposeSvgNode(aNewTarget, true);
148 const_cast< SvgNode* >(pXLink)->setAlternativeParent();
149 mbDecomposingSvgNode = false;
150
151 if(aNewTarget.empty())
152 return;
153
154 if(getX().isSet() || getY().isSet())
155 {
156 aTransform.translate(
159 }
160
161 if(getTransform())
162 {
163 aTransform = *getTransform() * aTransform;
164 }
165 }
166
168
169 if(pStyle)
170 {
172 {
173 pStyle->add_postProcess(rTarget, std::move(aNewTarget), aTransform);
174 }
175 }
176 }
177
178} // end of namespace svgio::svgreader
179
180/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void translate(double fX, double fY)
bool isIdentity() const
const SvgNode * findSvgNodeById(const OUString &rStr) const
find a node by its Id
Definition: svgdocument.cxx:56
void setAlternativeParent(const SvgNode *pAlternativeParent=nullptr)
alternative parent
Definition: svgnode.hxx:186
Display getDisplay() const
Display access #i121656#.
Definition: svgnode.hxx:182
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const
Definition: svgnode.cxx:584
const SvgStyleAttributes * checkForCssStyle(const SvgStyleAttributes &rOriginal) const
helper to evtl. link to css style
Definition: svgnode.cxx:335
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent)
Definition: svgnode.cxx:534
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
const SvgDocument & getDocument() const
Definition: svgnode.hxx:157
double solve(const InfoProvider &rInfoProvider, NumberType aNumberType=NumberType::length) const
Definition: SvgNumber.cxx:69
void add_postProcess(drawinglayer::primitive2d::Primitive2DContainer &rTarget, drawinglayer::primitive2d::Primitive2DContainer &&rSource, const std::optional< basegfx::B2DHomMatrix > &pTransform) const
void parseStyleAttribute(SVGToken aSVGToken, const OUString &rContent)
local attribute scanner
OUString maXLink
link to content. If maXLink is set, the node can be fetched
Definition: svgusenode.hxx:45
virtual ~SvgUseNode() override
Definition: svgusenode.cxx:35
SvgStyleAttributes maSvgStyleAttributes
use styles
Definition: svgusenode.hxx:33
const SvgNumber & getX() const
x content
Definition: svgusenode.hxx:64
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
Definition: svgusenode.cxx:44
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
Definition: svgusenode.cxx:39
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
Definition: svgusenode.hxx:61
const SvgNumber & getY() const
y content
Definition: svgusenode.hxx:67
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content
Definition: svgusenode.hxx:60
SvgUseNode(SvgDocument &rDocument, SvgNode *pParent)
Definition: svgusenode.cxx:26
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
Definition: svgusenode.cxx:129
bool mbDecomposingSvgNode
detect if maXLink causes a loop to ourself during decomposing
Definition: svgusenode.hxx:47
FilterGroup & rTarget
bool readLocalLink(std::u16string_view rCandidate, OUString &rURL)
Definition: svgtools.cxx:1084
bool readSingleNumber(std::u16string_view rCandidate, SvgNumber &aNum)
Definition: svgtools.cxx:1076
basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const &rInfoProvider)
Definition: svgtools.cxx:871