xref: /trunk/main/svgio/inc/svgio/svgreader/svgnode.hxx (revision b87166d3)
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 strings 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 style vector chain, used in decompose phase and built up once per node.
115             // It contains the StyleHierarchy for the local node. INdependent from the
116             // node hierarchy itself which also needs to be used in style entry solving
117             SvgStyleAttributeVector     maCssStyleVector;
118 
119             /// possibbe local CssStyle, e.g. style="fill:red; stroke:red;"
120             SvgStyleAttributes*         mpLocalCssStyle;
121 
122             /// bitfield
123             // flag if maCssStyleVector is already computed (done only once)
124             bool                        mbCssStyleVectorBuilt : 1;
125 
126         protected:
127             /// helper to evtl. link to css style
128             const SvgStyleAttributes* checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
129 
130             /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
131             void fillCssStyleVector(const rtl::OUString& rClassStr);
132             void fillCssStyleVectorUsingHierarchyAndSelectors(
133                 const rtl::OUString& rClassStr,
134                 const SvgNode& rCurrent,
135                 rtl::OUString aConcatenated);
136 
137         public:
138             SvgNode(
139                 SVGToken aType,
140                 SvgDocument& rDocument,
141                 SvgNode* pParent);
142             virtual ~SvgNode();
143 
144             /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
145             void readLocalCssStyle(const rtl::OUString& aContent);
146 
147             /// style helpers
148             void parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs);
149             virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
150             virtual void parseAttribute(const rtl::OUString& rTokenName, SVGToken aSVGToken, const rtl::OUString& aContent);
151             virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const;
152 
153             /// #125258# tell if this node is allowed to have a parent style (e.g. defs do not)
154             virtual bool supportsParentStyle() const;
155 
156             /// basic data read access
getType() const157             SVGToken getType() const { return maType; }
getDocument() const158             const SvgDocument& getDocument() const { return mrDocument; }
getParent() const159             const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
getChildren() const160             const SvgNodeVector& getChildren() const { return maChildren; }
161 
162             /// InfoProvider support for %, em and ex values
163             virtual const basegfx::B2DRange getCurrentViewPort() const;
164             virtual double getCurrentFontSize() const;
165             virtual double getCurrentXHeight() const;
166 
167             /// Id access
getId() const168             const rtl::OUString* getId() const { return mpId; }
169             void setId(const rtl::OUString* pfId = 0);
170 
171             /// Class access
getClass() const172             const rtl::OUString* getClass() const { return mpClass; }
173             void setClass(const rtl::OUString* pfClass = 0);
174 
175             /// XmlSpace access
176             XmlSpace getXmlSpace() const;
setXmlSpace(XmlSpace eXmlSpace=XmlSpace_notset)177             void setXmlSpace(XmlSpace eXmlSpace = XmlSpace_notset) { maXmlSpace = eXmlSpace; }
178 
179             /// Display access #121656#
getDisplay() const180             Display getDisplay() const { return maDisplay; }
setDisplay(Display eDisplay=Display_inherit)181             void setDisplay(Display eDisplay = Display_inherit) { maDisplay = eDisplay; }
182 
183             /// alternative parent
setAlternativeParent(const SvgNode * pAlternativeParent=0)184             void setAlternativeParent(const SvgNode* pAlternativeParent = 0) { mpAlternativeParent = pAlternativeParent; }
185         };
186     } // end of namespace svgreader
187 } // end of namespace svgio
188 
189 //////////////////////////////////////////////////////////////////////////////
190 
191 #endif //INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
192 
193 // eof
194