Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svgio/source/svgreader/svgswitchnode.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 <svgswitchnode.hxx>
21
#include <basegfx/matrix/b2dhommatrix.hxx>
22
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
23
#include <i18nlangtag/languagetag.hxx>
24
#include <unotools/syslocaleoptions.hxx>
25
26
namespace svgio::svgreader
27
{
28
SvgSwitchNode::SvgSwitchNode(SvgDocument& rDocument, SvgNode* pParent)
29
0
    : SvgNode(SVGToken::Switch, rDocument, pParent)
30
0
    , maSvgStyleAttributes(*this)
31
0
{
32
0
}
33
34
0
SvgSwitchNode::~SvgSwitchNode() {}
35
36
const SvgStyleAttributes* SvgSwitchNode::getSvgStyleAttributes() const
37
0
{
38
0
    return checkForCssStyle(maSvgStyleAttributes);
39
0
}
40
41
void SvgSwitchNode::parseAttribute(SVGToken aSVGToken, const OUString& aContent)
42
0
{
43
    // call parent
44
0
    SvgNode::parseAttribute(aSVGToken, aContent);
45
46
    // read style attributes
47
0
    maSvgStyleAttributes.parseStyleAttribute(aSVGToken, aContent);
48
49
    // parse own
50
0
    switch (aSVGToken)
51
0
    {
52
0
        case SVGToken::Style:
53
0
        {
54
0
            readLocalCssStyle(aContent);
55
0
            break;
56
0
        }
57
0
        case SVGToken::Transform:
58
0
        {
59
0
            const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
60
61
0
            if (!aMatrix.isIdentity())
62
0
            {
63
0
                setTransform(aMatrix);
64
0
            }
65
0
            break;
66
0
        }
67
0
        default:
68
0
        {
69
0
            break;
70
0
        }
71
0
    }
72
0
}
73
74
void SvgSwitchNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget,
75
                                     bool bReferenced) const
76
0
{
77
    // #i125258# for SVGTokenG decompose children
78
0
    const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
79
80
0
    if (pStyle)
81
0
    {
82
0
        drawinglayer::primitive2d::Primitive2DContainer aContent;
83
84
0
        const auto& rChildren = getChildren();
85
0
        const sal_uInt32 nCount(rChildren.size());
86
0
        OUString sLanguage(SvtSysLocaleOptions().GetRealUILanguageTag().getLanguage());
87
88
0
        SvgNode* pNodeToDecompose = nullptr;
89
0
        for (sal_uInt32 a(0); a < nCount; a++)
90
0
        {
91
0
            SvgNode* pCandidate = rChildren[a].get();
92
93
0
            if (pCandidate && Display::None != pCandidate->getDisplay())
94
0
            {
95
0
                std::vector<OUString> aSystemLanguage = pCandidate->getSystemLanguage();
96
0
                if (!sLanguage.isEmpty() && !aSystemLanguage.empty())
97
0
                {
98
0
                    for (const OUString& sSystemLang : aSystemLanguage)
99
0
                    {
100
0
                        if (sSystemLang == sLanguage)
101
0
                        {
102
0
                            pNodeToDecompose = pCandidate;
103
0
                            break;
104
0
                        }
105
0
                    }
106
0
                }
107
0
                else
108
0
                {
109
0
                    pNodeToDecompose = pCandidate;
110
0
                }
111
0
            }
112
113
0
            if (pNodeToDecompose)
114
0
            {
115
0
                pNodeToDecompose->decomposeSvgNode(aContent, bReferenced);
116
                // break once it's decomposed
117
0
                break;
118
0
            }
119
0
        }
120
121
0
        if (!aContent.empty())
122
0
        {
123
0
            pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
124
0
        }
125
0
    }
126
0
}
127
128
} // end of namespace svgio::svgreader
129
130
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */