Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svgio/source/svgreader/svgellipsenode.cxx
Line
Count
Source
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 <svgellipsenode.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
        SvgEllipseNode::SvgEllipseNode(
28
            SvgDocument& rDocument,
29
            SvgNode* pParent)
30
0
        :   SvgNode(SVGToken::Ellipse, rDocument, pParent),
31
0
            maSvgStyleAttributes(*this),
32
0
            maCx(0),
33
0
            maCy(0),
34
0
            maRx(0),
35
0
            maRy(0)
36
0
        {
37
0
        }
38
39
        SvgEllipseNode::~SvgEllipseNode()
40
0
        {
41
0
        }
42
43
        const SvgStyleAttributes* SvgEllipseNode::getSvgStyleAttributes() const
44
0
        {
45
0
            return checkForCssStyle(maSvgStyleAttributes);
46
0
        }
47
48
        void SvgEllipseNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
49
0
        {
50
            // call parent
51
0
            SvgNode::parseAttribute(aSVGToken, aContent);
52
53
            // read style attributes
54
0
            maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
55
56
            // parse own
57
0
            switch(aSVGToken)
58
0
            {
59
0
                case SVGToken::Style:
60
0
                {
61
0
                    readLocalCssStyle(aContent);
62
0
                    break;
63
0
                }
64
0
                case SVGToken::Cx:
65
0
                {
66
0
                    SvgNumber aNum;
67
68
0
                    if(readSingleNumber(aContent, aNum))
69
0
                    {
70
0
                        maCx = aNum;
71
0
                    }
72
0
                    break;
73
0
                }
74
0
                case SVGToken::Cy:
75
0
                {
76
0
                    SvgNumber aNum;
77
78
0
                    if(readSingleNumber(aContent, aNum))
79
0
                    {
80
0
                        maCy = aNum;
81
0
                    }
82
0
                    break;
83
0
                }
84
0
                case SVGToken::Rx:
85
0
                {
86
0
                    SvgNumber aNum;
87
88
0
                    if(readSingleNumber(aContent, aNum))
89
0
                    {
90
0
                        if(aNum.isPositive())
91
0
                        {
92
0
                            maRx = aNum;
93
0
                        }
94
0
                    }
95
0
                    break;
96
0
                }
97
0
                case SVGToken::Ry:
98
0
                {
99
0
                    SvgNumber aNum;
100
101
0
                    if(readSingleNumber(aContent, aNum))
102
0
                    {
103
0
                        if(aNum.isPositive())
104
0
                        {
105
0
                            maRy = aNum;
106
0
                        }
107
0
                    }
108
0
                    break;
109
0
                }
110
0
                case SVGToken::Transform:
111
0
                {
112
0
                    const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
113
114
0
                    if(!aMatrix.isIdentity())
115
0
                    {
116
0
                        setTransform(aMatrix);
117
0
                    }
118
0
                    break;
119
0
                }
120
0
                default:
121
0
                {
122
0
                    break;
123
0
                }
124
0
            }
125
0
        }
126
127
        void SvgEllipseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool /*bReferenced*/) const
128
0
        {
129
0
            const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
130
131
0
            if(!(pStyle && getRx().isSet() && getRy().isSet()))
132
0
                return;
133
134
0
            const double fRx(getRx().solve(*this, NumberType::xcoordinate));
135
0
            const double fRy(getRy().solve(*this, NumberType::ycoordinate));
136
137
0
            if(fRx <= 0.0 || fRy <= 0.0)
138
0
                return;
139
140
0
            const basegfx::B2DPolygon aPath(
141
0
                basegfx::utils::createPolygonFromEllipse(
142
0
                    basegfx::B2DPoint(
143
0
                        getCx().isSet() ? getCx().solve(*this, NumberType::xcoordinate) : 0.0,
144
0
                        getCy().isSet() ? getCy().solve(*this, NumberType::ycoordinate) : 0.0),
145
0
                    fRx, fRy));
146
147
0
            drawinglayer::primitive2d::Primitive2DContainer aNewTarget;
148
149
0
            pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, nullptr);
150
151
0
            if(!aNewTarget.empty())
152
0
            {
153
0
                pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
154
0
            }
155
0
        }
156
} // end of namespace svgio::svgreader
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */