Coverage Report

Created: 2025-11-16 09:57

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