1*ddde725dSArmin Le Grand /**************************************************************
2*ddde725dSArmin Le Grand  *
3*ddde725dSArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
4*ddde725dSArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
5*ddde725dSArmin Le Grand  * distributed with this work for additional information
6*ddde725dSArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
7*ddde725dSArmin Le Grand  * to you under the Apache License, Version 2.0 (the
8*ddde725dSArmin Le Grand  * "License"); you may not use this file except in compliance
9*ddde725dSArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*ddde725dSArmin Le Grand  *
11*ddde725dSArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*ddde725dSArmin Le Grand  *
13*ddde725dSArmin Le Grand  * Unless required by applicable law or agreed to in writing,
14*ddde725dSArmin Le Grand  * software distributed under the License is distributed on an
15*ddde725dSArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ddde725dSArmin Le Grand  * KIND, either express or implied.  See the License for the
17*ddde725dSArmin Le Grand  * specific language governing permissions and limitations
18*ddde725dSArmin Le Grand  * under the License.
19*ddde725dSArmin Le Grand  *
20*ddde725dSArmin Le Grand  *************************************************************/
21*ddde725dSArmin Le Grand 
22*ddde725dSArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
23*ddde725dSArmin Le Grand #include "precompiled_svgio.hxx"
24*ddde725dSArmin Le Grand 
25*ddde725dSArmin Le Grand #include <svgio/svgreader/svgsvgnode.hxx>
26*ddde725dSArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx>
27*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
28*ddde725dSArmin Le Grand #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
29*ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx>
30*ddde725dSArmin Le Grand #include <basegfx/polygon/b2dpolygon.hxx>
31*ddde725dSArmin Le Grand #include <basegfx/matrix/b2dhommatrixtools.hxx>
32*ddde725dSArmin Le Grand 
33*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
34*ddde725dSArmin Le Grand 
35*ddde725dSArmin Le Grand namespace svgio
36*ddde725dSArmin Le Grand {
37*ddde725dSArmin Le Grand     namespace svgreader
38*ddde725dSArmin Le Grand     {
39*ddde725dSArmin Le Grand         SvgSvgNode::SvgSvgNode(
40*ddde725dSArmin Le Grand             SvgDocument& rDocument,
41*ddde725dSArmin Le Grand             SvgNode* pParent)
42*ddde725dSArmin Le Grand         :   SvgNode(SVGTokenSvg, rDocument, pParent),
43*ddde725dSArmin Le Grand             maSvgStyleAttributes(*this),
44*ddde725dSArmin Le Grand             mpViewBox(0),
45*ddde725dSArmin Le Grand             maSvgAspectRatio(),
46*ddde725dSArmin Le Grand             maX(),
47*ddde725dSArmin Le Grand             maY(),
48*ddde725dSArmin Le Grand             maWidth(),
49*ddde725dSArmin Le Grand             maHeight(),
50*ddde725dSArmin Le Grand             maVersion()
51*ddde725dSArmin Le Grand         {
52*ddde725dSArmin Le Grand             if(!getParent())
53*ddde725dSArmin Le Grand             {
54*ddde725dSArmin Le Grand                 // initial fill is black
55*ddde725dSArmin Le Grand                 maSvgStyleAttributes.setFill(SvgPaint(basegfx::BColor(0.0, 0.0, 0.0), true, true));
56*ddde725dSArmin Le Grand             }
57*ddde725dSArmin Le Grand         }
58*ddde725dSArmin Le Grand 
59*ddde725dSArmin Le Grand         SvgSvgNode::~SvgSvgNode()
60*ddde725dSArmin Le Grand         {
61*ddde725dSArmin Le Grand             if(mpViewBox) delete mpViewBox;
62*ddde725dSArmin Le Grand         }
63*ddde725dSArmin Le Grand 
64*ddde725dSArmin Le Grand         const SvgStyleAttributes* SvgSvgNode::getSvgStyleAttributes() const
65*ddde725dSArmin Le Grand         {
66*ddde725dSArmin Le Grand             return &maSvgStyleAttributes;
67*ddde725dSArmin Le Grand         }
68*ddde725dSArmin Le Grand 
69*ddde725dSArmin Le Grand         void SvgSvgNode::parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent)
70*ddde725dSArmin Le Grand         {
71*ddde725dSArmin Le Grand             // call parent
72*ddde725dSArmin Le Grand             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
73*ddde725dSArmin Le Grand 
74*ddde725dSArmin Le Grand             // read style attributes
75*ddde725dSArmin Le Grand             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
76*ddde725dSArmin Le Grand 
77*ddde725dSArmin Le Grand             // parse own
78*ddde725dSArmin Le Grand             switch(aSVGToken)
79*ddde725dSArmin Le Grand             {
80*ddde725dSArmin Le Grand                 case SVGTokenStyle:
81*ddde725dSArmin Le Grand                 {
82*ddde725dSArmin Le Grand                     maSvgStyleAttributes.readStyle(aContent);
83*ddde725dSArmin Le Grand                     break;
84*ddde725dSArmin Le Grand                 }
85*ddde725dSArmin Le Grand                 case SVGTokenViewBox:
86*ddde725dSArmin Le Grand                 {
87*ddde725dSArmin Le Grand                     const basegfx::B2DRange aRange(readViewBox(aContent, *this));
88*ddde725dSArmin Le Grand 
89*ddde725dSArmin Le Grand                     if(!aRange.isEmpty())
90*ddde725dSArmin Le Grand                     {
91*ddde725dSArmin Le Grand                         setViewBox(&aRange);
92*ddde725dSArmin Le Grand                     }
93*ddde725dSArmin Le Grand                     break;
94*ddde725dSArmin Le Grand                 }
95*ddde725dSArmin Le Grand                 case SVGTokenPreserveAspectRatio:
96*ddde725dSArmin Le Grand                 {
97*ddde725dSArmin Le Grand                     setSvgAspectRatio(readSvgAspectRatio(aContent));
98*ddde725dSArmin Le Grand                     break;
99*ddde725dSArmin Le Grand                 }
100*ddde725dSArmin Le Grand                 case SVGTokenX:
101*ddde725dSArmin Le Grand                 {
102*ddde725dSArmin Le Grand                     SvgNumber aNum;
103*ddde725dSArmin Le Grand 
104*ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
105*ddde725dSArmin Le Grand                     {
106*ddde725dSArmin Le Grand                         setX(aNum);
107*ddde725dSArmin Le Grand                     }
108*ddde725dSArmin Le Grand                     break;
109*ddde725dSArmin Le Grand                 }
110*ddde725dSArmin Le Grand                 case SVGTokenY:
111*ddde725dSArmin Le Grand                 {
112*ddde725dSArmin Le Grand                     SvgNumber aNum;
113*ddde725dSArmin Le Grand 
114*ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
115*ddde725dSArmin Le Grand                     {
116*ddde725dSArmin Le Grand                         setY(aNum);
117*ddde725dSArmin Le Grand                     }
118*ddde725dSArmin Le Grand                     break;
119*ddde725dSArmin Le Grand                 }
120*ddde725dSArmin Le Grand                 case SVGTokenWidth:
121*ddde725dSArmin Le Grand                 {
122*ddde725dSArmin Le Grand                     SvgNumber aNum;
123*ddde725dSArmin Le Grand 
124*ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
125*ddde725dSArmin Le Grand                     {
126*ddde725dSArmin Le Grand                         if(aNum.isPositive())
127*ddde725dSArmin Le Grand                         {
128*ddde725dSArmin Le Grand                             setWidth(aNum);
129*ddde725dSArmin Le Grand                         }
130*ddde725dSArmin Le Grand                     }
131*ddde725dSArmin Le Grand                     break;
132*ddde725dSArmin Le Grand                 }
133*ddde725dSArmin Le Grand                 case SVGTokenHeight:
134*ddde725dSArmin Le Grand                 {
135*ddde725dSArmin Le Grand                     SvgNumber aNum;
136*ddde725dSArmin Le Grand 
137*ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
138*ddde725dSArmin Le Grand                     {
139*ddde725dSArmin Le Grand                         if(aNum.isPositive())
140*ddde725dSArmin Le Grand                         {
141*ddde725dSArmin Le Grand                             setHeight(aNum);
142*ddde725dSArmin Le Grand                         }
143*ddde725dSArmin Le Grand                     }
144*ddde725dSArmin Le Grand                     break;
145*ddde725dSArmin Le Grand                 }
146*ddde725dSArmin Le Grand                 case SVGTokenVersion:
147*ddde725dSArmin Le Grand                 {
148*ddde725dSArmin Le Grand                     SvgNumber aNum;
149*ddde725dSArmin Le Grand 
150*ddde725dSArmin Le Grand                     if(readSingleNumber(aContent, aNum))
151*ddde725dSArmin Le Grand                     {
152*ddde725dSArmin Le Grand                         setVersion(aNum);
153*ddde725dSArmin Le Grand                     }
154*ddde725dSArmin Le Grand                     break;
155*ddde725dSArmin Le Grand                 }
156*ddde725dSArmin Le Grand             }
157*ddde725dSArmin Le Grand         }
158*ddde725dSArmin Le Grand 
159*ddde725dSArmin Le Grand         void SvgSvgNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const
160*ddde725dSArmin Le Grand         {
161*ddde725dSArmin Le Grand             drawinglayer::primitive2d::Primitive2DSequence aSequence;
162*ddde725dSArmin Le Grand 
163*ddde725dSArmin Le Grand             // decompose childs
164*ddde725dSArmin Le Grand             SvgNode::decomposeSvgNode(aSequence, bReferenced);
165*ddde725dSArmin Le Grand 
166*ddde725dSArmin Le Grand             if(aSequence.hasElements())
167*ddde725dSArmin Le Grand             {
168*ddde725dSArmin Le Grand                 if(getParent())
169*ddde725dSArmin Le Grand                 {
170*ddde725dSArmin Le Grand                     if(getViewBox())
171*ddde725dSArmin Le Grand                     {
172*ddde725dSArmin Le Grand                         // Svg defines that with no width or no height the viewBox content is empty,
173*ddde725dSArmin Le Grand                         // so both need to exist
174*ddde725dSArmin Le Grand                         if(!basegfx::fTools::equalZero(getViewBox()->getWidth()) && !basegfx::fTools::equalZero(getViewBox()->getHeight()))
175*ddde725dSArmin Le Grand                         {
176*ddde725dSArmin Le Grand                             // create target range homing x,y, width and height as given
177*ddde725dSArmin Le Grand                             const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
178*ddde725dSArmin Le Grand                             const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
179*ddde725dSArmin Le Grand                             const double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) : getViewBox()->getWidth());
180*ddde725dSArmin Le Grand                             const double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate) : getViewBox()->getHeight());
181*ddde725dSArmin Le Grand                             const basegfx::B2DRange aTarget(fX, fY, fX + fW, fY + fH);
182*ddde725dSArmin Le Grand 
183*ddde725dSArmin Le Grand                             if(aTarget.equal(*getViewBox()))
184*ddde725dSArmin Le Grand                             {
185*ddde725dSArmin Le Grand                                 // no mapping needed, append
186*ddde725dSArmin Le Grand                                 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aSequence);
187*ddde725dSArmin Le Grand                             }
188*ddde725dSArmin Le Grand                             else
189*ddde725dSArmin Le Grand                             {
190*ddde725dSArmin Le Grand                                 // create mapping
191*ddde725dSArmin Le Grand                                 const SvgAspectRatio& rRatio = getSvgAspectRatio();
192*ddde725dSArmin Le Grand 
193*ddde725dSArmin Le Grand                                 if(rRatio.isSet())
194*ddde725dSArmin Le Grand                                 {
195*ddde725dSArmin Le Grand                                     // let mapping be created from SvgAspectRatio
196*ddde725dSArmin Le Grand                                     const basegfx::B2DHomMatrix aEmbeddingTransform(
197*ddde725dSArmin Le Grand                                         rRatio.createMapping(aTarget, *getViewBox()));
198*ddde725dSArmin Le Grand 
199*ddde725dSArmin Le Grand                                     // prepare embedding in transformation
200*ddde725dSArmin Le Grand                                     const drawinglayer::primitive2d::Primitive2DReference xRef(
201*ddde725dSArmin Le Grand                                         new drawinglayer::primitive2d::TransformPrimitive2D(
202*ddde725dSArmin Le Grand                                             aEmbeddingTransform,
203*ddde725dSArmin Le Grand                                             aSequence));
204*ddde725dSArmin Le Grand 
205*ddde725dSArmin Le Grand                                     if(rRatio.isMeetOrSlice())
206*ddde725dSArmin Le Grand                                     {
207*ddde725dSArmin Le Grand                                         // embed in transformation
208*ddde725dSArmin Le Grand                                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xRef);
209*ddde725dSArmin Le Grand                                     }
210*ddde725dSArmin Le Grand                                     else
211*ddde725dSArmin Le Grand                                     {
212*ddde725dSArmin Le Grand                                         // need to embed in MaskPrimitive2D, too
213*ddde725dSArmin Le Grand                                         const drawinglayer::primitive2d::Primitive2DReference xMask(
214*ddde725dSArmin Le Grand                                             new drawinglayer::primitive2d::MaskPrimitive2D(
215*ddde725dSArmin Le Grand                                                 basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aTarget)),
216*ddde725dSArmin Le Grand                                                 drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1)));
217*ddde725dSArmin Le Grand 
218*ddde725dSArmin Le Grand                                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xMask);
219*ddde725dSArmin Le Grand                                     }
220*ddde725dSArmin Le Grand                                 }
221*ddde725dSArmin Le Grand                                 else
222*ddde725dSArmin Le Grand                                 {
223*ddde725dSArmin Le Grand                                     // choose default mapping
224*ddde725dSArmin Le Grand                                     const basegfx::B2DHomMatrix aEmbeddingTransform(
225*ddde725dSArmin Le Grand                                         rRatio.createLinearMapping(
226*ddde725dSArmin Le Grand                                             aTarget, *getViewBox()));
227*ddde725dSArmin Le Grand 
228*ddde725dSArmin Le Grand                                     // embed in transformation
229*ddde725dSArmin Le Grand                                     const drawinglayer::primitive2d::Primitive2DReference xTransform(
230*ddde725dSArmin Le Grand                                         new drawinglayer::primitive2d::TransformPrimitive2D(
231*ddde725dSArmin Le Grand                                             aEmbeddingTransform,
232*ddde725dSArmin Le Grand                                             aSequence));
233*ddde725dSArmin Le Grand 
234*ddde725dSArmin Le Grand                                     drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xTransform);
235*ddde725dSArmin Le Grand                                 }
236*ddde725dSArmin Le Grand                             }
237*ddde725dSArmin Le Grand                         }
238*ddde725dSArmin Le Grand                     }
239*ddde725dSArmin Le Grand                     else
240*ddde725dSArmin Le Grand                     {
241*ddde725dSArmin Le Grand                         // check if we have a size
242*ddde725dSArmin Le Grand                         const double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) : 0.0);
243*ddde725dSArmin Le Grand                         const double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate) : 0.0);
244*ddde725dSArmin Le Grand 
245*ddde725dSArmin Le Grand                         // Svg defines that a negative value is an error and that 0.0 disables rendering
246*ddde725dSArmin Le Grand                         if(basegfx::fTools::more(fW, 0.0) && basegfx::fTools::more(fH, 0.0))
247*ddde725dSArmin Le Grand                         {
248*ddde725dSArmin Le Grand                             // check if we have a x,y position
249*ddde725dSArmin Le Grand                             const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
250*ddde725dSArmin Le Grand                             const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
251*ddde725dSArmin Le Grand 
252*ddde725dSArmin Le Grand                             if(!basegfx::fTools::equalZero(fX) || !basegfx::fTools::equalZero(fY))
253*ddde725dSArmin Le Grand                             {
254*ddde725dSArmin Le Grand                                 // embed in transform
255*ddde725dSArmin Le Grand                                 const drawinglayer::primitive2d::Primitive2DReference xRef(
256*ddde725dSArmin Le Grand                                     new drawinglayer::primitive2d::TransformPrimitive2D(
257*ddde725dSArmin Le Grand                                         basegfx::tools::createTranslateB2DHomMatrix(fX, fY),
258*ddde725dSArmin Le Grand                                         aSequence));
259*ddde725dSArmin Le Grand 
260*ddde725dSArmin Le Grand                                 aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xRef, 1);
261*ddde725dSArmin Le Grand                             }
262*ddde725dSArmin Le Grand 
263*ddde725dSArmin Le Grand                             // embed in MaskPrimitive2D to clip
264*ddde725dSArmin Le Grand                             const drawinglayer::primitive2d::Primitive2DReference xMask(
265*ddde725dSArmin Le Grand                                 new drawinglayer::primitive2d::MaskPrimitive2D(
266*ddde725dSArmin Le Grand                                     basegfx::B2DPolyPolygon(
267*ddde725dSArmin Le Grand                                         basegfx::tools::createPolygonFromRect(
268*ddde725dSArmin Le Grand                                             basegfx::B2DRange(fX, fY, fX + fW, fY + fH))),
269*ddde725dSArmin Le Grand                                     aSequence));
270*ddde725dSArmin Le Grand 
271*ddde725dSArmin Le Grand                             // append
272*ddde725dSArmin Le Grand                             drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xMask);
273*ddde725dSArmin Le Grand                         }
274*ddde725dSArmin Le Grand                     }
275*ddde725dSArmin Le Grand                 }
276*ddde725dSArmin Le Grand                 else
277*ddde725dSArmin Le Grand                 {
278*ddde725dSArmin Le Grand                     // Outermost SVG element; create target range homing width and height as given.
279*ddde725dSArmin Le Grand                     // SVG defines that x,y has no meanig for the outermost SVG element. Use a fallback
280*ddde725dSArmin Le Grand                     // width and height of din A 4 (21 x 29,7 cm)
281*ddde725dSArmin Le Grand                     double fW(getWidth().isSet() ? getWidth().solve(*this, xcoordinate) : (210.0 * 3.543307));
282*ddde725dSArmin Le Grand                     double fH(getHeight().isSet() ? getHeight().solve(*this, ycoordinate) : (297.0 * 3.543307));
283*ddde725dSArmin Le Grand 
284*ddde725dSArmin Le Grand                     // Svg defines that a negative value is an error and that 0.0 disables rendering
285*ddde725dSArmin Le Grand                     if(basegfx::fTools::more(fW, 0.0) && basegfx::fTools::more(fH, 0.0))
286*ddde725dSArmin Le Grand                     {
287*ddde725dSArmin Le Grand                         const basegfx::B2DRange aSvgCanvasRange(0.0, 0.0, fW, fH);
288*ddde725dSArmin Le Grand 
289*ddde725dSArmin Le Grand                         if(getViewBox())
290*ddde725dSArmin Le Grand                         {
291*ddde725dSArmin Le Grand                             if(!basegfx::fTools::equalZero(getViewBox()->getWidth()) && !basegfx::fTools::equalZero(getViewBox()->getHeight()))
292*ddde725dSArmin Le Grand                             {
293*ddde725dSArmin Le Grand                                 // create mapping
294*ddde725dSArmin Le Grand                                 const SvgAspectRatio& rRatio = getSvgAspectRatio();
295*ddde725dSArmin Le Grand                                 basegfx::B2DHomMatrix aViewBoxMapping;
296*ddde725dSArmin Le Grand 
297*ddde725dSArmin Le Grand                                 if(rRatio.isSet())
298*ddde725dSArmin Le Grand                                 {
299*ddde725dSArmin Le Grand                                     // let mapping be created from SvgAspectRatio
300*ddde725dSArmin Le Grand                                     aViewBoxMapping = rRatio.createMapping(aSvgCanvasRange, *getViewBox());
301*ddde725dSArmin Le Grand 
302*ddde725dSArmin Le Grand                                     // no need to check ratio here for slice, the outermost Svg will
303*ddde725dSArmin Le Grand                                     // be clipped anyways (see below)
304*ddde725dSArmin Le Grand                                 }
305*ddde725dSArmin Le Grand                                 else
306*ddde725dSArmin Le Grand                                 {
307*ddde725dSArmin Le Grand                                     // choose default mapping
308*ddde725dSArmin Le Grand                                     aViewBoxMapping = rRatio.createLinearMapping(aSvgCanvasRange, *getViewBox());
309*ddde725dSArmin Le Grand                                 }
310*ddde725dSArmin Le Grand 
311*ddde725dSArmin Le Grand                                 // scale content to viewBox definitions
312*ddde725dSArmin Le Grand                                 const drawinglayer::primitive2d::Primitive2DReference xTransform(
313*ddde725dSArmin Le Grand                                     new drawinglayer::primitive2d::TransformPrimitive2D(
314*ddde725dSArmin Le Grand                                         aViewBoxMapping,
315*ddde725dSArmin Le Grand                                         aSequence));
316*ddde725dSArmin Le Grand 
317*ddde725dSArmin Le Grand                                 aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xTransform, 1);
318*ddde725dSArmin Le Grand                             }
319*ddde725dSArmin Le Grand                         }
320*ddde725dSArmin Le Grand 
321*ddde725dSArmin Le Grand                         // to be completely correct in Svg sense it is necessary to clip
322*ddde725dSArmin Le Grand                         // the whole content to the given canvas. I choose here to do this
323*ddde725dSArmin Le Grand                         // initially despite I found various examples of Svg files out there
324*ddde725dSArmin Le Grand                         // which have no correct values for this clipping. It's correct
325*ddde725dSArmin Le Grand                         // due to the Svg spec.
326*ddde725dSArmin Le Grand                         bool bDoCorrectCanvasClipping(true);
327*ddde725dSArmin Le Grand 
328*ddde725dSArmin Le Grand                         if(bDoCorrectCanvasClipping)
329*ddde725dSArmin Le Grand                         {
330*ddde725dSArmin Le Grand                             // different from Svg we have the possibility with primitives to get
331*ddde725dSArmin Le Grand                             // a correct bounding box for the geometry, thhus I will allow to
332*ddde725dSArmin Le Grand                             // only clip if necessary. This will make Svg images evtl. smaller
333*ddde725dSArmin Le Grand                             // than wanted from Svg (the free space which may be around it is
334*ddde725dSArmin Le Grand                             // conform to the Svg spec), but avoids an expensive and unneccessary
335*ddde725dSArmin Le Grand                             // clip.
336*ddde725dSArmin Le Grand                             const basegfx::B2DRange aContentRange(
337*ddde725dSArmin Le Grand                                 drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(
338*ddde725dSArmin Le Grand                                     aSequence,
339*ddde725dSArmin Le Grand                                     drawinglayer::geometry::ViewInformation2D()));
340*ddde725dSArmin Le Grand 
341*ddde725dSArmin Le Grand                             if(!aSvgCanvasRange.isInside(aContentRange))
342*ddde725dSArmin Le Grand                             {
343*ddde725dSArmin Le Grand                                 const drawinglayer::primitive2d::Primitive2DReference xMask(
344*ddde725dSArmin Le Grand                                     new drawinglayer::primitive2d::MaskPrimitive2D(
345*ddde725dSArmin Le Grand                                         basegfx::B2DPolyPolygon(
346*ddde725dSArmin Le Grand                                             basegfx::tools::createPolygonFromRect(
347*ddde725dSArmin Le Grand                                                 aSvgCanvasRange)),
348*ddde725dSArmin Le Grand                                         aSequence));
349*ddde725dSArmin Le Grand 
350*ddde725dSArmin Le Grand                                 aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xMask, 1);
351*ddde725dSArmin Le Grand                             }
352*ddde725dSArmin Le Grand                         }
353*ddde725dSArmin Le Grand 
354*ddde725dSArmin Le Grand                         {
355*ddde725dSArmin Le Grand                             // embed in transform primitive to scale to 1/100th mm
356*ddde725dSArmin Le Grand                             // where 1 mm == 3.543307 px to get from Svg coordinates to
357*ddde725dSArmin Le Grand                             // drawinglayer ones
358*ddde725dSArmin Le Grand                             const double fScaleTo100thmm(100.0 / 3.543307);
359*ddde725dSArmin Le Grand                             const basegfx::B2DHomMatrix aTransform(
360*ddde725dSArmin Le Grand                                 basegfx::tools::createScaleB2DHomMatrix(
361*ddde725dSArmin Le Grand                                     fScaleTo100thmm,
362*ddde725dSArmin Le Grand                                     fScaleTo100thmm));
363*ddde725dSArmin Le Grand 
364*ddde725dSArmin Le Grand                             const drawinglayer::primitive2d::Primitive2DReference xTransform(
365*ddde725dSArmin Le Grand                                 new drawinglayer::primitive2d::TransformPrimitive2D(
366*ddde725dSArmin Le Grand                                     aTransform,
367*ddde725dSArmin Le Grand                                     aSequence));
368*ddde725dSArmin Le Grand 
369*ddde725dSArmin Le Grand                             aSequence = drawinglayer::primitive2d::Primitive2DSequence(&xTransform, 1);
370*ddde725dSArmin Le Grand                         }
371*ddde725dSArmin Le Grand 
372*ddde725dSArmin Le Grand                         // append
373*ddde725dSArmin Le Grand                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aSequence);
374*ddde725dSArmin Le Grand                     }
375*ddde725dSArmin Le Grand                 }
376*ddde725dSArmin Le Grand             }
377*ddde725dSArmin Le Grand         }
378*ddde725dSArmin Le Grand 
379*ddde725dSArmin Le Grand         const basegfx::B2DRange* SvgSvgNode::getCurrentViewPort() const
380*ddde725dSArmin Le Grand         {
381*ddde725dSArmin Le Grand             if(getViewBox())
382*ddde725dSArmin Le Grand             {
383*ddde725dSArmin Le Grand                 return getViewBox();
384*ddde725dSArmin Le Grand             }
385*ddde725dSArmin Le Grand             else
386*ddde725dSArmin Le Grand             {
387*ddde725dSArmin Le Grand                 return SvgNode::getCurrentViewPort();
388*ddde725dSArmin Le Grand             }
389*ddde725dSArmin Le Grand         }
390*ddde725dSArmin Le Grand 
391*ddde725dSArmin Le Grand     } // end of namespace svgreader
392*ddde725dSArmin Le Grand } // end of namespace svgio
393*ddde725dSArmin Le Grand 
394*ddde725dSArmin Le Grand //////////////////////////////////////////////////////////////////////////////
395*ddde725dSArmin Le Grand // eof
396