Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/svgio/source/svgreader/svgfeoffsetnode.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 <drawinglayer/primitive2d/transformprimitive2d.hxx>
21
#include <svgfeoffsetnode.hxx>
22
#include <o3tl/string_view.hxx>
23
24
namespace svgio::svgreader
25
{
26
SvgFeOffsetNode::SvgFeOffsetNode(SvgDocument& rDocument, SvgNode* pParent)
27
0
    : SvgFilterNode(SVGToken::FeOffset, rDocument, pParent)
28
0
    , maDx(SvgNumber(0.0))
29
0
    , maDy(SvgNumber(0.0))
30
0
{
31
0
}
32
33
0
SvgFeOffsetNode::~SvgFeOffsetNode() {}
34
35
void SvgFeOffsetNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
36
0
{
37
    // parse own
38
0
    switch (aSVGToken)
39
0
    {
40
0
        case SVGToken::In:
41
0
        {
42
0
            maIn = aContent.trim();
43
0
            break;
44
0
        }
45
0
        case SVGToken::Result:
46
0
        {
47
0
            maResult = aContent.trim();
48
0
            break;
49
0
        }
50
0
        case SVGToken::Dx:
51
0
        {
52
0
            SvgNumber aNum;
53
54
0
            if (readSingleNumber(aContent, aNum))
55
0
            {
56
0
                if (aNum.isPositive())
57
0
                {
58
0
                    maDx = aNum;
59
0
                }
60
0
            }
61
0
            break;
62
0
        }
63
0
        case SVGToken::Dy:
64
0
        {
65
0
            SvgNumber aNum;
66
67
0
            if (readSingleNumber(aContent, aNum))
68
0
            {
69
0
                if (aNum.isPositive())
70
0
                {
71
0
                    maDy = aNum;
72
0
                }
73
0
            }
74
0
            break;
75
0
        }
76
0
        default:
77
0
        {
78
0
            break;
79
0
        }
80
0
    }
81
0
}
82
83
void SvgFeOffsetNode::apply(drawinglayer::primitive2d::Primitive2DContainer& rTarget,
84
                            const SvgFilterNode* pParent) const
85
0
{
86
0
    if (const drawinglayer::primitive2d::Primitive2DContainer* rSource
87
0
        = pParent->findGraphicSource(maIn))
88
0
    {
89
0
        rTarget = *rSource;
90
0
    }
91
92
0
    basegfx::B2DHomMatrix aTransform;
93
94
0
    if (maDx.isSet() || maDy.isSet())
95
0
    {
96
0
        aTransform.translate(maDx.solve(*this, NumberType::xcoordinate),
97
0
                             maDy.solve(*this, NumberType::ycoordinate));
98
0
    }
99
100
0
    const drawinglayer::primitive2d::Primitive2DReference xRef(
101
0
        new drawinglayer::primitive2d::TransformPrimitive2D(aTransform, std::move(rTarget)));
102
103
0
    rTarget = drawinglayer::primitive2d::Primitive2DContainer{ xRef };
104
105
0
    pParent->addGraphicSourceToMapper(maResult, rTarget);
106
0
}
107
108
} // end of namespace svgio::svgreader
109
110
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */