xref: /AOO41X/main/svgio/inc/svgio/svgreader/svgnode.hxx (revision ab4b560eb121751a83af6a2bd9439e1ac417a6d0)
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_SVGNODE_HXX
23 #define INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
24 
25 #include <svgio/svgiodllapi.h>
26 #include <svgio/svgreader/svgtools.hxx>
27 #include <svgio/svgreader/svgtoken.hxx>
28 #include <svgio/svgreader/svgpaint.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <com/sun/star/xml/sax/XAttributeList.hpp>
31 #include <vector>
32 #include <hash_map>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 // predefines
36 namespace svgio
37 {
38     namespace svgreader
39     {
40         class SvgNode;
41         class SvgDocument;
42         class SvgStyleAttributes;
43     }
44 }
45 
46 //////////////////////////////////////////////////////////////////////////////
47 
48 namespace svgio
49 {
50     namespace svgreader
51     {
52         typedef ::std::vector< SvgNode* > SvgNodeVector;
53         typedef ::std::vector< const SvgStyleAttributes* > SvgStyleAttributeVector;
54 
55         enum XmlSpace
56         {
57             XmlSpace_notset,
58             XmlSpace_default,
59             XmlSpace_preserve
60         };
61 
62         // display property (see SVG 1.1. 11.5), not inheritable
63         enum Display // #121656#
64         {
65             Display_inline, // the default
66             Display_block,
67             Display_list_item,
68             Display_run_in,
69             Display_compact,
70             Display_marker,
71             Display_table,
72             Display_inline_table,
73             Display_table_row_group,
74             Display_table_header_group,
75             Display_table_footer_group,
76             Display_table_row,
77             Display_table_column_group,
78             Display_table_column,
79             Display_table_cell,
80             Display_table_caption,
81             Display_none,
82             Display_inherit
83         };
84 
85         class SvgNode : private boost::noncopyable, public InfoProvider
86         {
87         private:
88             /// basic data, Type, document we belong to and parent (if not root)
89             SVGToken                    maType;
90             SvgDocument&                mrDocument;
91             const SvgNode*              mpParent;
92             const SvgNode*              mpAlternativeParent;
93 
94             /// sub hierarchy
95             SvgNodeVector               maChildren;
96 
97             /// Id svan value
98             rtl::OUString*              mpId;
99 
100             /// Class svan value
101             rtl::OUString*              mpClass;
102 
103             /// XmlSpace value
104             XmlSpace                    maXmlSpace;
105 
106             /// Display value #121656#
107             Display                     maDisplay;
108 
109             /// CSS styles
110             SvgStyleAttributeVector     maCssStyleVector;
111 
112         protected:
113             /// helper to evtl. link to css style
114             const SvgStyleAttributes* checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
115 
116         public:
117             SvgNode(
118                 SVGToken aType,
119                 SvgDocument& rDocument,
120                 SvgNode* pParent);
121             virtual ~SvgNode();
122 
123             void parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs);
124             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
125             virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
126             virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const;
127 
128             /// basic data read access
129             SVGToken getType() const { return maType; }
130             const SvgDocument& getDocument() const { return mrDocument; }
131             const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
132             const SvgNodeVector& getChildren() const { return maChildren; }
133 
134             /// InfoProvider support for %, em and ex values
135             virtual const basegfx::B2DRange* getCurrentViewPort() const;
136             virtual double getCurrentFontSize() const;
137             virtual double getCurrentXHeight() const;
138 
139             /// Id access
140             const rtl::OUString* getId() const { return mpId; }
141             void setId(const rtl::OUString* pfId = 0);
142 
143             /// Class access
144             const rtl::OUString* getClass() const { return mpClass; }
145             void setClass(const rtl::OUString* pfClass = 0);
146 
147             /// XmlSpace access
148             XmlSpace getXmlSpace() const;
149             void setXmlSpace(XmlSpace eXmlSpace = XmlSpace_notset) { maXmlSpace = eXmlSpace; }
150 
151             /// Display access #121656#
152             Display getDisplay() const { return maDisplay; }
153             void setDisplay(Display eDisplay = Display_inherit) { maDisplay = eDisplay; }
154 
155             /// alternative parent
156             void setAlternativeParent(const SvgNode* pAlternativeParent = 0) { mpAlternativeParent = pAlternativeParent; }
157         };
158     } // end of namespace svgreader
159 } // end of namespace svgio
160 
161 //////////////////////////////////////////////////////////////////////////////
162 
163 #endif //INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
164 
165 // eof
166