1ddde725dSArmin Le Grand /**************************************************************
2ddde725dSArmin Le Grand  *
3ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5ddde725dSArmin Le Grand  * distributed with this work for additional information
6ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10ddde725dSArmin Le Grand  *
11ddde725dSArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12ddde725dSArmin Le Grand  *
13ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18ddde725dSArmin Le Grand  * under the License.
19ddde725dSArmin Le Grand  *
20ddde725dSArmin Le Grand  *************************************************************/
21ddde725dSArmin Le Grand 
22ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23ddde725dSArmin Le Grand #include "precompiled_svgio.hxx"
24ddde725dSArmin Le Grand 
25ddde725dSArmin Le Grand #include <svgio/svgreader/svgusenode.hxx>
26ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
27ddde725dSArmin Le Grand #include <svgio/svgreader/svgdocument.hxx>
28ddde725dSArmin Le Grand 
29ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
30ddde725dSArmin Le Grand 
31ddde725dSArmin Le Grand namespace svgio
32ddde725dSArmin Le Grand {
33ddde725dSArmin Le Grand     namespace svgreader
34ddde725dSArmin Le Grand     {
35ddde725dSArmin Le Grand         SvgUseNode::SvgUseNode(
36ddde725dSArmin Le Grand             SvgDocument& rDocument,
37ddde725dSArmin Le Grand             SvgNode* pParent)
38ddde725dSArmin Le Grand         :   SvgNode(SVGTokenG, rDocument, pParent),
39ddde725dSArmin Le Grand             maSvgStyleAttributes(*this),
40ddde725dSArmin Le Grand             mpaTransform(0),
41ddde725dSArmin Le Grand             maX(),
42ddde725dSArmin Le Grand             maY(),
43ddde725dSArmin Le Grand             maWidth(),
44ddde725dSArmin Le Grand             maHeight(),
45ddde725dSArmin Le Grand             maXLink()
46ddde725dSArmin Le Grand         {
47ddde725dSArmin Le Grand         }
48ddde725dSArmin Le Grand 
49ddde725dSArmin Le Grand         SvgUseNode::~SvgUseNode()
50ddde725dSArmin Le Grand         {
51ddde725dSArmin Le Grand             if(mpaTransform) delete mpaTransform;
52ddde725dSArmin Le Grand         }
53ddde725dSArmin Le Grand 
54ddde725dSArmin Le Grand         const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
55ddde725dSArmin Le Grand         {
56ddde725dSArmin Le Grand             return &maSvgStyleAttributes;
57ddde725dSArmin Le Grand         }
58ddde725dSArmin Le Grand 
59ddde725dSArmin Le Grand         void SvgUseNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
60ddde725dSArmin Le Grand         {
61ddde725dSArmin Le Grand             // call parent
62ddde725dSArmin Le Grand             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
63ddde725dSArmin Le Grand 
64ddde725dSArmin Le Grand             // read style attributes
65ddde725dSArmin Le Grand             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
66ddde725dSArmin Le Grand 
67ddde725dSArmin Le Grand             // parse own
68ddde725dSArmin Le Grand             switch(aSVGToken)
69ddde725dSArmin Le Grand             {
70ddde725dSArmin Le Grand                 case SVGTokenStyle:
71ddde725dSArmin Le Grand                 {
72ddde725dSArmin Le Grand                     maSvgStyleAttributes.readStyle(aContent);
73ddde725dSArmin Le Grand                     break;
74ddde725dSArmin Le Grand                 }
75ddde725dSArmin Le Grand                 case SVGTokenTransform:
76ddde725dSArmin Le Grand                 {
77ddde725dSArmin Le Grand                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
78ddde725dSArmin Le Grand 
79ddde725dSArmin Le Grand                     if(!aMatrix.isIdentity())
80ddde725dSArmin Le Grand                     {
81ddde725dSArmin Le Grand                         setTransform(&aMatrix);
82ddde725dSArmin Le Grand                     }
83ddde725dSArmin Le Grand                     break;
84ddde725dSArmin Le Grand                 }
85ddde725dSArmin Le Grand                 case SVGTokenX:
86ddde725dSArmin Le Grand                 {
87ddde725dSArmin Le Grand                     SvgNumber aNum;
88ddde725dSArmin Le Grand 
89ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
90ddde725dSArmin Le Grand                     {
91ddde725dSArmin Le Grand                         setX(aNum);
92ddde725dSArmin Le Grand                     }
93ddde725dSArmin Le Grand                     break;
94ddde725dSArmin Le Grand                 }
95ddde725dSArmin Le Grand                 case SVGTokenY:
96ddde725dSArmin Le Grand                 {
97ddde725dSArmin Le Grand                     SvgNumber aNum;
98ddde725dSArmin Le Grand 
99ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
100ddde725dSArmin Le Grand                     {
101ddde725dSArmin Le Grand                         setY(aNum);
102ddde725dSArmin Le Grand                     }
103ddde725dSArmin Le Grand                     break;
104ddde725dSArmin Le Grand                 }
105ddde725dSArmin Le Grand                 case SVGTokenWidth:
106ddde725dSArmin Le Grand                 {
107ddde725dSArmin Le Grand                     SvgNumber aNum;
108ddde725dSArmin Le Grand 
109ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
110ddde725dSArmin Le Grand                     {
111ddde725dSArmin Le Grand                         if(aNum.isPositive())
112ddde725dSArmin Le Grand                         {
113ddde725dSArmin Le Grand                             setWidth(aNum);
114ddde725dSArmin Le Grand                         }
115ddde725dSArmin Le Grand                     }
116ddde725dSArmin Le Grand                     break;
117ddde725dSArmin Le Grand                 }
118ddde725dSArmin Le Grand                 case SVGTokenHeight:
119ddde725dSArmin Le Grand                 {
120ddde725dSArmin Le Grand                     SvgNumber aNum;
121ddde725dSArmin Le Grand 
122ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
123ddde725dSArmin Le Grand                     {
124ddde725dSArmin Le Grand                         if(aNum.isPositive())
125ddde725dSArmin Le Grand                         {
126ddde725dSArmin Le Grand                             setHeight(aNum);
127ddde725dSArmin Le Grand                         }
128ddde725dSArmin Le Grand                     }
129ddde725dSArmin Le Grand                 }
130ddde725dSArmin Le Grand                 case SVGTokenXlinkHref:
131ddde725dSArmin Le Grand                 {
132ddde725dSArmin Le Grand                     const sal_Int32 nLen(aContent.getLength());
133ddde725dSArmin Le Grand 
134ddde725dSArmin Le Grand                     if(nLen && sal_Unicode('#') == aContent[0])
135ddde725dSArmin Le Grand                     {
136ddde725dSArmin Le Grand                         maXLink = aContent.copy(1);
137ddde725dSArmin Le Grand                     }
138ddde725dSArmin Le Grand                     break;
139ddde725dSArmin Le Grand                 }
140*e2bf1e9dSArmin Le Grand                 default:
141*e2bf1e9dSArmin Le Grand                 {
142*e2bf1e9dSArmin Le Grand                     break;
143*e2bf1e9dSArmin Le Grand                 }
144ddde725dSArmin Le Grand             }
145ddde725dSArmin Le Grand         }
146ddde725dSArmin Le Grand 
147*e2bf1e9dSArmin Le Grand         void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
148ddde725dSArmin Le Grand         {
149ddde725dSArmin Le Grand             // try to access link to content
150ddde725dSArmin Le Grand             const SvgNode* mpXLink = getDocument().findSvgNodeById(maXLink);
151ddde725dSArmin Le Grand 
152ddde725dSArmin Le Grand             if(mpXLink)
153ddde725dSArmin Le Grand             {
154ddde725dSArmin Le Grand                 // decompose childs
155ddde725dSArmin Le Grand                 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
156ddde725dSArmin Le Grand 
157ddde725dSArmin Le Grand                 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
158ddde725dSArmin Le Grand                 // SVG docs want the getWidth() and getHeight() from this node
159ddde725dSArmin Le Grand                 // to be valid for the subtree.
160ddde725dSArmin Le Grand                 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(this);
161ddde725dSArmin Le Grand                 mpXLink->decomposeSvgNode(aNewTarget, true);
162ddde725dSArmin Le Grand                 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(0);
163ddde725dSArmin Le Grand 
164ddde725dSArmin Le Grand                 if(aNewTarget.hasElements())
165ddde725dSArmin Le Grand                 {
166ddde725dSArmin Le Grand                     basegfx::B2DHomMatrix aTransform;
167ddde725dSArmin Le Grand 
168ddde725dSArmin Le Grand                     if(getX().isSet() || getY().isSet())
169ddde725dSArmin Le Grand                     {
170ddde725dSArmin Le Grand                         aTransform.translate(
171ddde725dSArmin Le Grand                             getX().solve(*this, xcoordinate),
172ddde725dSArmin Le Grand                             getY().solve(*this, ycoordinate));
173ddde725dSArmin Le Grand                     }
174ddde725dSArmin Le Grand 
175ddde725dSArmin Le Grand                     if(getTransform())
176ddde725dSArmin Le Grand                     {
177ddde725dSArmin Le Grand                         aTransform = *getTransform() * aTransform;
178ddde725dSArmin Le Grand                     }
179ddde725dSArmin Le Grand 
180ddde725dSArmin Le Grand                     if(!aTransform.isIdentity())
181ddde725dSArmin Le Grand                     {
182ddde725dSArmin Le Grand                         const drawinglayer::primitive2d::Primitive2DReference xRef(
183ddde725dSArmin Le Grand                             new drawinglayer::primitive2d::TransformPrimitive2D(
184ddde725dSArmin Le Grand                                 aTransform,
185ddde725dSArmin Le Grand                                 aNewTarget));
186ddde725dSArmin Le Grand 
187ddde725dSArmin Le Grand                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xRef);
188ddde725dSArmin Le Grand                     }
189ddde725dSArmin Le Grand                     else
190ddde725dSArmin Le Grand                     {
191ddde725dSArmin Le Grand                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
192ddde725dSArmin Le Grand                     }
193ddde725dSArmin Le Grand                 }
194ddde725dSArmin Le Grand             }
195ddde725dSArmin Le Grand         }
196ddde725dSArmin Le Grand 
197ddde725dSArmin Le Grand     } // end of namespace svgreader
198ddde725dSArmin Le Grand } // end of namespace svgio
199ddde725dSArmin Le Grand 
200ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
201ddde725dSArmin Le Grand // eof
202