OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
XLStyles_Fonts.hpp
Go to the documentation of this file.
1/*
2 * OpenXLSX-NX - Modern High-Performance C++ Excel Library
3 *
4 * Original work Copyright (c) 2018-2025, Kenneth Troldal Balslev and OpenXLSX contributors
5 * Modified work Copyright (c) 2026, Curry Tang and OpenXLSX-NX contributors
6 *
7 * Distributed under the BSD 3-Clause License.
8 * See LICENSE.md in the project root or https://opensource.org/licenses/BSD-3-Clause
9 */
10
11#ifndef OPENXLSX_XLSTYLES_FONTS_HPP
12#define OPENXLSX_XLSTYLES_FONTS_HPP
13
14#ifdef _MSC_VER
15# pragma warning(push)
16# pragma warning(disable : 4251)
17# pragma warning(disable : 4275)
18#endif
19
20#include "XLStyles_Common.hpp"
21#include "XLColor.hpp"
22#include "XLXmlParser.hpp"
23
24#include <memory>
25#include <string>
26#include <string_view>
27#include <unordered_map>
28#include <vector>
29
30
31namespace OpenXLSX
32{
33 class OPENXLSX_EXPORT XLFont
34 {
35 friend class XLFonts; // for access to m_fontNode in XLFonts::create
36 friend class XLStyles;
37 public: // ---------- Public Member Functions ---------- //
41 XLFont();
42
47 explicit XLFont(const XMLNode& node);
48
53 XLFont(const XLFont& other);
54
59 XLFont(XLFont&& other) noexcept = default;
60
65
71 XLFont& operator=(const XLFont& other);
72
78 XLFont& operator=(XLFont&& other) noexcept = default;
79
84 std::string fontName() const;
85
90 size_t fontCharset() const;
91
96 size_t fontFamily() const;
97
102 size_t fontSize() const;
103
108 XLColor fontColor() const;
109
114 bool bold() const;
115
120 bool italic() const;
121
126 bool strikethrough() const;
127
133
139
145
150 bool outline() const;
151
156 bool shadow() const;
157
162 bool condense() const;
163
168 bool extend() const;
169
175 XLFont& setFontName(std::string_view newName);
176 XLFont& setFontCharset(size_t newCharset);
177 XLFont& setFontFamily(size_t newFamily);
178 XLFont& setFontSize(size_t newSize);
179 XLFont& setFontColor(XLColor newColor);
180 XLFont& setBold(bool set = true);
181 XLFont& setItalic(bool set = true);
182 XLFont& setStrikethrough(bool set = true);
186 XLFont& setOutline(bool set = true);
187 XLFont& setShadow(bool set = true);
188 XLFont& setCondense(bool set = true);
189 XLFont& setExtend(bool set = true);
190
195 std::string summary() const;
196
197 private: // ---------- Private Member Variables ---------- //
198 std::unique_ptr<XMLNode> m_fontNode;
199 };
200
204 class OPENXLSX_EXPORT XLFonts
205 {
206 public: // ---------- Public Member Functions ---------- //
210 XLFonts();
211
216 explicit XLFonts(const XMLNode& node);
217
222 XLFonts(const XLFonts& other);
223
228 XLFonts(XLFonts&& other);
229
233 ~XLFonts();
234
240 XLFonts& operator=(const XLFonts& other);
241
247 XLFonts& operator=(XLFonts&& other) noexcept = default;
248
253 size_t count() const;
254
260 XLFont fontByIndex(XLStyleIndex index) const;
261
267 XLFont operator[](XLStyleIndex index) const { return fontByIndex(index); }
268
275 XLStyleIndex create(XLFont copyFrom = XLFont{}, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
276
285 XLStyleIndex findOrCreate(XLFont copyFrom, std::string_view styleEntriesPrefix = XLDefaultStyleEntriesPrefix);
286
287 private: // ---------- Private Member Variables ---------- //
288 std::unique_ptr<XMLNode> m_fontsNode;
289 std::vector<XLFont> m_fonts;
290 mutable std::unordered_map<std::string, XLStyleIndex> m_fingerprintCache;
291 };
292
293} // namespace OpenXLSX
294
295#ifdef _MSC_VER
296# pragma warning(pop)
297#endif
298
299#endif // OPENXLSX_XLSTYLES_FONTS_HPP
Definition XLColor.hpp:32
Definition XLStyles_Fonts.hpp:34
XLFont(XLFont &&other) noexcept=default
Move Constructor.
XLFont & operator=(const XLFont &other)
Copy assignment operator.
Definition XLStyles_Fonts.cpp:79
XLFont & setVertAlign(XLVerticalAlignRunStyle newVertAlign)
Definition XLStyles_Fonts.cpp:180
XLFontSchemeStyle scheme() const
get the font scheme: none, major or minor
Definition XLStyles_Fonts.cpp:121
XLFont & setShadow(bool set=true)
Definition XLStyles_Fonts.cpp:190
XLFont & setFontName(std::string_view newName)
Setter functions for style parameters.
Definition XLStyles_Fonts.cpp:130
XLFont & setExtend(bool set=true)
Definition XLStyles_Fonts.cpp:200
XLFont & setFontCharset(size_t newCharset)
Definition XLStyles_Fonts.cpp:135
XLUnderlineStyle underline() const
Get the font underline status.
Definition XLStyles_Fonts.cpp:119
size_t fontSize() const
Get the font size.
Definition XLStyles_Fonts.cpp:103
XLFont & setFontFamily(size_t newFamily)
Definition XLStyles_Fonts.cpp:140
XLFont & setOutline(bool set=true)
Definition XLStyles_Fonts.cpp:185
XLFont & setFontSize(size_t newSize)
Definition XLStyles_Fonts.cpp:145
XLFont & setFontColor(XLColor newColor)
Definition XLStyles_Fonts.cpp:150
std::string summary() const
Return a string summary of the font properties.
Definition XLStyles_Fonts.cpp:206
XLVerticalAlignRunStyle vertAlign() const
get the font vertical alignment run style: baseline, subscript or superscript
Definition XLStyles_Fonts.cpp:123
XLFont & setUnderline(XLUnderlineStyle style=XLUnderlineSingle)
Definition XLStyles_Fonts.cpp:170
friend class XLStyles
Definition XLStyles_Fonts.hpp:36
XLFont & setBold(bool set=true)
Definition XLStyles_Fonts.cpp:155
std::string fontName() const
Get the font name.
Definition XLStyles_Fonts.cpp:85
bool italic() const
Get the font italic (cursive) status.
Definition XLStyles_Fonts.cpp:117
XLFont & setStrikethrough(bool set=true)
Definition XLStyles_Fonts.cpp:165
bool shadow() const
Get the shadow status.
Definition XLStyles_Fonts.cpp:126
XLFont & setScheme(XLFontSchemeStyle newScheme)
Definition XLStyles_Fonts.cpp:175
size_t fontFamily() const
Get the font family.
Definition XLStyles_Fonts.cpp:97
bool outline() const
Get the outline status.
Definition XLStyles_Fonts.cpp:125
XLFont & operator=(XLFont &&other) noexcept=default
Move assignment operator.
XLFont & setItalic(bool set=true)
Definition XLStyles_Fonts.cpp:160
friend class XLFonts
Definition XLStyles_Fonts.hpp:35
bool condense() const
Get the condense status.
Definition XLStyles_Fonts.cpp:127
bool extend() const
Get the extend status.
Definition XLStyles_Fonts.cpp:128
size_t fontCharset() const
Get the font charset.
Definition XLStyles_Fonts.cpp:91
XLFont & setCondense(bool set=true)
Definition XLStyles_Fonts.cpp:195
XLFont()
Definition XLStyles_Fonts.cpp:71
bool strikethrough() const
Get the font strikethrough status.
Definition XLStyles_Fonts.cpp:118
XLColor fontColor() const
Get the font color.
Definition XLStyles_Fonts.cpp:109
bool bold() const
Get the font bold status.
Definition XLStyles_Fonts.cpp:116
XLFonts()
Definition XLStyles_Fonts.cpp:228
XLFonts & operator=(XLFonts &&other) noexcept=default
Move assignment operator.
size_t count() const
Get the count of fonts.
Definition XLStyles_Fonts.cpp:263
XLFonts & operator=(const XLFonts &other)
Copy assignment operator.
Definition XLStyles_Fonts.cpp:253
XLFont operator[](XLStyleIndex index) const
Operator overload: allow [] as shortcut access to fontByIndex.
Definition XLStyles_Fonts.hpp:267
XLFont fontByIndex(XLStyleIndex index) const
Get the font identified by index.
Definition XLStyles_Fonts.cpp:265
Definition IXLCellProvider.hpp:24
XLUnderlineStyle
Definition XLStyles_Common.hpp:88
@ XLUnderlineSingle
Definition XLStyles_Common.hpp:90
OpenXLSX_xml_node XMLNode
Definition XLXmlParser.hpp:64
XLFontSchemeStyle
Definition XLStyles_Common.hpp:97
size_t XLStyleIndex
Definition XLStyles_Common.hpp:36
XLVerticalAlignRunStyle
Definition XLStyles_Common.hpp:104