Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/oox/source/drawingml/chart/titlecontext.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 <drawingml/chart/titlecontext.hxx>
21
22
#include <drawingml/shapepropertiescontext.hxx>
23
#include <drawingml/textbodycontext.hxx>
24
#include <drawingml/chart/datasourcecontext.hxx>
25
#include <drawingml/chart/titlemodel.hxx>
26
#include <oox/helper/attributelist.hxx>
27
#include <oox/token/namespaces.hxx>
28
29
#include <osl/diagnose.h>
30
31
32
namespace oox::drawingml::chart {
33
34
using ::oox::core::ContextHandler2Helper;
35
using ::oox::core::ContextHandlerRef;
36
37
TextContext::TextContext( ContextHandler2Helper& rParent, TextModel& rModel ) :
38
0
    ContextBase< TextModel >( rParent, rModel )
39
0
{
40
0
}
41
42
TextContext::~TextContext()
43
0
{
44
0
}
45
46
ContextHandlerRef TextContext::onCreateContext( sal_Int32 nElement, const AttributeList& )
47
0
{
48
    // this context handler is used for <c:tx> and embedded <c:v> elements
49
0
    if( isCurrentElement( C_TOKEN( tx ) ) ||
50
0
            isCurrentElement(CX_TOKEN(tx)) ||
51
0
            isCurrentElement(CX_TOKEN(txData)) ) switch( nElement )
52
0
    {
53
0
        case C_TOKEN( rich ):
54
0
        case CX_TOKEN( rich ):
55
0
            return new TextBodyContext( *this, mrModel.mxTextBody.create() );
56
57
0
        case C_TOKEN( strRef ):
58
0
            OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
59
0
            return new StringSequenceContext( *this, mrModel.mxDataSeq.create() );
60
61
0
        case C_TOKEN( v ):
62
0
        case CX_TOKEN( v ):
63
0
            OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" );
64
0
            return this;    // collect value in onCharacters()
65
0
        case CX_TOKEN( txData ):
66
            // CT_TextData can have a <cx:v> element or a sequence
67
            // <cx:f> <cx:v>. The former case will be handled through the
68
            // CX_TOKEN(v) above, but the latter is not handled. TODO
69
0
            return this;
70
0
    }
71
0
    return nullptr;
72
0
}
73
74
void TextContext::onCharacters( const OUString& rChars )
75
0
{
76
0
    if( isCurrentElement( C_TOKEN( v ) ) ||  isCurrentElement( CX_TOKEN( v ) ))
77
0
    {
78
        // Static text is stored as a single string formula token for Excel document.
79
0
        mrModel.mxDataSeq.create().maFormula =  "\"" + rChars + "\"";
80
81
        // Also store it as a single element type for non-Excel document.
82
0
        mrModel.mxDataSeq->maData[0] <<= rChars;
83
0
        mrModel.mxDataSeq->mnPointCount = 1;
84
0
    }
85
0
}
86
87
TitleContext::TitleContext( ContextHandler2Helper& rParent, TitleModel& rModel ) :
88
0
    ContextBase< TitleModel >( rParent, rModel )
89
0
{
90
0
}
91
92
TitleContext::~TitleContext()
93
0
{
94
0
}
95
96
ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
97
0
{
98
0
    switch( nElement )
99
0
    {
100
0
        case C_TOKEN( layout ):
101
0
            return new LayoutContext( *this, mrModel.mxLayout.create() );
102
103
0
        case C_TOKEN( overlay ):
104
0
            mrModel.mbOverlay = rAttribs.getBool( XML_val, true );
105
0
            return nullptr;
106
107
0
        case C_TOKEN( spPr ):
108
0
        case CX_TOKEN( spPr ):
109
0
            return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
110
111
0
        case C_TOKEN( tx ):
112
0
        case CX_TOKEN( tx ):
113
0
            return new TextContext( *this, mrModel.mxText.create() );
114
115
0
        case C_TOKEN( txPr ):
116
0
        case CX_TOKEN( txPr ):
117
0
            return new TextBodyContext( *this, mrModel.mxTextProp.create() );
118
0
    }
119
0
    return nullptr;
120
0
}
121
122
LegendEntryContext::LegendEntryContext( ContextHandler2Helper& rParent, LegendEntryModel& rModel ) :
123
0
    ContextBase< LegendEntryModel >( rParent, rModel )
124
0
{
125
0
}
126
127
LegendEntryContext::~LegendEntryContext()
128
0
{
129
0
}
130
131
ContextHandlerRef LegendEntryContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
132
0
{
133
    // this context handler is used for <c:legendEntry> only
134
0
    switch( nElement )
135
0
    {
136
0
        case C_TOKEN( idx ):
137
0
            mrModel.mnLegendEntryIdx = rAttribs.getInteger( XML_val, -1 );
138
0
            return nullptr;
139
140
0
        case C_TOKEN( delete ):
141
0
            mrModel.mbLabelDeleted = rAttribs.getBool( XML_val, true );
142
0
            return nullptr;
143
0
    }
144
0
    return nullptr;
145
0
}
146
147
LegendContext::LegendContext( ContextHandler2Helper& rParent,
148
        LegendModel& rModel,
149
        bool bOverlay /* = false */,
150
        sal_Int32 nPos /* = XML_r */) :
151
0
    ContextBase< LegendModel >( rParent, rModel )
152
0
{
153
    // These can't be in the initializer list because they're members of
154
    // ContextBase<LegendModel>
155
0
    mrModel.mbOverlay = bOverlay;
156
0
    mrModel.mnPosition = nPos;
157
0
}
158
159
LegendContext::~LegendContext()
160
0
{
161
0
}
162
163
ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
164
0
{
165
0
    switch( nElement )
166
0
    {
167
0
        case C_TOKEN( layout ):
168
0
            return new LayoutContext( *this, mrModel.mxLayout.create() );
169
170
0
        case C_TOKEN( legendPos ):
171
0
            mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r );
172
0
            return nullptr;
173
174
0
        case C_TOKEN( legendEntry ):
175
0
            return new LegendEntryContext( *this, mrModel.maLegendEntries.create() );
176
177
0
        case C_TOKEN( overlay ):
178
            // For cx, overlay is an attribute of <cx:legend>
179
0
            mrModel.mbOverlay = rAttribs.getBool( XML_val, true );
180
0
            return nullptr;
181
182
0
        case C_TOKEN( spPr ):
183
0
        case CX_TOKEN( spPr ):
184
0
            return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() );
185
186
0
        case C_TOKEN( txPr ):
187
0
        case CX_TOKEN( txPr ):
188
0
            return new TextBodyContext( *this, mrModel.mxTextProp.create() );
189
0
    }
190
0
    return nullptr;
191
0
}
192
193
} // namespace oox::drawingml::chart
194
195
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */