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 <com/sun/star/xml/sax/XAttributeList.hpp>
26 #include <drawinglayer/primitive2d/baseprimitive2d.hxx>
32 namespace svgio::svgreader
36 class SvgStyleAttributes
;
41 namespace svgio::svgreader
50 // display property (see SVG 1.1. 11.5), not inheritable
51 enum Display
// #i121656#
53 Display_inline
, // the default
61 Display_table_row_group
,
62 Display_table_header_group
,
63 Display_table_footer_group
,
65 Display_table_column_group
,
68 Display_table_caption
,
73 // helper to convert a string associated with a token of type SVGTokenDisplay
74 // to the enum Display. Empty strings return the default 'Display_inline' with
75 // which members should be initialized
76 Display
getDisplayFromContent(const OUString
& aContent
);
80 class SvgNode
: public InfoProvider
83 /// basic data, Type, document we belong to and parent (if not root)
85 SvgDocument
& mrDocument
;
86 const SvgNode
* mpParent
;
87 const SvgNode
* mpAlternativeParent
;
90 std::vector
< std::unique_ptr
<SvgNode
> > maChildren
;
93 std::optional
<OUString
> mpId
;
96 std::optional
<OUString
> mpClass
;
101 /// Display value #i121656#
104 // CSS style vector chain, used in decompose phase and built up once per node.
105 // It contains the StyleHierarchy for the local node. Independent from the
106 // node hierarchy itself which also needs to be used in style entry solving
107 ::std::vector
< const SvgStyleAttributes
* > maCssStyleVector
;
109 /// possible local CssStyle, e.g. style="fill:red; stroke:red;"
110 std::unique_ptr
<SvgStyleAttributes
> mpLocalCssStyle
;
112 mutable bool mbDecomposing
;
114 // flag if maCssStyleVector is already computed (done only once)
115 bool mbCssStyleVectorBuilt
: 1;
118 /// helper to evtl. link to css style
119 const SvgStyleAttributes
* checkForCssStyle(const OUString
& rClassStr
, const SvgStyleAttributes
& rOriginal
) const;
121 /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
122 void fillCssStyleVector(const OUString
& rClassStr
, const SvgStyleAttributes
& rOriginal
);
123 void fillCssStyleVectorUsingHierarchyAndSelectors(
124 const OUString
& rClassStr
,
125 const SvgNode
& rCurrent
,
126 const OUString
& aConcatenated
);
131 SvgDocument
& rDocument
,
133 virtual ~SvgNode() override
;
134 SvgNode(const SvgNode
&) = delete;
135 SvgNode
& operator=(const SvgNode
&) = delete;
137 void accept(Visitor
& rVisitor
);
139 /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
140 void readLocalCssStyle(const OUString
& aContent
);
143 void parseAttributes(const css::uno::Reference
< css::xml::sax::XAttributeList
>& xAttribs
);
144 virtual const SvgStyleAttributes
* getSvgStyleAttributes() const;
145 virtual void parseAttribute(const OUString
& rTokenName
, SVGToken aSVGToken
, const OUString
& aContent
);
146 virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer
& rTarget
, bool bReferenced
) const;
148 /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
149 virtual bool supportsParentStyle() const;
151 /// basic data read access
152 SVGToken
getType() const { return maType
; }
153 const SvgDocument
& getDocument() const { return mrDocument
; }
154 const SvgNode
* getParent() const { if(mpAlternativeParent
) return mpAlternativeParent
; return mpParent
; }
155 const std::vector
< std::unique_ptr
<SvgNode
> > & getChildren() const { return maChildren
; }
157 /// InfoProvider support for %, em and ex values
158 virtual basegfx::B2DRange
getCurrentViewPort() const override
;
159 virtual double getCurrentFontSizeInherited() const override
;
160 virtual double getCurrentXHeightInherited() const override
;
162 virtual double getCurrentFontSize() const;
163 double getCurrentXHeight() const;
166 std::optional
<OUString
> const & getId() const { return mpId
; }
167 void setId(OUString
const &);
170 std::optional
<OUString
> const & getClass() const { return mpClass
; }
171 void setClass(OUString
const &);
174 XmlSpace
getXmlSpace() const;
175 void setXmlSpace(XmlSpace eXmlSpace
) { maXmlSpace
= eXmlSpace
; }
177 /// Display access #i121656#
178 Display
getDisplay() const { return maDisplay
; }
179 void setDisplay(Display eDisplay
) { maDisplay
= eDisplay
; }
181 /// alternative parent
182 void setAlternativeParent(const SvgNode
* pAlternativeParent
= nullptr) { mpAlternativeParent
= pAlternativeParent
; }
188 virtual ~Visitor() = default;
189 virtual void visit(SvgNode
const & pNode
) = 0;
192 } // end of namespace svgio::svgreader
194 #endif // INCLUDED_SVGIO_INC_SVGNODE_HXX
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */