Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svgio/inc/svgnode.hxx
Line
Count
Source
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 "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>
31
32
// predefines
33
namespace svgio::svgreader
34
{
35
    class SvgDocument;
36
    class SvgStyleAttributes;
37
}
38
39
40
41
namespace svgio::svgreader
42
    {
43
        enum class XmlSpace
44
        {
45
            NotSet,
46
            Default,
47
            Preserve
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,
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
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:
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;
88
89
            /// sub hierarchy
90
            std::vector< std::unique_ptr<SvgNode> >  maChildren;
91
92
            /// Id svan value
93
            std::optional<OUString>   mpId;
94
95
            /// Class svan value
96
            std::optional<OUString>   mpClass;
97
98
            /// systemLanguage values
99
            SvgStringVector  maSystemLanguage;
100
101
            /// XmlSpace value
102
            XmlSpace                    maXmlSpace;
103
104
            /// Display value #i121656#
105
            Display                     maDisplay;
106
107
            // CSS style vector chain, used in decompose phase and built up once per node.
108
            // It contains the StyleHierarchy for the local node. Independent from the
109
            // node hierarchy itself which also needs to be used in style entry solving
110
            ::std::vector< const SvgStyleAttributes* > maCssStyleVector;
111
112
            /// possible local CssStyle, e.g. style="fill:red; stroke:red;"
113
            std::unique_ptr<SvgStyleAttributes>        mpLocalCssStyle;
114
115
            mutable bool                mbDecomposing;
116
117
            // flag if maCssStyleVector is already computed (done only once)
118
            bool                        mbCssStyleVectorBuilt : 1;
119
120
        protected:
121
            /// helper to evtl. link to css style
122
            const SvgStyleAttributes* checkForCssStyle(const SvgStyleAttributes& rOriginal) const;
123
124
            /// helper for filling the CssStyle vector once dependent on mbCssStyleVectorBuilt
125
            void fillCssStyleVector(const SvgStyleAttributes& rOriginal);
126
            void addCssStyle(
127
                const SvgDocument& rDocument,
128
                const OUString& aConcatenated);
129
            void fillCssStyleVectorUsingHierarchyAndSelectors(
130
                const SvgNode& rCurrent,
131
                std::u16string_view aConcatenated);
132
            void fillCssStyleVectorUsingParent(
133
                const SvgNode& rCurrent);
134
135
        public:
136
            SvgNode(
137
                SVGToken aType,
138
                SvgDocument& rDocument,
139
                SvgNode* pParent);
140
            virtual ~SvgNode() override;
141
            SvgNode(const SvgNode&) = delete;
142
            SvgNode& operator=(const SvgNode&) = delete;
143
144
            void accept(Visitor& rVisitor);
145
146
            /// scan helper to read and interpret a local CssStyle to mpLocalCssStyle
147
            void readLocalCssStyle(std::u16string_view aContent);
148
149
            /// style helpers
150
            void parseAttributes(const css::uno::Reference< css::xml::sax::XAttributeList >& xAttribs);
151
            virtual const SvgStyleAttributes* getSvgStyleAttributes() const;
152
            virtual void parseAttribute(SVGToken aSVGToken, const OUString& aContent);
153
            virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const;
154
155
            /// #i125258# tell if this node is allowed to have a parent style (e.g. defs do not)
156
            virtual bool supportsParentStyle() const;
157
158
            /// basic data read access
159
17.3k
            SVGToken getType() const { return maType; }
160
1.56k
            const SvgDocument& getDocument() const { return mrDocument; }
161
30.0k
            const SvgNode* getParent() const { if(mpAlternativeParent) return mpAlternativeParent; return mpParent; }
162
7
            const std::vector< std::unique_ptr<SvgNode> > & getChildren() const { return maChildren; }
163
164
            /// InfoProvider support for %, em and ex values
165
            virtual basegfx::B2DRange getCurrentViewPort() const override;
166
            virtual double getCurrentFontSize() const override;
167
            virtual double getCurrentXHeight() const override;
168
169
            /// Id access
170
0
            std::optional<OUString> const & getId() const { return mpId; }
171
            void setId(OUString const &);
172
173
            /// Class access
174
0
            std::optional<OUString> const & getClass() const { return mpClass; }
175
            void setClass(OUString const &);
176
177
            /// SystemLanguage access
178
0
            std::vector<OUString> const & getSystemLanguage() const { return maSystemLanguage; }
179
180
            /// XmlSpace access
181
            XmlSpace getXmlSpace() const;
182
0
            void setXmlSpace(XmlSpace eXmlSpace) { maXmlSpace = eXmlSpace; }
183
184
            /// Display access #i121656#
185
45
            Display getDisplay() const { return maDisplay; }
186
0
            void setDisplay(Display eDisplay) { maDisplay = eDisplay; }
187
188
            /// alternative parent
189
0
            void setAlternativeParent(const SvgNode* pAlternativeParent = nullptr) { mpAlternativeParent = pAlternativeParent; }
190
        };
191
192
      class Visitor
193
      {
194
      public:
195
0
            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: */