Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svgio/source/svgreader/svgmarkernode.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 <svgmarkernode.hxx>
21
#include <o3tl/string_view.hxx>
22
23
namespace svgio::svgreader
24
{
25
        SvgMarkerNode::SvgMarkerNode(
26
            SvgDocument& rDocument,
27
            SvgNode* pParent)
28
0
        :   SvgNode(SVGToken::Marker, rDocument, pParent),
29
0
            maSvgStyleAttributes(*this),
30
0
            maRefX(0),
31
0
            maRefY(0),
32
0
            maMarkerUnits(MarkerUnits::strokeWidth),
33
0
            maMarkerWidth(3),
34
0
            maMarkerHeight(3),
35
0
            mfAngle(0.0),
36
0
            maMarkerOrient(MarkerOrient::notset),
37
0
            maContextStyleAttibutes(nullptr)
38
0
        {
39
0
        }
40
41
        SvgMarkerNode::~SvgMarkerNode()
42
0
        {
43
0
        }
44
45
        const SvgStyleAttributes* SvgMarkerNode::getSvgStyleAttributes() const
46
0
        {
47
0
            return checkForCssStyle(maSvgStyleAttributes);
48
0
        }
49
50
        void SvgMarkerNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
51
0
        {
52
            // call parent
53
0
            SvgNode::parseAttribute(aSVGToken, aContent);
54
55
            // read style attributes
56
0
            maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
57
58
            // parse own
59
0
            switch(aSVGToken)
60
0
            {
61
0
                case SVGToken::Style:
62
0
                {
63
0
                    readLocalCssStyle(aContent);
64
0
                    break;
65
0
                }
66
0
                case SVGToken::ViewBox:
67
0
                {
68
0
                    const basegfx::B2DRange aRange(readViewBox(aContent, *this));
69
70
0
                    if(!aRange.isEmpty())
71
0
                    {
72
0
                        setViewBox(&aRange);
73
0
                    }
74
0
                    break;
75
0
                }
76
0
                case SVGToken::PreserveAspectRatio:
77
0
                {
78
0
                    maSvgAspectRatio = readSvgAspectRatio(aContent);
79
0
                    break;
80
0
                }
81
0
                case SVGToken::RefX:
82
0
                {
83
0
                    SvgNumber aNum;
84
85
0
                    if(readSingleNumber(aContent, aNum))
86
0
                    {
87
0
                        maRefX = aNum;
88
0
                    }
89
0
                    break;
90
0
                }
91
0
                case SVGToken::RefY:
92
0
                {
93
0
                    SvgNumber aNum;
94
95
0
                    if(readSingleNumber(aContent, aNum))
96
0
                    {
97
0
                        maRefY = aNum;
98
0
                    }
99
0
                    break;
100
0
                }
101
0
                case SVGToken::MarkerUnits:
102
0
                {
103
0
                    if(!aContent.isEmpty())
104
0
                    {
105
0
                        if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"strokeWidth"))
106
0
                        {
107
0
                            setMarkerUnits(MarkerUnits::strokeWidth);
108
0
                        }
109
0
                        else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), commonStrings::aStrUserSpaceOnUse))
110
0
                        {
111
0
                            setMarkerUnits(MarkerUnits::userSpaceOnUse);
112
0
                        }
113
0
                    }
114
0
                    break;
115
0
                }
116
0
                case SVGToken::MarkerWidth:
117
0
                {
118
0
                    SvgNumber aNum;
119
120
0
                    if(readSingleNumber(aContent, aNum))
121
0
                    {
122
0
                        if(aNum.isPositive())
123
0
                        {
124
0
                            maMarkerWidth = aNum;
125
0
                        }
126
0
                    }
127
0
                    break;
128
0
                }
129
0
                case SVGToken::MarkerHeight:
130
0
                {
131
0
                    SvgNumber aNum;
132
133
0
                    if(readSingleNumber(aContent, aNum))
134
0
                    {
135
0
                        if(aNum.isPositive())
136
0
                        {
137
0
                            maMarkerHeight = aNum;
138
0
                        }
139
0
                    }
140
0
                    break;
141
0
                }
142
0
                case SVGToken::Orient:
143
0
                {
144
0
                    const sal_Int32 nLen(aContent.getLength());
145
146
0
                    if(nLen)
147
0
                    {
148
0
                        if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"auto"))
149
0
                        {
150
0
                            setMarkerOrient(MarkerOrient::auto_start);
151
0
                        }
152
0
                        else if(o3tl::equalsIgnoreAsciiCase(o3tl::trim(aContent), u"auto-start-reverse"))
153
0
                        {
154
0
                            setMarkerOrient(MarkerOrient::auto_start_reverse);
155
0
                        }
156
0
                        else
157
0
                        {
158
0
                            sal_Int32 nPos(0);
159
0
                            double fAngle(0.0);
160
161
0
                            if(readAngle(aContent, nPos, fAngle, nLen))
162
0
                            {
163
0
                                setAngle(fAngle);
164
0
                            }
165
0
                        }
166
0
                    }
167
0
                    break;
168
0
                }
169
0
                default:
170
0
                {
171
0
                    break;
172
0
                }
173
0
            }
174
0
        }
175
176
        const drawinglayer::primitive2d::Primitive2DContainer& SvgMarkerNode::getMarkerPrimitives() const
177
0
        {
178
0
            if(Display::None != getDisplay())
179
0
            {
180
0
                decomposeSvgNode(const_cast< SvgMarkerNode* >(this)->aPrimitives, true);
181
0
            }
182
183
0
            return aPrimitives;
184
0
        }
185
186
        basegfx::B2DRange SvgMarkerNode::getCurrentViewPort() const
187
0
        {
188
0
            if(getViewBox())
189
0
            {
190
0
                return *(getViewBox());
191
0
            }
192
0
            else
193
0
            {
194
0
                return SvgNode::getCurrentViewPort();
195
0
            }
196
0
        }
197
198
} // end of namespace svgio::svgreader
199
200
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */