nss: upgrade to release 3.73
[LibreOffice.git] / svgio / inc / svgnode.hxx
blob9120c909839cfda490c2aec6e7b5be05c9caa8f9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <memory>
28 #include <vector>
29 #include <optional>
31 // predefines
32 namespace svgio::svgreader
34 class SvgNode;
35 class SvgDocument;
36 class SvgStyleAttributes;
41 namespace svgio::svgreader
43 enum XmlSpace
45 XmlSpace_notset,
46 XmlSpace_default,
47 XmlSpace_preserve
50 // display property (see SVG 1.1. 11.5), not inheritable
51 enum Display // #i121656#
53 Display_inline, // the default
54 Display_block,
55 Display_list_item,
56 Display_run_in,
57 Display_compact,
58 Display_marker,
59 Display_table,
60 Display_inline_table,
61 Display_table_row_group,
62 Display_table_header_group,
63 Display_table_footer_group,
64 Display_table_row,
65 Display_table_column_group,
66 Display_table_column,
67 Display_table_cell,
68 Display_table_caption,
69 Display_none,
70 Display_inherit
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);
78 class Visitor;
80 class SvgNode : public InfoProvider
82 private:
83 /// basic data, Type, document we belong to and parent (if not root)
84 SVGToken maType;
85 SvgDocument& mrDocument;
86 const SvgNode* mpParent;
87 const SvgNode* mpAlternativeParent;
89 /// sub hierarchy
90 std::vector< std::unique_ptr<SvgNode> > maChildren;
92 /// Id svan value
93 std::optional<OUString> mpId;
95 /// Class svan value
96 std::optional<OUString> mpClass;
98 /// XmlSpace value
99 XmlSpace maXmlSpace;
101 /// Display value #i121656#
102 Display maDisplay;
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;
117 protected:
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);
128 public:
129 SvgNode(
130 SVGToken aType,
131 SvgDocument& rDocument,
132 SvgNode* pParent);
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);
142 /// style helpers
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;
165 /// Id access
166 std::optional<OUString> const & getId() const { return mpId; }
167 void setId(OUString const &);
169 /// Class access
170 std::optional<OUString> const & getClass() const { return mpClass; }
171 void setClass(OUString const &);
173 /// XmlSpace access
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; }
185 class Visitor
187 public:
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: */