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         // helper to convert a string associated with a token of type SVGTokenDisplay
86         // to the enum Display. Empty trings return the default 'Display_inline' with
87         // which members should be initialized
88         Display getDisplayFromContent(const rtl::OUString& aContent);
89 
90         class SvgNode : private boost::noncopyable, public InfoProvider
91         {
92         private:
93             /// basic data, Type, document we belong to and parent (if not root)
94             SVGToken                    maType;
95             SvgDocument&                mrDocument;
96             const SvgNode*              mpParent;
97             const SvgNode*              mpAlternativeParent;
98 
99             /// sub hierarchy
100             SvgNodeVector               maChildren;
101 
102             /// Id svan value
103             rtl::OUString*              mpId;
104 
105             /// Class svan value
106             rtl::OUString*              mpClass;
107 
108             /// XmlSpace value
109             XmlSpace                    maXmlSpace;
110 
111             /// Display value #121656#
112             Display                     maDisplay;
113 
114             /// CSS styles
115             SvgStyleAttributeVector     maCssStyleVector;
116 
117         protected:
118             /// helper to evtl. link to css style
119             const SvgStyleAttributes* checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
120 
121         public:
122             SvgNode(
123                 SVGToken aType,
124                 SvgDocument& rDocument,
125                 SvgNode* pParent);
126             virtual ~SvgNode();
127 
128             void parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs);
129             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
130             virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
131             virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const;
132 
133             /// #125258# tell if this node is allowed to have a parent style (e.g. defs do not)
134             virtual bool supportsParentStyle() const;
135 
136             /// basic data read access
getType() const137             SVGToken getType() const { return maType; }
getDocument() const138             const SvgDocument& getDocument() const { return mrDocument; }
getParent() const139             const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
getChildren() const140             const SvgNodeVector& getChildren() const { return maChildren; }
141 
142             /// InfoProvider support for %, em and ex values
143             virtual const basegfx::B2DRange getCurrentViewPort() const;
144             virtual double getCurrentFontSize() const;
145             virtual double getCurrentXHeight() const;
146 
147             /// Id access
getId() const148             const rtl::OUString* getId() const { return mpId; }
149             void setId(const rtl::OUString* pfId = 0);
150 
151             /// Class access
getClass() const152             const rtl::OUString* getClass() const { return mpClass; }
153             void setClass(const rtl::OUString* pfClass = 0);
154 
155             /// XmlSpace access
156             XmlSpace getXmlSpace() const;
setXmlSpace(XmlSpace eXmlSpace=XmlSpace_notset)157             void setXmlSpace(XmlSpace eXmlSpace = XmlSpace_notset) { maXmlSpace = eXmlSpace; }
158 
159             /// Display access #121656#
getDisplay() const160             Display getDisplay() const { return maDisplay; }
setDisplay(Display eDisplay=Display_inherit)161             void setDisplay(Display eDisplay = Display_inherit) { maDisplay = eDisplay; }
162 
163             /// alternative parent
setAlternativeParent(const SvgNode * pAlternativeParent=0)164             void setAlternativeParent(const SvgNode* pAlternativeParent = 0) { mpAlternativeParent = pAlternativeParent; }
165         };
166     } // end of namespace svgreader
167 } // end of namespace svgio
168 
169 //////////////////////////////////////////////////////////////////////////////
170 
171 #endif //INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
172 
173 // eof
174