Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/docmodel/styles/ChartStyle.hxx
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
 */
10
11
#pragma once
12
13
#include <oox/drawingml/color.hxx>
14
#include <docmodel/color/ComplexColor.hxx>
15
#include <oox/drawingml/shape.hxx>
16
#include <oox/helper/propertymap.hxx>
17
#include <comphelper/string.hxx>
18
#include <rtl/ustring.hxx>
19
#include <memory>
20
#include <variant>
21
22
namespace model
23
{
24
struct FontOrStyleRef
25
{
26
    enum class StyleColorEnum
27
    {
28
        AUTO
29
    };
30
31
    // The schema uses 'union' here. Implement with a std::variant for safety.
32
    using StyleColorVal = std::variant<sal_uInt32, enum StyleColorEnum, OUString>;
33
    std::unique_ptr<StyleColorVal> maStyleClr; // optional
34
35
    // Get a string version of the ColorVal, for output/streaming
36
    OUString getColorValStr() const
37
0
    {
38
0
        OUString sV;
39
40
0
        if (maStyleClr)
41
0
        {
42
0
            switch (maStyleClr->index())
43
0
            {
44
0
                case 0: // sal_uInt32, a raw color value
45
0
                    sV = OUString::number(std::get<0>(*maStyleClr));
46
0
                    break;
47
0
                case 1: // enum; only value "auto"
48
0
                    sV = "auto";
49
0
                    break;
50
0
                case 2: // arbitrary string
51
0
                    sV = std::get<2>(*maStyleClr);
52
0
                    break;
53
0
            }
54
0
        }
55
0
        return sV;
56
0
    }
57
58
    // Convert an input string to ColorVal
59
    void setColorValStr(const std::optional<OUString>& str)
60
0
    {
61
        // The attribute here can be an integer, a string, or "auto" (which
62
        // of course is also a string, but is considered special). So we
63
        // need to try to convert the input string to an integer, and handle
64
        // it as an int if we can.
65
0
        if (str)
66
0
        {
67
0
            StyleColorVal v;
68
69
0
            const sal_Unicode* pRawStr = str->getStr();
70
71
0
            if (comphelper::string::isdigitAsciiString(pRawStr))
72
0
            {
73
0
                sal_uInt32 nIntVal = str->toUInt32();
74
0
                v = nIntVal;
75
0
            }
76
0
            else
77
0
            {
78
                // Not an integer, so see if it's the fixed enum
79
0
                if (*str == "auto")
80
0
                {
81
0
                    v = StyleColorEnum::AUTO;
82
0
                }
83
0
                else
84
0
                {
85
0
                    v = *str;
86
0
                }
87
0
            }
88
0
            maStyleClr = std::make_unique<StyleColorVal>(v);
89
0
        }
90
0
    }
91
92
    // A child element of cs:CT_FontReference or cs:CT_StyleReference is
93
    // a:EG_ColorChoice. The latter is handled by ColorValueContext.
94
    model::ComplexColor maComplexColor; // needed for ColorValueContext
95
    // There's also an a:EG_ColorTransform member and a 'mods' member for
96
    // FontOrStyleRef. Ignore those for now. TODO
97
};
98
99
struct StyleRef : public FontOrStyleRef
100
{
101
    sal_Int32 mnIdx = 0; // StyleMatrixColumnIndex
102
};
103
104
struct FontRef : public FontOrStyleRef
105
{
106
    enum class FontCollectionIndex
107
    {
108
        MAJOR,
109
        MINOR,
110
        NONE
111
    };
112
113
    FontCollectionIndex meIdx = FontCollectionIndex::MINOR; // required
114
115
    // Get the string value of the font collection index
116
    const char* getFontCollectionStr() const
117
0
    {
118
0
        switch (meIdx)
119
0
        {
120
0
            case FontCollectionIndex::MINOR:
121
0
                return "minor";
122
0
            case FontCollectionIndex::MAJOR:
123
0
                return "major";
124
0
            case FontCollectionIndex::NONE:
125
0
                return "none";
126
0
            default:
127
0
                assert(false);
128
0
        }
129
0
        return nullptr;
130
0
    }
131
132
    // Set the font collection index from a string
133
    void setFontCollectionIndex(std::u16string_view sIdx)
134
0
    {
135
0
        if (sIdx == std::u16string_view(u"major"))
136
0
        {
137
0
            meIdx = FontCollectionIndex::MAJOR;
138
0
        }
139
0
        else if (sIdx == std::u16string_view(u"minor"))
140
0
        {
141
0
            meIdx = FontCollectionIndex::MINOR;
142
0
        }
143
0
        else if (sIdx == std::u16string_view(u"none"))
144
0
        {
145
0
            meIdx = FontCollectionIndex::NONE;
146
0
        }
147
0
    }
148
};
149
150
struct StyleEntry
151
{
152
    std::shared_ptr<StyleRef> mxLnClr;
153
    double mfLineWidthScale = 1.0;
154
    std::shared_ptr<StyleRef> mxFillClr;
155
    std::shared_ptr<StyleRef> mxEffectClr;
156
    std::shared_ptr<FontRef> mxFontClr;
157
    std::shared_ptr<oox::drawingml::Shape> mxShapePr;
158
    // The following is derived from a TextCharacterProperties
159
    std::shared_ptr<oox::PropertyMap> mrTextCharacterPr;
160
    // The following is derived from a TextBodyProperties
161
    std::shared_ptr<oox::PropertyMap> mxTextBodyPr;
162
163
    StyleEntry(std::shared_ptr<StyleRef> aLnClr, double fLineScale,
164
               std::shared_ptr<StyleRef> aFillClr, std::shared_ptr<StyleRef> aEffectClr,
165
               std::shared_ptr<FontRef> aFontClr, std::shared_ptr<oox::drawingml::Shape> aShape,
166
               std::shared_ptr<oox::PropertyMap> aCharProps,
167
               std::shared_ptr<oox::PropertyMap> aBodyProps)
168
0
        : mxLnClr(std::move(aLnClr))
169
0
        , mfLineWidthScale(fLineScale)
170
0
        , mxFillClr(std::move(aFillClr))
171
0
        , mxEffectClr(std::move(aEffectClr))
172
0
        , mxFontClr(std::move(aFontClr))
173
0
        , mxShapePr(std::move(aShape))
174
0
        , mrTextCharacterPr(std::move(aCharProps))
175
0
        , mxTextBodyPr(std::move(aBodyProps))
176
0
    {
177
0
    }
178
};
179
180
struct DOCMODEL_DLLPUBLIC StyleSet
181
{
182
    enum class StyleEntryType
183
    {
184
        BEGIN = 0, // for iteration
185
        AXISTITLE = BEGIN,
186
        CATEGORYAXIS,
187
        CHARTAREA,
188
        DATALABEL,
189
        DATALABELCALLOUT,
190
        DATAPOINT,
191
        DATAPOINT3D,
192
        DATAPOINTLINE,
193
        DATAPOINTMARKER,
194
        DATAPOINTMARKERLAYOUT,
195
        DATAPOINTWIREFRAME,
196
        DATATABLE,
197
        DOWNBAR,
198
        DROPLINE,
199
        ERRORBAR,
200
        FLOOR,
201
        GRIDLINEMAJOR,
202
        GRIDLINEMINOR,
203
        HILOLINE,
204
        LEADERLINE,
205
        LEGEND,
206
        PLOTAREA,
207
        PLOTAREA3D,
208
        SERIESAXIS,
209
        SERIESLINE,
210
        TITLE,
211
        TRENDLINE,
212
        TRENDLINELABEL,
213
        UPBAR,
214
        VALUEAXIS,
215
        WALL,
216
        END // for iteration
217
    };
218
219
    std::map<enum StyleEntryType, StyleEntry> maEntryMap;
220
221
    sal_Int32 mnId = -1;
222
223
    void addEntry(enum StyleEntryType eType, const StyleEntry& aEntry);
224
};
225
226
} // namespace model
227
228
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */