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 "svgtools.hxx"
23 #include "svgtoken.hxx"
24 #include <com/sun/star/xml/sax/XAttributeList.hpp>
25 #include <drawinglayer/primitive2d/Primitive2DContainer.hxx>
31 namespace svgio::svgreader
35 class SvgStyleAttributes
;
40 namespace svgio::svgreader
49 // display property (see SVG 1.1. 11.5), not inheritable
50 enum class Display
// #i121656#
52 Inline
, // the default
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
);
79 class SvgNode
: public InfoProvider
82 /// basic data, Type, document we belong to and parent (if not root)
84 SvgDocument
& mrDocument
;
85 const SvgNode
* mpParent
;
86 const SvgNode
* mpAlternativeParent
;
89 std::vector
< std::unique_ptr
<SvgNode
> > maChildren
;
92 std::optional
<OUString
> mpId
;
95 std::optional
<OUString
> mpClass
;
100 /// Display value #i121656#
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;
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
);
130 SvgDocument
& rDocument
,
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
);
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;
165 std::optional
<OUString
> const & getId() const { return mpId
; }
166 void setId(OUString
const &);
169 std::optional
<OUString
> const & getClass() const { return mpClass
; }
170 void setClass(OUString
const &);
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
; }
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: */