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 <com/sun/star/xml/sax/XAttributeList.hpp>
25 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
27 #include <string_view>
32 namespace svgio::svgreader
36 class SvgStyleAttributes
;
41 namespace svgio::svgreader
50 // display property (see SVG 1.1. 11.5), not inheritable
51 enum class Display
// #i121656#
53 Inline
, // the default
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
);
80 class SvgNode
: public InfoProvider
83 /// basic data, Type, document we belong to and parent (if not root)
85 SvgDocument
& mrDocument
;
86 const SvgNode
* mpParent
;
87 const SvgNode
* mpAlternativeParent
;
90 std::vector
< std::unique_ptr
<SvgNode
> > maChildren
;
93 std::optional
<OUString
> mpId
;
96 std::optional
<OUString
> mpClass
;
101 /// Display value #i121656#
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;
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
);
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
);
135 SvgDocument
& rDocument
,
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
);
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;
170 std::optional
<OUString
> const & getId() const { return mpId
; }
171 void setId(OUString
const &);
174 std::optional
<OUString
> const & getClass() const { return mpClass
; }
175 void setClass(OUString
const &);
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
); }
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: */