1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVGIO_INC_SVGNODE_HXX
21 #define INCLUDED_SVGIO_INC_SVGNODE_HXX
23 #include "svgtools.hxx"
24 #include "svgtoken.hxx"
25 #include "svgpaint.hxx"
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <com/sun/star/xml/sax/XAttributeList.hpp>
30 #include <boost/optional.hpp>
39 class SvgStyleAttributes
;
55 // display property (see SVG 1.1. 11.5), not inheritable
56 enum Display
// #i121656#
58 Display_inline
, // the default
66 Display_table_row_group
,
67 Display_table_header_group
,
68 Display_table_footer_group
,
70 Display_table_column_group
,
73 Display_table_caption
,
78 // helper to convert a string associated with a token of type SVGTokenDisplay
79 // to the enum Display. Empty strings return the default 'Display_inline' with
80 // which members should be initialized
81 Display
getDisplayFromContent(const OUString
& aContent
);
85 class SvgNode
: public InfoProvider
88 /// basic data, Type, document we belong to and parent (if not root)
89 SVGToken
const maType
;
90 SvgDocument
& mrDocument
;
91 const SvgNode
* mpParent
;
92 const SvgNode
* mpAlternativeParent
;
95 std::vector
< std::unique_ptr
<SvgNode
> > maChildren
;
98 boost::optional
<OUString
> mpId
;
101 boost::optional
<OUString
> mpClass
;
106 /// Display value #i121656#
109 // CSS style vector chain, used in decompose phase and built up once per node.
110 // It contains the StyleHierarchy for the local node. Independent from the
111 // node hierarchy itself which also needs to be used in style entry solving
112 ::std::vector
< const SvgStyleAttributes
* > maCssStyleVector
;
114 /// possible local CssStyle, e.g. style="fill:red; stroke:red;"
115 std::unique_ptr
<SvgStyleAttributes
> mpLocalCssStyle
;
117 mutable bool mbDecomposing
;
119 // flag if maCssStyleVector is already computed (done only once)
120 bool mbCssStyleVectorBuilt
: 1;
123 /// helper to evtl. link to css style
124 const SvgStyleAttributes
* checkForCssStyle(const OUString
& rClassStr
, const SvgStyleAttributes
& rOriginal
) const;
126 /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
127 void fillCssStyleVector(const OUString
& rClassStr
, const SvgStyleAttributes
& rOriginal
);
128 void fillCssStyleVectorUsingHierarchyAndSelectors(
129 const OUString
& rClassStr
,
130 const SvgNode
& rCurrent
,
131 const OUString
& aConcatenated
);
136 SvgDocument
& rDocument
,
138 virtual ~SvgNode() override
;
139 SvgNode(const SvgNode
&) = delete;
140 SvgNode
& operator=(const SvgNode
&) = delete;
142 void accept(Visitor
& rVisitor
);
144 /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
145 void readLocalCssStyle(const OUString
& aContent
);
148 void parseAttributes(const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
);
149 virtual const SvgStyleAttributes
* getSvgStyleAttributes() const;
150 virtual void parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
);
151 virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool bReferenced
) const;
153 /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
154 virtual bool supportsParentStyle() const;
156 /// basic data read access
157 SVGToken
getType() const { return maType
; }
158 const SvgDocument
& getDocument() const { return mrDocument
; }
159 const SvgNode
* getParent() const { if(mpAlternativeParent
) return mpAlternativeParent
; return mpParent
; }
160 const std::vector
< std::unique_ptr
<SvgNode
> > & getChildren() const { return maChildren
; }
162 /// InfoProvider support for %, em and ex values
163 virtual basegfx::B2DRange
getCurrentViewPort() const override
;
164 virtual double getCurrentFontSizeInherited() const override
;
165 virtual double getCurrentXHeightInherited() const override
;
167 virtual double getCurrentFontSize() const;
168 double getCurrentXHeight() const;
171 boost::optional
<OUString
> const & getId() const { return mpId
; }
172 void setId(OUString
const &);
175 boost::optional
<OUString
> const & getClass() const { return mpClass
; }
176 void setClass(OUString
const &);
179 XmlSpace
getXmlSpace() const;
180 void setXmlSpace(XmlSpace eXmlSpace
) { maXmlSpace
= eXmlSpace
; }
182 /// Display access #i121656#
183 Display
getDisplay() const { return maDisplay
; }
184 void setDisplay(Display eDisplay
) { maDisplay
= eDisplay
; }
186 /// alternative parent
187 void setAlternativeParent(const SvgNode
* pAlternativeParent
= nullptr) { mpAlternativeParent
= pAlternativeParent
; }
193 virtual ~Visitor() = default;
194 virtual void visit(SvgNode
const & pNode
) = 0;
197 } // end of namespace svgreader
198 } // end of namespace svgio
200 #endif // INCLUDED_SVGIO_INC_SVGNODE_HXX
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */