LibreOffice Module svgio (master) 1
svgnode.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include "SvgNumber.hxx"
23#include "svgtoken.hxx"
24#include <com/sun/star/xml/sax/XAttributeList.hpp>
26#include <memory>
27#include <string_view>
28#include <vector>
29#include <optional>
30
31// predefines
32namespace svgio::svgreader
33{
34 class SvgNode;
35 class SvgDocument;
36 class SvgStyleAttributes;
37}
38
39
40
41namespace svgio::svgreader
42 {
43 enum class XmlSpace
44 {
45 NotSet,
46 Default,
48 };
49
50 // display property (see SVG 1.1. 11.5), not inheritable
51 enum class Display // #i121656#
52 {
53 Inline, // the default
54 Block,
56 RunIn,
57 Compact,
58 Marker,
59 Table,
69 None,
71 };
72
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);
77
78 class Visitor;
79
80 class SvgNode : public InfoProvider
81 {
82 private:
88
90 std::vector< std::unique_ptr<SvgNode> > maChildren;
91
93 std::optional<OUString> mpId;
94
96 std::optional<OUString> mpClass;
97
100
103
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;
108
110 std::unique_ptr<SvgStyleAttributes> mpLocalCssStyle;
111
112 mutable bool mbDecomposing;
113
114 // flag if maCssStyleVector is already computed (done only once)
116
117 protected:
119 const SvgStyleAttributes* checkForCssStyle(const SvgStyleAttributes& rOriginal) const;
120
122 void fillCssStyleVector(const SvgStyleAttributes& rOriginal);
123 void addCssStyle(
124 const SvgDocument& rDocument,
125 const OUString& aConcatenated);
127 const SvgNode& rCurrent,
128 const OUString& aConcatenated);
130 const SvgNode& rCurrent);
131
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;
140
141 void accept(Visitor& rVisitor);
142
144 void readLocalCssStyle(std::u16string_view aContent);
145
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;
151
153 virtual bool supportsParentStyle() const;
154
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; }
160
162 virtual basegfx::B2DRange getCurrentViewPort() const override;
163 virtual double getCurrentFontSizeInherited() const override;
164 virtual double getCurrentXHeightInherited() const override;
165
166 double getCurrentFontSize() const;
167 double getCurrentXHeight() const;
168
170 std::optional<OUString> const & getId() const { return mpId; }
171 void setId(OUString const &);
172
174 std::optional<OUString> const & getClass() const { return mpClass; }
175 void setClass(OUString const &);
176
178 XmlSpace getXmlSpace() const;
179 void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; }
180
182 Display getDisplay() const { return maDisplay; }
183 void setDisplay(Display eDisplay) { maDisplay = eDisplay; }
184
186 void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
187
189 bool hasLocalCssStyle() { return static_cast<bool>(mpLocalCssStyle); }
190 };
191
193 {
194 public:
195 virtual ~Visitor() = default;
196 virtual void visit(SvgNode const & pNode) = 0;
197 };
198
199} // end of namespace svgio::svgreader
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList > &xAttribs)
style helpers
Definition: svgnode.cxx:436
void setAlternativeParent(const SvgNode *pAlternativeParent=nullptr)
alternative parent
Definition: svgnode.hxx:186
virtual ~SvgNode() override
Definition: svgnode.cxx:408
virtual bool supportsParentStyle() const
#i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
Definition: svgnode.cxx:32
std::optional< OUString > const & getId() const
Id access.
Definition: svgnode.hxx:170
std::unique_ptr< SvgStyleAttributes > mpLocalCssStyle
possible local CssStyle, e.g. style="fill:red; stroke:red;"
Definition: svgnode.hxx:110
const std::vector< std::unique_ptr< SvgNode > > & getChildren() const
Definition: svgnode.hxx:159
Display getDisplay() const
Display access #i121656#.
Definition: svgnode.hxx:182
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const
Definition: svgnode.cxx:584
SVGToken maType
basic data, Type, document we belong to and parent (if not root)
Definition: svgnode.hxx:84
SVGToken getType() const
basic data read access
Definition: svgnode.hxx:156
Display maDisplay
Display value #i121656#.
Definition: svgnode.hxx:102
SvgNode(SVGToken aType, SvgDocument &rDocument, SvgNode *pParent)
Definition: svgnode.cxx:385
void fillCssStyleVectorUsingHierarchyAndSelectors(const SvgNode &rCurrent, const OUString &aConcatenated)
Definition: svgnode.cxx:95
const SvgStyleAttributes * checkForCssStyle(const SvgStyleAttributes &rOriginal) const
helper to evtl. link to css style
Definition: svgnode.cxx:335
void setXmlSpace(XmlSpace eXmlSpace)
Definition: svgnode.hxx:179
std::vector< std::unique_ptr< SvgNode > > maChildren
sub hierarchy
Definition: svgnode.hxx:90
XmlSpace getXmlSpace() const
XmlSpace access.
Definition: svgnode.cxx:779
const SvgNode * mpParent
Definition: svgnode.hxx:86
void setClass(OUString const &)
Definition: svgnode.cxx:767
SvgNode & operator=(const SvgNode &)=delete
XmlSpace maXmlSpace
XmlSpace value.
Definition: svgnode.hxx:99
virtual double getCurrentXHeightInherited() const override
return xheight of node inherited from parents
Definition: svgnode.cxx:734
double getCurrentXHeight() const
Definition: svgnode.cxx:746
::std::vector< const SvgStyleAttributes * > maCssStyleVector
Definition: svgnode.hxx:107
const SvgNode * getParent() const
Definition: svgnode.hxx:158
std::optional< OUString > mpId
Id svan value.
Definition: svgnode.hxx:93
std::optional< OUString > mpClass
Class svan value.
Definition: svgnode.hxx:96
void fillCssStyleVector(const SvgStyleAttributes &rOriginal)
helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
Definition: svgnode.cxx:281
virtual double getCurrentFontSizeInherited() const override
return font size of node inherited from parents
Definition: svgnode.cxx:714
std::optional< OUString > const & getClass() const
Class access.
Definition: svgnode.hxx:174
SvgNode(const SvgNode &)=delete
const SvgNode * mpAlternativeParent
Definition: svgnode.hxx:87
virtual basegfx::B2DRange getCurrentViewPort() const override
InfoProvider support for %, em and ex values.
Definition: svgnode.cxx:702
void fillCssStyleVectorUsingParent(const SvgNode &rCurrent)
Definition: svgnode.cxx:187
SvgDocument & mrDocument
Definition: svgnode.hxx:85
double getCurrentFontSize() const
Definition: svgnode.cxx:726
void addCssStyle(const SvgDocument &rDocument, const OUString &aConcatenated)
Definition: svgnode.cxx:42
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent)
Definition: svgnode.cxx:534
void accept(Visitor &rVisitor)
Definition: svgnode.cxx:795
void setId(OUString const &)
Definition: svgnode.cxx:755
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
virtual const SvgStyleAttributes * getSvgStyleAttributes() const
Definition: svgnode.cxx:37
bool hasLocalCssStyle()
Check if there is a local css style.
Definition: svgnode.hxx:189
const SvgDocument & getDocument() const
Definition: svgnode.hxx:157
void setDisplay(Display eDisplay)
Definition: svgnode.hxx:183
virtual ~Visitor()=default
virtual void visit(SvgNode const &pNode)=0
None
Display getDisplayFromContent(std::u16string_view aContent)
Definition: svgnode.cxx:452