Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svgio/source/svgreader/svgpolynode.cxx
Line
Count
Source (jump to first uncovered line)
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 <svgpolynode.hxx>
21
#include <basegfx/polygon/b2dpolygon.hxx>
22
#include <basegfx/polygon/b2dpolygontools.hxx>
23
#include <basegfx/polygon/b2dpolypolygon.hxx>
24
25
namespace svgio::svgreader
26
{
27
        SvgPolyNode::SvgPolyNode(
28
            SVGToken aType,
29
            SvgDocument& rDocument,
30
            SvgNode* pParent)
31
0
        :   SvgNode(aType, rDocument, pParent),
32
0
            maSvgStyleAttributes(*this)
33
0
        {
34
0
        }
35
36
        SvgPolyNode::~SvgPolyNode()
37
0
        {
38
0
        }
39
40
        const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
41
0
        {
42
0
            return checkForCssStyle(maSvgStyleAttributes);
43
0
        }
44
45
        void SvgPolyNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
46
0
        {
47
            // call parent
48
0
            SvgNode::parseAttribute(aSVGToken, aContent);
49
50
            // read style attributes
51
0
            maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
52
53
            // parse own
54
0
            switch(aSVGToken)
55
0
            {
56
0
                case SVGToken::Style:
57
0
                {
58
0
                    readLocalCssStyle(aContent);
59
0
                    break;
60
0
                }
61
0
                case SVGToken::Points:
62
0
                {
63
0
                    basegfx::B2DPolygon aPath;
64
65
0
                    if(basegfx::utils::importFromSvgPoints(aPath, aContent))
66
0
                    {
67
0
                        if(aPath.count())
68
0
                        {
69
0
                            if(getType() == SVGToken::Polygon)
70
0
                            {
71
0
                                aPath.setClosed(true);
72
0
                            }
73
74
0
                            setPolygon(aPath);
75
0
                        }
76
0
                    }
77
0
                    break;
78
0
                }
79
0
                case SVGToken::Transform:
80
0
                {
81
0
                    const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
82
83
0
                    if(!aMatrix.isIdentity())
84
0
                    {
85
0
                        setTransform(aMatrix);
86
0
                    }
87
0
                    break;
88
0
                }
89
0
                default:
90
0
                {
91
0
                    break;
92
0
                }
93
0
            }
94
0
        }
95
96
        void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
97
0
        {
98
0
            const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
99
100
0
            if(pStyle && mpPolygon)
101
0
            {
102
0
                drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
103
104
0
                pStyle->add_path(basegfx::B2DPolyPolygon(*mpPolygon), aNewTarget, nullptr);
105
106
0
                if(!aNewTarget.empty())
107
0
                {
108
0
                    pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
109
0
                }
110
0
            }
111
0
        }
112
} // end of namespace svgio::svgreader
113
114
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */