bump product version to 7.6.3.2-android
[LibreOffice.git] / svgio / inc / svgnode.hxx
blob96c6ade01efaabc5c5e73cc8e995759f1763b89c
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 <com/sun/star/xml/sax/XAttributeList.hpp>
25 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
26 #include <memory>
27 #include <string_view>
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 class XmlSpace
45 NotSet,
46 Default,
47 Preserve
50 // display property (see SVG 1.1. 11.5), not inheritable
51 enum class Display // #i121656#
53 Inline, // the default
54 Block,
55 ListItem,
56 RunIn,
57 Compact,
58 Marker,
59 Table,
60 InlineTable,
61 TableRowGroup,
62 TableHeaderGroup,
63 TableFooterGroup,
64 TableRow,
65 TableColumnGroup,
66 TableColumn,
67 TableCell,
68 TableCaption,
69 None,
70 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(std::u16string_view 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 SvgStyleAttributes& rOriginal) const;
121 /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
122 void fillCssStyleVector(const SvgStyleAttributes& rOriginal);
123 void addCssStyle(
124 const SvgDocument& rDocument,
125 const OUString& aConcatenated);
126 void fillCssStyleVectorUsingHierarchyAndSelectors(
127 const SvgNode& rCurrent,
128 std::u16string_view aConcatenated);
129 void fillCssStyleVectorUsingParent(
130 const SvgNode& rCurrent);
132 public:
133 SvgNode(
134 SVGToken aType,
135 SvgDocument& rDocument,
136 SvgNode* pParent);
137 virtual ~SvgNode() override;
138 SvgNode(const SvgNode&) = delete;
139 SvgNode& operator=(const SvgNode&) = delete;
141 void accept(Visitor& rVisitor);
143 /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
144 void readLocalCssStyle(std::u16string_view aContent);
146 /// style helpers
147 void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs);
148 virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
149 virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent);
150 virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const;
152 /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
153 virtual bool supportsParentStyle() const;
155 /// basic data read access
156 SVGToken getType() const { return maType; }
157 const SvgDocument& getDocument() const { return mrDocument; }
158 const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
159 const std::vector< std::unique_ptr<SvgNode> > & getChildren() const { return maChildren; }
161 /// InfoProvider support for %, em and ex values
162 virtual basegfx::B2DRange getCurrentViewPort() const override;
163 virtual double getCurrentFontSizeInherited() const override;
164 virtual double getCurrentXHeightInherited() const override;
166 double getCurrentFontSize() const;
167 double getCurrentXHeight() const;
169 /// Id access
170 std::optional<OUString> const & getId() const { return mpId; }
171 void setId(OUString const &);
173 /// Class access
174 std::optional<OUString> const & getClass() const { return mpClass; }
175 void setClass(OUString const &);
177 /// XmlSpace access
178 XmlSpace getXmlSpace() const;
179 void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; }
181 /// Display access #i121656#
182 Display getDisplay() const { return maDisplay; }
183 void setDisplay(Display eDisplay) { maDisplay = eDisplay; }
185 /// alternative parent
186 void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
188 /// Check if there is a local css style
189 bool hasLocalCssStyle() { return static_cast<bool>(mpLocalCssStyle); }
192 class Visitor
194 public:
195 virtual ~Visitor() = default;
196 virtual void visit(SvgNode const & pNode) = 0;
199 } // end of namespace svgio::svgreader
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */