Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/docmodel/theme/Theme.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 <docmodel/dllapi.h>
14
#include <vector>
15
16
#include <rtl/ustring.hxx>
17
#include <docmodel/theme/ThemeColorType.hxx>
18
#include <docmodel/theme/ColorSet.hxx>
19
#include <docmodel/theme/FormatScheme.hxx>
20
#include <tools/color.hxx>
21
22
typedef struct _xmlTextWriter* xmlTextWriterPtr;
23
24
namespace model
25
{
26
struct DOCMODEL_DLLPUBLIC ThemeSupplementalFont
27
{
28
    OUString maScript;
29
    OUString maTypeface;
30
};
31
32
struct DOCMODEL_DLLPUBLIC ThemeFont
33
{
34
    OUString maTypeface;
35
    OUString maPanose;
36
    sal_Int16 maPitch = 0;
37
    sal_Int16 maFamily = 0;
38
    sal_Int32 maCharset = 1;
39
40
0
    sal_Int16 getPitchFamily() const { return (maPitch & 0x0F) | (maFamily & 0x0F) << 4; }
41
};
42
43
class DOCMODEL_DLLPUBLIC FontScheme
44
{
45
private:
46
    OUString maName;
47
48
    ThemeFont maMinorLatin;
49
    ThemeFont maMinorAsian;
50
    ThemeFont maMinorComplex;
51
52
    ThemeFont maMajorLatin;
53
    ThemeFont maMajorAsian;
54
    ThemeFont maMajorComplex;
55
56
    std::vector<ThemeSupplementalFont> maMinorSupplementalFontList;
57
    std::vector<ThemeSupplementalFont> maMajorSupplementalFontList;
58
59
public:
60
    FontScheme()
61
110k
        : maName(u"Office"_ustr)
62
110k
    {
63
110k
    }
64
65
    FontScheme(OUString const& rName)
66
4.44k
        : maName(rName)
67
4.44k
    {
68
4.44k
    }
69
70
    static FontScheme getDefault()
71
110k
    {
72
110k
        FontScheme aDefault;
73
110k
        aDefault.maMinorLatin.maTypeface = "Arial";
74
110k
        aDefault.maMinorAsian.maTypeface = "DejaVu Sans";
75
110k
        aDefault.maMinorComplex.maTypeface = "DejaVu Sans";
76
77
110k
        aDefault.maMajorLatin.maTypeface = "Arial";
78
110k
        aDefault.maMajorAsian.maTypeface = "DejaVu Sans";
79
110k
        aDefault.maMajorComplex.maTypeface = "DejaVu Sans";
80
110k
        return aDefault;
81
110k
    }
82
83
0
    const OUString& getName() const { return maName; }
84
85
1.03k
    ThemeFont const& getMinorLatin() const { return maMinorLatin; }
86
4.44k
    void setMinorLatin(ThemeFont const& aMinor) { maMinorLatin = aMinor; }
87
88
3.95k
    ThemeFont const& getMinorAsian() const { return maMinorAsian; }
89
4.44k
    void setMinorAsian(ThemeFont const& aMinor) { maMinorAsian = aMinor; }
90
91
690
    ThemeFont const& getMinorComplex() const { return maMinorComplex; }
92
4.44k
    void setMinorComplex(ThemeFont const& aMinor) { maMinorComplex = aMinor; }
93
94
656
    ThemeFont const& getMajorLatin() const { return maMajorLatin; }
95
4.44k
    void setMajorLatin(ThemeFont const& aMajor) { maMajorLatin = aMajor; }
96
97
946
    ThemeFont const& getMajorAsian() const { return maMajorAsian; }
98
4.44k
    void setMajorAsian(ThemeFont const& aMajor) { maMajorAsian = aMajor; }
99
100
621
    ThemeFont const& getMajorComplex() const { return maMajorComplex; }
101
4.44k
    void setMajorComplex(ThemeFont const& aMajor) { maMajorComplex = aMajor; }
102
103
    OUString findMinorSupplementalTypeface(std::u16string_view rScript) const
104
4.91k
    {
105
4.91k
        for (auto const& rSupplementalFont : maMinorSupplementalFontList)
106
91.9k
        {
107
91.9k
            if (rSupplementalFont.maScript == rScript)
108
272
                return rSupplementalFont.maTypeface;
109
91.9k
        }
110
4.64k
        return OUString();
111
4.91k
    }
112
113
    std::vector<ThemeSupplementalFont> const& getMinorSupplementalFontList() const
114
0
    {
115
0
        return maMinorSupplementalFontList;
116
0
    }
117
118
    void addMinorSupplementalFont(ThemeSupplementalFont const& rfont)
119
93.8k
    {
120
93.8k
        maMinorSupplementalFontList.push_back(rfont);
121
93.8k
    }
122
123
    void setMinorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont)
124
0
    {
125
0
        maMinorSupplementalFontList = rSupplementalFont;
126
0
    }
127
128
    OUString findMajorSupplementalTypeface(std::u16string_view rScript) const
129
1.62k
    {
130
1.62k
        for (auto const& rSupplementalFont : maMajorSupplementalFontList)
131
32.3k
        {
132
32.3k
            if (rSupplementalFont.maScript == rScript)
133
60
                return rSupplementalFont.maTypeface;
134
32.3k
        }
135
1.56k
        return OUString();
136
1.62k
    }
137
138
    std::vector<ThemeSupplementalFont> const& getMajorSupplementalFontList() const
139
0
    {
140
0
        return maMajorSupplementalFontList;
141
0
    }
142
143
    void addMajorSupplementalFont(ThemeSupplementalFont const& rfont)
144
93.8k
    {
145
93.8k
        maMajorSupplementalFontList.push_back(rfont);
146
93.8k
    }
147
148
    void setMajorSupplementalFontList(std::vector<ThemeSupplementalFont> const& rSupplementalFont)
149
0
    {
150
0
        maMajorSupplementalFontList = rSupplementalFont;
151
0
    }
152
};
153
154
/// A named theme has a named color set.
155
class DOCMODEL_DLLPUBLIC Theme
156
{
157
private:
158
    OUString maName;
159
    std::shared_ptr<model::ColorSet> mpColorSet;
160
161
    FontScheme maFontScheme = FontScheme::getDefault();
162
    FormatScheme maFormatScheme;
163
164
public:
165
    Theme();
166
    Theme(OUString const& rName);
167
168
    Theme(Theme const& rTheme);
169
170
4.44k
    void setFontScheme(FontScheme const& rFontScheme) { maFontScheme = rFontScheme; }
171
8.23k
    FontScheme const& getFontScheme() const { return maFontScheme; }
172
173
0
    void setFormatScheme(FormatScheme const& rFormatScheme) { maFormatScheme = rFormatScheme; }
174
0
    FormatScheme const& getFormatScheme() const { return maFormatScheme; }
175
17.7k
    FormatScheme& getFormatScheme() { return maFormatScheme; }
176
177
106k
    void setColorSet(std::shared_ptr<model::ColorSet> const& pColorSet) { mpColorSet = pColorSet; }
178
179
45.4k
    std::shared_ptr<model::ColorSet> const& getColorSet() const { return mpColorSet; }
180
181
    void SetName(const OUString& rName);
182
    const OUString& GetName() const;
183
184
    void dumpAsXml(xmlTextWriterPtr pWriter) const;
185
186
    void ToAny(css::uno::Any& rVal) const;
187
188
    static std::shared_ptr<Theme> FromAny(const css::uno::Any& rVal);
189
190
    std::vector<Color> GetColors() const;
191
192
    Color GetColor(model::ThemeColorType eType) const;
193
};
194
195
} // end of namespace model
196
197
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */