Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
21 : #define INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
22 :
23 : #include <svgio/svgreader/svgtools.hxx>
24 : #include <svgio/svgreader/svgtoken.hxx>
25 : #include <svgio/svgreader/svgpaint.hxx>
26 : #include <basegfx/matrix/b2dhommatrix.hxx>
27 : #include <com/sun/star/xml/sax/XAttributeList.hpp>
28 : #include <vector>
29 : #include <boost/unordered_map.hpp>
30 :
31 :
32 : // predefines
33 : namespace svgio
34 : {
35 : namespace svgreader
36 : {
37 : class SvgNode;
38 : class SvgDocument;
39 : class SvgStyleAttributes;
40 : }
41 : }
42 :
43 :
44 :
45 : namespace svgio
46 : {
47 : namespace svgreader
48 : {
49 : typedef ::std::vector< SvgNode* > SvgNodeVector;
50 : typedef ::std::vector< const SvgStyleAttributes* > SvgStyleAttributeVector;
51 :
52 : enum XmlSpace
53 : {
54 : XmlSpace_notset,
55 : XmlSpace_default,
56 : XmlSpace_preserve
57 : };
58 :
59 : // display property (see SVG 1.1. 11.5), not inheritable
60 : enum Display // #i121656#
61 : {
62 : Display_inline, // the default
63 : Display_block,
64 : Display_list_item,
65 : Display_run_in,
66 : Display_compact,
67 : Display_marker,
68 : Display_table,
69 : Display_inline_table,
70 : Display_table_row_group,
71 : Display_table_header_group,
72 : Display_table_footer_group,
73 : Display_table_row,
74 : Display_table_column_group,
75 : Display_table_column,
76 : Display_table_cell,
77 : Display_table_caption,
78 : Display_none,
79 : Display_inherit
80 : };
81 :
82 : // helper to convert a string associated with a token of type SVGTokenDisplay
83 : // to the enum Display. Empty trings return the default 'Display_inline' with
84 : // which members should be initialized
85 : Display getDisplayFromContent(const rtl::OUString& aContent);
86 :
87 : class SvgNode : private boost::noncopyable, public InfoProvider
88 : {
89 : private:
90 : /// basic data, Type, document we belong to and parent (if not root)
91 : SVGToken maType;
92 : SvgDocument& mrDocument;
93 : const SvgNode* mpParent;
94 : const SvgNode* mpAlternativeParent;
95 :
96 : /// sub hierarchy
97 : SvgNodeVector maChildren;
98 :
99 : /// Id svan value
100 : OUString* mpId;
101 :
102 : /// Class svan value
103 : OUString* mpClass;
104 :
105 : /// XmlSpace value
106 : XmlSpace maXmlSpace;
107 :
108 : /// Display value #i121656#
109 : Display maDisplay;
110 :
111 : /// CSS styles
112 : SvgStyleAttributeVector maCssStyleVector;
113 :
114 : protected:
115 : /// helper to evtl. link to css style
116 : const SvgStyleAttributes* checkForCssStyle(const rtl::OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
117 :
118 : public:
119 : SvgNode(
120 : SVGToken aType,
121 : SvgDocument& rDocument,
122 : SvgNode* pParent);
123 : virtual ~SvgNode();
124 :
125 : void parseAttributes(const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttribs);
126 : virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
127 : virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent);
128 : virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool bReferenced) const;
129 :
130 : /// basic data read access
131 0 : SVGToken getType() const { return maType; }
132 0 : const SvgDocument& getDocument() const { return mrDocument; }
133 0 : const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
134 0 : const SvgNodeVector& getChildren() const { return maChildren; }
135 :
136 : /// InfoProvider support for %, em and ex values
137 : virtual const basegfx::B2DRange getCurrentViewPort() const SAL_OVERRIDE;
138 : virtual double getCurrentFontSizeInherited() const SAL_OVERRIDE;
139 : virtual double getCurrentXHeightInherited() const SAL_OVERRIDE;
140 :
141 : double getCurrentFontSize() const;
142 : double getCurrentXHeight() const;
143 :
144 : /// Id access
145 0 : const OUString* getId() const { return mpId; }
146 : void setId(const OUString* pfId = 0);
147 :
148 : /// Class access
149 0 : const OUString* getClass() const { return mpClass; }
150 : void setClass(const OUString* pfClass = 0);
151 :
152 : /// XmlSpace access
153 : XmlSpace getXmlSpace() const;
154 0 : void setXmlSpace(XmlSpace eXmlSpace = XmlSpace_notset) { maXmlSpace = eXmlSpace; }
155 :
156 : /// Display access #i121656#
157 0 : Display getDisplay() const { return maDisplay; }
158 0 : void setDisplay(Display eDisplay = Display_inherit) { maDisplay = eDisplay; }
159 :
160 : /// alternative parent
161 0 : void setAlternativeParent(const SvgNode* pAlternativeParent = 0) { mpAlternativeParent = pAlternativeParent; }
162 : };
163 : } // end of namespace svgreader
164 : } // end of namespace svgio
165 :
166 :
167 :
168 : #endif //INCLUDED_SVGIO_SVGREADER_SVGNODE_HXX
169 :
170 : // eof
171 :
172 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|