Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/diagram/diagramfragmenthandler.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
21
#include "diagramdefinitioncontext.hxx"
22
#include "diagramfragmenthandler.hxx"
23
#include "datamodelcontext.hxx"
24
#include <drawingml/colorchoicecontext.hxx>
25
#include <oox/helper/attributelist.hxx>
26
#include <oox/token/namespaces.hxx>
27
#include <utility>
28
29
using namespace ::oox::core;
30
31
namespace oox::drawingml {
32
33
DiagramDataFragmentHandler::DiagramDataFragmentHandler( XmlFilterBase& rFilter,
34
                                                        const OUString& rFragmentPath,
35
                                                        OoxDiagramDataPtr xDataPtr )
36
366
    : FragmentHandler2( rFilter, rFragmentPath )
37
366
    , mpDataPtr(std::move( xDataPtr ))
38
366
{
39
366
}
40
41
DiagramDataFragmentHandler::~DiagramDataFragmentHandler( ) noexcept
42
366
{
43
44
366
}
45
46
void SAL_CALL DiagramDataFragmentHandler::endDocument()
47
330
{
48
49
330
}
50
51
ContextHandlerRef
52
DiagramDataFragmentHandler::onCreateContext( ::sal_Int32 aElement,
53
                                             const AttributeList& )
54
330
{
55
330
    switch( aElement )
56
330
    {
57
330
    case DGM_TOKEN( dataModel ):
58
330
        return new DataModelContext( *this, mpDataPtr );
59
0
    default:
60
0
        break;
61
330
    }
62
63
0
    return this;
64
330
}
65
66
DiagramLayoutFragmentHandler::DiagramLayoutFragmentHandler( SmartArtDiagram& rDgm,
67
                                                        XmlFilterBase& rFilter,
68
                                                        const OUString& rFragmentPath,
69
                                                        DiagramLayoutPtr xDataPtr )
70
313
    : FragmentHandler2( rFilter, rFragmentPath )
71
313
    , mpDataPtr(std::move( xDataPtr ))
72
313
    , mrDgm(rDgm)
73
313
{
74
313
}
75
76
DiagramLayoutFragmentHandler::~DiagramLayoutFragmentHandler( ) noexcept
77
313
{
78
79
313
}
80
81
void SAL_CALL DiagramLayoutFragmentHandler::endDocument()
82
236
{
83
84
236
}
85
86
ContextHandlerRef
87
DiagramLayoutFragmentHandler::onCreateContext( ::sal_Int32 aElement,
88
                                               const AttributeList& rAttribs )
89
3.68k
{
90
3.68k
    switch( aElement )
91
3.68k
    {
92
236
    case DGM_TOKEN( layoutDef ):
93
236
        return new DiagramDefinitionContext( mrDgm, *this, rAttribs, mpDataPtr );
94
3.44k
    default:
95
3.44k
        break;
96
3.68k
    }
97
98
3.44k
    return this;
99
3.68k
}
100
101
DiagramQStylesFragmentHandler::DiagramQStylesFragmentHandler( XmlFilterBase& rFilter,
102
                                                              const OUString& rFragmentPath,
103
                                                              DiagramQStyleMap& rStylesMap ) :
104
236
    FragmentHandler2( rFilter, rFragmentPath ),
105
236
    maStyleEntry(),
106
236
    mrStylesMap( rStylesMap )
107
236
{}
108
109
::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::createStyleMatrixContext(
110
    sal_Int32 nElement,
111
    const AttributeList& rAttribs,
112
    ShapeStyleRef& o_rStyle )
113
26.8k
{
114
26.8k
    o_rStyle.mnThemedIdx = (nElement == A_TOKEN(fontRef)) ?
115
20.1k
        rAttribs.getToken( XML_idx, XML_none ) : rAttribs.getInteger( XML_idx, 0 );
116
26.8k
    return new ColorContext(*this, &o_rStyle.maPhClr);
117
26.8k
}
118
119
::oox::core::ContextHandlerRef DiagramQStylesFragmentHandler::onCreateContext( sal_Int32 nElement,
120
                                                                               const AttributeList& rAttribs )
121
74.9k
{
122
    // state-table like way of navigating the color fragment. we
123
    // currently ignore everything except styleLbl in the styleDef
124
    // element
125
74.9k
    switch( getCurrentElement() )
126
74.9k
    {
127
141
        case XML_ROOT_CONTEXT:
128
141
            return nElement == DGM_TOKEN(styleDef) ? this : nullptr;
129
7.67k
        case DGM_TOKEN(styleDef):
130
7.67k
            return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
131
40.2k
        case DGM_TOKEN(styleLbl):
132
40.2k
            return nElement == DGM_TOKEN(style) ? this : nullptr;
133
26.8k
        case DGM_TOKEN(style):
134
26.8k
        {
135
26.8k
            switch( nElement )
136
26.8k
            {
137
6.71k
                case A_TOKEN(lnRef):     // CT_StyleMatrixReference
138
6.71k
                    return createStyleMatrixContext(nElement,rAttribs,
139
6.71k
                                                    maStyleEntry.maLineStyle);
140
6.71k
                case A_TOKEN(fillRef):   // CT_StyleMatrixReference
141
6.71k
                    return createStyleMatrixContext(nElement,rAttribs,
142
6.71k
                                                    maStyleEntry.maFillStyle);
143
6.71k
                case A_TOKEN(effectRef): // CT_StyleMatrixReference
144
6.71k
                    return createStyleMatrixContext(nElement,rAttribs,
145
6.71k
                                                    maStyleEntry.maEffectStyle);
146
6.71k
                case A_TOKEN(fontRef):   // CT_FontReference
147
6.71k
                    return createStyleMatrixContext(nElement,rAttribs,
148
6.71k
                                                    maStyleEntry.maTextStyle);
149
26.8k
            }
150
0
            return nullptr;
151
26.8k
        }
152
74.9k
    }
153
154
0
    return nullptr;
155
74.9k
}
156
157
void DiagramQStylesFragmentHandler::onStartElement( const AttributeList& rAttribs )
158
13.5k
{
159
13.5k
    if( getCurrentElement() == DGM_TOKEN( styleLbl ) )
160
6.71k
    {
161
6.71k
        maStyleName = rAttribs.getStringDefaulted( XML_name);
162
6.71k
        maStyleEntry = mrStylesMap[maStyleName];
163
6.71k
    }
164
13.5k
}
165
166
void DiagramQStylesFragmentHandler::onEndElement( )
167
13.5k
{
168
13.5k
    if( getCurrentElement() == DGM_TOKEN(styleLbl) )
169
6.71k
        mrStylesMap[maStyleName] = maStyleEntry;
170
13.5k
}
171
172
ColorFragmentHandler::ColorFragmentHandler( ::oox::core::XmlFilterBase& rFilter,
173
                                            const OUString& rFragmentPath,
174
                                            DiagramColorMap& rColorsMap ) :
175
141
    FragmentHandler2(rFilter,rFragmentPath),
176
141
    maColorEntry(),
177
141
    mrColorsMap(rColorsMap)
178
141
{}
179
180
::oox::core::ContextHandlerRef ColorFragmentHandler::onCreateContext( sal_Int32 nElement,
181
                                                                      const AttributeList& /*rAttribs*/ )
182
29.2k
{
183
    // state-table like way of navigating the color fragment. we
184
    // currently ignore everything except styleLbl in the colorsDef
185
    // element
186
29.2k
    switch( getCurrentElement() )
187
29.2k
    {
188
86
        case XML_ROOT_CONTEXT:
189
86
            return nElement == DGM_TOKEN(colorsDef) ? this : nullptr;
190
4.45k
        case DGM_TOKEN(colorsDef):
191
4.45k
            return nElement == DGM_TOKEN(styleLbl) ? this : nullptr;
192
24.6k
        case DGM_TOKEN(styleLbl):
193
24.6k
        {
194
24.6k
            switch( nElement )
195
24.6k
            {
196
                // the actual colors - defer to color fragment handlers.
197
198
4.11k
                case DGM_TOKEN(fillClrLst):
199
4.11k
                    return new ColorsContext( *this, maColorEntry.maFillColors );
200
4.11k
                case DGM_TOKEN(linClrLst):
201
4.11k
                    return new ColorsContext( *this, maColorEntry.maLineColors );
202
4.11k
                case DGM_TOKEN(effectClrLst):
203
4.11k
                    return new ColorsContext( *this, maColorEntry.maEffectColors );
204
4.11k
                case DGM_TOKEN(txFillClrLst):
205
4.11k
                    return new ColorsContext( *this, maColorEntry.maTextFillColors );
206
4.11k
                case DGM_TOKEN(txLinClrLst):
207
4.11k
                    return new ColorsContext( *this, maColorEntry.maTextLineColors );
208
4.11k
                case DGM_TOKEN(txEffectClrLst):
209
4.11k
                    return new ColorsContext( *this, maColorEntry.maTextEffectColors );
210
24.6k
            }
211
0
            break;
212
24.6k
        }
213
29.2k
    }
214
215
0
    return nullptr;
216
29.2k
}
217
218
void ColorFragmentHandler::onStartElement( const AttributeList& rAttribs )
219
4.20k
{
220
4.20k
    if( getCurrentElement() == DGM_TOKEN(styleLbl) )
221
4.11k
    {
222
4.11k
        maColorName = rAttribs.getStringDefaulted( XML_name);
223
4.11k
        maColorEntry = mrColorsMap[maColorName];
224
4.11k
    }
225
4.20k
}
226
227
void ColorFragmentHandler::onEndElement( )
228
4.20k
{
229
4.20k
    if( getCurrentElement() == DGM_TOKEN(styleLbl) )
230
4.11k
        mrColorsMap[maColorName] = maColorEntry;
231
4.20k
}
232
233
}
234
235
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */