bump product version to 7.2.5.1
[LibreOffice.git] / svgio / inc / svgnode.hxx
blob93c303fa2df72ea4e660f578b8b8b14472eb61ae
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 "svgtools.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 <vector>
28 #include <optional>
30 // predefines
31 namespace svgio::svgreader
33 class SvgNode;
34 class SvgDocument;
35 class SvgStyleAttributes;
40 namespace svgio::svgreader
42 enum class XmlSpace
44 NotSet,
45 Default,
46 Preserve
49 // display property (see SVG 1.1. 11.5), not inheritable
50 enum class Display // #i121656#
52 Inline, // the default
53 Block,
54 ListItem,
55 RunIn,
56 Compact,
57 Marker,
58 Table,
59 InlineTable,
60 TableRowGroup,
61 TableHeaderGroup,
62 TableFooterGroup,
63 TableRow,
64 TableColumnGroup,
65 TableColumn,
66 TableCell,
67 TableCaption,
68 None,
69 Inherit
72 // helper to convert a string associated with a token of type SVGTokenDisplay
73 // to the enum Display. Empty strings return the default 'Display_inline' with
74 // which members should be initialized
75 Display getDisplayFromContent(const OUString& aContent);
77 class Visitor;
79 class SvgNode : public InfoProvider
81 private:
82 /// basic data, Type, document we belong to and parent (if not root)
83 SVGToken maType;
84 SvgDocument& mrDocument;
85 const SvgNode* mpParent;
86 const SvgNode* mpAlternativeParent;
88 /// sub hierarchy
89 std::vector< std::unique_ptr<SvgNode> > maChildren;
91 /// Id svan value
92 std::optional<OUString> mpId;
94 /// Class svan value
95 std::optional<OUString> mpClass;
97 /// XmlSpace value
98 XmlSpace maXmlSpace;
100 /// Display value #i121656#
101 Display maDisplay;
103 // CSS style vector chain, used in decompose phase and built up once per node.
104 // It contains the StyleHierarchy for the local node. Independent from the
105 // node hierarchy itself which also needs to be used in style entry solving
106 ::std::vector< const SvgStyleAttributes* > maCssStyleVector;
108 /// possible local CssStyle, e.g. style="fill:red; stroke:red;"
109 std::unique_ptr<SvgStyleAttributes> mpLocalCssStyle;
111 mutable bool mbDecomposing;
113 // flag if maCssStyleVector is already computed (done only once)
114 bool mbCssStyleVectorBuilt : 1;
116 protected:
117 /// helper to evtl. link to css style
118 const SvgStyleAttributes* checkForCssStyle(const OUString& rClassStr, const SvgStyleAttributes& rOriginal) const;
120 /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
121 void fillCssStyleVector(const OUString& rClassStr, const SvgStyleAttributes& rOriginal);
122 void fillCssStyleVectorUsingHierarchyAndSelectors(
123 const OUString& rClassStr,
124 const SvgNode& rCurrent,
125 const OUString& aConcatenated);
127 public:
128 SvgNode(
129 SVGToken aType,
130 SvgDocument& rDocument,
131 SvgNode* pParent);
132 virtual ~SvgNode() override;
133 SvgNode(const SvgNode&) = delete;
134 SvgNode& operator=(const SvgNode&) = delete;
136 void accept(Visitor& rVisitor);
138 /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
139 void readLocalCssStyle(const OUString& aContent);
141 /// style helpers
142 void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs);
143 virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
144 virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent);
145 virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const;
147 /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
148 virtual bool supportsParentStyle() const;
150 /// basic data read access
151 SVGToken getType() const { return maType; }
152 const SvgDocument& getDocument() const { return mrDocument; }
153 const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
154 const std::vector< std::unique_ptr<SvgNode> > & getChildren() const { return maChildren; }
156 /// InfoProvider support for %, em and ex values
157 virtual basegfx::B2DRange getCurrentViewPort() const override;
158 virtual double getCurrentFontSizeInherited() const override;
159 virtual double getCurrentXHeightInherited() const override;
161 virtual double getCurrentFontSize() const;
162 double getCurrentXHeight() const;
164 /// Id access
165 std::optional<OUString> const & getId() const { return mpId; }
166 void setId(OUString const &);
168 /// Class access
169 std::optional<OUString> const & getClass() const { return mpClass; }
170 void setClass(OUString const &);
172 /// XmlSpace access
173 XmlSpace getXmlSpace() const;
174 void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; }
176 /// Display access #i121656#
177 Display getDisplay() const { return maDisplay; }
178 void setDisplay(Display eDisplay) { maDisplay = eDisplay; }
180 /// alternative parent
181 void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
184 class Visitor
186 public:
187 virtual ~Visitor() = default;
188 virtual void visit(SvgNode const & pNode) = 0;
191 } // end of namespace svgio::svgreader
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */