LibreOffice Module svgio (master) 1
svggnode.cxx
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#include <svggnode.hxx>
21#include <osl/diagnose.h>
22
23namespace svgio::svgreader
24{
26 SVGToken aType,
27 SvgDocument& rDocument,
28 SvgNode* pParent)
29 : SvgNode(aType, rDocument, pParent),
30 maSvgStyleAttributes(*this)
31 {
32 OSL_ENSURE(aType == SVGToken::Defs || aType == SVGToken::G, "SvgGNode should only be used for Group and Defs (!)");
33 }
34
36 {
37 }
38
40 {
41 // tdf#98599 attributes may be inherit by the children, therefore read them
42 // #i125258# for SVGToken::G take CssStyles into account
44 }
45
46 void SvgGNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
47 {
48 // call parent
49 SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
50
51 // read style attributes
52 maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
53
54 // parse own
55 switch(aSVGToken)
56 {
57 case SVGToken::Style:
58 {
59 readLocalCssStyle(aContent);
60 break;
61 }
63 {
64 const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
65
66 if(!aMatrix.isIdentity())
67 {
68 setTransform(aMatrix);
69 }
70 break;
71 }
72 default:
73 {
74 break;
75 }
76 }
77 }
78
80 {
81 if(SVGToken::Defs == getType())
82 {
83 // #i125258# no decompose needed for defs element, call parent for SVGTokenDefs
85 }
86 else
87 {
88 // #i125258# for SVGTokenG decompose children
90
91 if(pStyle)
92 {
94
95 // decompose children
96 SvgNode::decomposeSvgNode(aContent, bReferenced);
97
98 if(!aContent.empty())
99 {
100 pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
101 }
102 }
103 }
104 }
105} // end of namespace svgio::svgreader
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool isIdentity() const
SvgStyleAttributes maSvgStyleAttributes
use styles
Definition: svggnode.hxx:32
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent) override
Definition: svggnode.cxx:46
const std::optional< basegfx::B2DHomMatrix > & getTransform() const
transform content
Definition: svggnode.hxx:49
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const override
Definition: svggnode.cxx:79
virtual ~SvgGNode() override
Definition: svggnode.cxx:35
virtual const SvgStyleAttributes * getSvgStyleAttributes() const override
Definition: svggnode.cxx:39
SvgGNode(SVGToken aType, SvgDocument &rDocument, SvgNode *pParent)
Definition: svggnode.cxx:25
void setTransform(const std::optional< basegfx::B2DHomMatrix > &pMatrix)
Definition: svggnode.hxx:50
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer &rTarget, bool bReferenced) const
Definition: svgnode.cxx:584
SVGToken getType() const
basic data read access
Definition: svgnode.hxx:156
const SvgStyleAttributes * checkForCssStyle(const SvgStyleAttributes &rOriginal) const
helper to evtl. link to css style
Definition: svgnode.cxx:335
virtual void parseAttribute(const OUString &rTokenName, SVGToken aSVGToken, const OUString &aContent)
Definition: svgnode.cxx:534
void readLocalCssStyle(std::u16string_view aContent)
scan helper to read and interpret a local CssStyle to mpLocalCssStyle
Definition: svgnode.cxx:412
void add_postProcess(drawinglayer::primitive2d::Primitive2DContainer &rTarget, drawinglayer::primitive2d::Primitive2DContainer &&rSource, const std::optional< basegfx::B2DHomMatrix > &pTransform) const
void parseStyleAttribute(SVGToken aSVGToken, const OUString &rContent)
local attribute scanner
FilterGroup & rTarget
basegfx::B2DHomMatrix readTransform(std::u16string_view rCandidate, InfoProvider const &rInfoProvider)
Definition: svgtools.cxx:871