1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
28 #include <string_view>
33 namespace svgio::svgreader
37 class SvgStyleAttributes
;
42 namespace svgio::svgreader
51 // display property (see SVG 1.1. 11.5), not inheritable
52 enum class Display
// #i121656#
54 Inline
, // the default
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
);
81 class SvgNode
: public InfoProvider
84 /// basic data, Type, document we belong to and parent (if not root)
86 SvgDocument
& mrDocument
;
87 const SvgNode
* mpParent
;
88 const SvgNode
* mpAlternativeParent
;
91 std::vector
< std::unique_ptr
<SvgNode
> > maChildren
;
94 std::optional
<OUString
> mpId
;
97 std::optional
<OUString
> mpClass
;
99 /// systemLanguage values
100 SvgStringVector maSystemLanguage
;
105 /// Display value #i121656#
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;
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
);
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
);
139 SvgDocument
& rDocument
,
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
);
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
;
171 std::optional
<OUString
> const & getId() const { return mpId
; }
172 void setId(OUString
const &);
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
; }
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
; }
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: */