1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef INCLUDED_SVGIO_SVGREADER_SVGPATTERNNODE_HXX
23 #define INCLUDED_SVGIO_SVGREADER_SVGPATTERNNODE_HXX
24 
25 #include <svgio/svgiodllapi.h>
26 #include <svgio/svgreader/svgnode.hxx>
27 #include <svgio/svgreader/svgstyleattributes.hxx>
28 
29 //////////////////////////////////////////////////////////////////////////////
30 
31 namespace svgio
32 {
33     namespace svgreader
34     {
35         class SvgPatternNode : public SvgNode
36         {
37         private:
38             /// buffered decomposition
39             drawinglayer::primitive2d::Primitive2DSequence aPrimitives;
40 
41             /// use styles
42             SvgStyleAttributes      maSvgStyleAttributes;
43 
44             /// variable scan values, dependent of given XAttributeList
45             basegfx::B2DRange*      mpViewBox;
46             SvgAspectRatio          maSvgAspectRatio;
47             SvgNumber               maX;
48             SvgNumber               maY;
49             SvgNumber               maWidth;
50             SvgNumber               maHeight;
51             SvgUnits*               mpPatternUnits;
52             SvgUnits*               mpPatternContentUnits;
53             basegfx::B2DHomMatrix*  mpaPatternTransform;
54 
55             /// link to another pattern used as style. If maXLink
56             /// is set, the node can be fetched on demand by using
57             // tryToFindLink (buffered)
58             rtl::OUString           maXLink;
59             const SvgPatternNode*   mpXLink;
60 
61             /// link on demand
62             void tryToFindLink();
63 
64         public:
65             SvgPatternNode(
66                 SvgDocument& rDocument,
67                 SvgNode* pParent);
68             virtual ~SvgPatternNode();
69 
70             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
71             virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
72 
73             /// global helpers
74             void getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode& rUser) const;
75 
76             /// get pattern primitives buffered, uses decomposeSvgNode internally
77             const drawinglayer::primitive2d::Primitive2DSequence& getPatternPrimitives() const;
78 
79             /// InfoProvider support for % values
80             virtual const basegfx::B2DRange getCurrentViewPort() const;
81 
82             /// viewBox content
83             const basegfx::B2DRange* getViewBox() const;
setViewBox(const basegfx::B2DRange * pViewBox=0)84             void setViewBox(const basegfx::B2DRange* pViewBox = 0) { if(mpViewBox) delete mpViewBox; mpViewBox = 0; if(pViewBox) mpViewBox = new basegfx::B2DRange(*pViewBox); }
85 
86             /// SvgAspectRatio content
87             const SvgAspectRatio& getSvgAspectRatio() const;
setSvgAspectRatio(const SvgAspectRatio & rSvgAspectRatio=SvgAspectRatio ())88             void setSvgAspectRatio(const SvgAspectRatio& rSvgAspectRatio = SvgAspectRatio()) { maSvgAspectRatio = rSvgAspectRatio; }
89 
90             /// X content, set if found in current context
91             const SvgNumber& getX() const;
setX(const SvgNumber & rX=SvgNumber ())92             void setX(const SvgNumber& rX = SvgNumber()) { maX = rX; }
93 
94             /// Y content, set if found in current context
95             const SvgNumber& getY() const;
setY(const SvgNumber & rY=SvgNumber ())96             void setY(const SvgNumber& rY = SvgNumber()) { maY = rY; }
97 
98             /// Width content, set if found in current context
99             const SvgNumber& getWidth() const;
setWidth(const SvgNumber & rWidth=SvgNumber ())100             void setWidth(const SvgNumber& rWidth = SvgNumber()) { maWidth = rWidth; }
101 
102             /// Height content, set if found in current context
103             const SvgNumber& getHeight() const;
setHeight(const SvgNumber & rHeight=SvgNumber ())104             void setHeight(const SvgNumber& rHeight = SvgNumber()) { maHeight = rHeight; }
105 
106             /// PatternUnits content
107             const SvgUnits* getPatternUnits() const;
setPatternUnits(const SvgUnits aPatternUnits)108             void setPatternUnits(const SvgUnits aPatternUnits) { if(mpPatternUnits) delete mpPatternUnits; mpPatternUnits = 0; mpPatternUnits = new SvgUnits(aPatternUnits); }
109 
110             /// PatternContentUnits content
111             const SvgUnits* getPatternContentUnits() const;
setPatternContentUnits(const SvgUnits aPatternContentUnits)112             void setPatternContentUnits(const SvgUnits aPatternContentUnits) { if(mpPatternContentUnits) delete mpPatternContentUnits; mpPatternContentUnits = 0; mpPatternContentUnits = new SvgUnits(aPatternContentUnits); }
113 
114             /// PatternTransform content
115             const basegfx::B2DHomMatrix* getPatternTransform() const;
setPatternTransform(const basegfx::B2DHomMatrix * pMatrix=0)116             void setPatternTransform(const basegfx::B2DHomMatrix* pMatrix = 0) { if(mpaPatternTransform) delete mpaPatternTransform; mpaPatternTransform = 0; if(pMatrix) mpaPatternTransform = new basegfx::B2DHomMatrix(*pMatrix); }
117 
118         };
119     } // end of namespace svgreader
120 } // end of namespace svgio
121 
122 //////////////////////////////////////////////////////////////////////////////
123 
124 #endif //INCLUDED_SVGIO_SVGREADER_SVGPATTERNNODE_HXX
125 
126 // eof
127