lok: getSlideShowInfo: interactions: check that properties are available
[LibreOffice.git] / svgio / inc / svgnode.hxx
blobc8b81fcb1d70b500d156d30819a992f25deb1f6f
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 #pragma once
22 #include "SvgNumber.hxx"
23 #include "svgtoken.hxx"
24 #include "svgtools.hxx"
25 #include <com/sun/star/xml/sax/XAttributeList.hpp>
26 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
27 #include <memory>
28 #include <string_view>
29 #include <vector>
30 #include <optional>
32 // predefines
33 namespace svgio::svgreader
35 class SvgNode;
36 class SvgDocument;
37 class SvgStyleAttributes;
42 namespace svgio::svgreader
44 enum class XmlSpace
46 NotSet,
47 Default,
48 Preserve
51 // display property (see SVG 1.1. 11.5), not inheritable
52 enum class Display // #i121656#
54 Inline, // the default
55 Block,
56 ListItem,
57 RunIn,
58 Compact,
59 Marker,
60 Table,
61 InlineTable,
62 TableRowGroup,
63 TableHeaderGroup,
64 TableFooterGroup,
65 TableRow,
66 TableColumnGroup,
67 TableColumn,
68 TableCell,
69 TableCaption,
70 None,
71 Inherit
74 // helper to convert a string associated with a token of type SVGTokenDisplay
75 // to the enum Display. Empty strings return the default 'Display_inline' with
76 // which members should be initialized
77 Display getDisplayFromContent(std::u16string_view aContent);
79 class Visitor;
81 class SvgNode : public InfoProvider
83 private:
84 /// basic data, Type, document we belong to and parent (if not root)
85 SVGToken maType;
86 SvgDocument& mrDocument;
87 const SvgNode* mpParent;
88 const SvgNode* mpAlternativeParent;
90 /// sub hierarchy
91 std::vector< std::unique_ptr<SvgNode> > maChildren;
93 /// Id svan value
94 std::optional<OUString> mpId;
96 /// Class svan value
97 std::optional<OUString> mpClass;
99 /// systemLanguage values
100 SvgStringVector maSystemLanguage;
102 /// XmlSpace value
103 XmlSpace maXmlSpace;
105 /// Display value #i121656#
106 Display maDisplay;
108 // CSS style vector chain, used in decompose phase and built up once per node.
109 // It contains the StyleHierarchy for the local node. Independent from the
110 // node hierarchy itself which also needs to be used in style entry solving
111 ::std::vector< const SvgStyleAttributes* > maCssStyleVector;
113 /// possible local CssStyle, e.g. style="fill:red; stroke:red;"
114 std::unique_ptr<SvgStyleAttributes> mpLocalCssStyle;
116 mutable bool mbDecomposing;
118 // flag if maCssStyleVector is already computed (done only once)
119 bool mbCssStyleVectorBuilt : 1;
121 protected:
122 /// helper to evtl. link to css style
123 const SvgStyleAttributes* checkForCssStyle(const SvgStyleAttributes& rOriginal) const;
125 /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
126 void fillCssStyleVector(const SvgStyleAttributes& rOriginal);
127 void addCssStyle(
128 const SvgDocument& rDocument,
129 const OUString& aConcatenated);
130 void fillCssStyleVectorUsingHierarchyAndSelectors(
131 const SvgNode& rCurrent,
132 std::u16string_view aConcatenated);
133 void fillCssStyleVectorUsingParent(
134 const SvgNode& rCurrent);
136 public:
137 SvgNode(
138 SVGToken aType,
139 SvgDocument& rDocument,
140 SvgNode* pParent);
141 virtual ~SvgNode() override;
142 SvgNode(const SvgNode&) = delete;
143 SvgNode& operator=(const SvgNode&) = delete;
145 void accept(Visitor& rVisitor);
147 /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
148 void readLocalCssStyle(std::u16string_view aContent);
150 /// style helpers
151 void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs);
152 virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
153 virtual void parseAttribute(SVGToken aSVGToken, const OUString& aContent);
154 virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const;
156 /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
157 virtual bool supportsParentStyle() const;
159 /// basic data read access
160 SVGToken getType() const { return maType; }
161 const SvgDocument& getDocument() const { return mrDocument; }
162 const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
163 const std::vector< std::unique_ptr<SvgNode> > & getChildren() const { return maChildren; }
165 /// InfoProvider support for %, em and ex values
166 virtual basegfx::B2DRange getCurrentViewPort() const override;
167 virtual double getCurrentFontSize() const override;
168 virtual double getCurrentXHeight() const override;
170 /// Id access
171 std::optional<OUString> const & getId() const { return mpId; }
172 void setId(OUString const &);
174 /// Class access
175 std::optional<OUString> const & getClass() const { return mpClass; }
176 void setClass(OUString const &);
178 /// SystemLanguage access
179 std::vector<OUString> const & getSystemLanguage() const { return maSystemLanguage; }
181 /// XmlSpace access
182 XmlSpace getXmlSpace() const;
183 void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; }
185 /// Display access #i121656#
186 Display getDisplay() const { return maDisplay; }
187 void setDisplay(Display eDisplay) { maDisplay = eDisplay; }
189 /// alternative parent
190 void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
193 class Visitor
195 public:
196 virtual ~Visitor() = default;
197 virtual void visit(SvgNode const & pNode) = 0;
200 } // end of namespace svgio::svgreader
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */