sptk2 logo
SPTK Home Page
CFont.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <map>
30#include <sptk5/String.h>
31#include <sptk5/sptk.h>
32
33namespace sptk {
34
43class SP_EXPORT CFont
44{
48 String m_name;
49
53 uint32_t m_size;
54
58 uint32_t m_color;
59
63 uint32_t m_index;
64
68 uint32_t m_attributes;
69
70public:
79 explicit CFont(const String& name = "arial", uint32_t size = 10, uint32_t color = 0, uint32_t index = 0,
80 uint32_t attributes = 0)
81 : m_name(name)
82 , m_size(size)
83 , m_color(color)
84 , m_index(index)
85 , m_attributes(attributes)
86 {
87 }
88
93 CFont(const CFont& font)
94 : m_name(font.m_name)
95 , m_size(font.m_size)
96 , m_color(font.m_color)
97 , m_index(font.m_index)
98 , m_attributes(font.m_attributes)
99 {
100 }
101
105 String name() const
106 {
107 return m_name;
108 }
109
113 uint32_t size() const
114 {
115 return m_size;
116 }
117
121 uint32_t color() const
122 {
123 return m_color;
124 }
125
129 uint32_t index() const
130 {
131 return m_index;
132 }
133
137 uint32_t attributes() const
138 {
139 return m_attributes;
140 }
141
147 std::string id() const;
148};
149
155class SP_EXPORT CFontsMap
156 : public std::map<String, CFont*, std::less<>>
157{
158public:
162 CFontsMap() = default;
163
168 {
169 clear();
170 }
171
177 void clear();
178};
179
184{
188 std::vector<CFont*> m_items;
189
193 CFontsMap m_index;
194
195public:
199 CFontsVector() = default;
200
205 {
206 clear();
207 }
208
212 CFont* operator[](uint32_t index)
213 {
214 return m_items[index];
215 }
216
220 const CFont* operator[](uint32_t index) const
221 {
222 return m_items[index];
223 }
224
228 CFont* find(const String& fontName) const;
229
234 void push_back(CFont* font);
235
239 uint32_t size() const
240 {
241 return (uint32_t) m_items.size();
242 }
243
249 void clear();
250};
251
255} // namespace sptk
Font information.
Definition: CFont.h:44
CFont(const String &name="arial", uint32_t size=10, uint32_t color=0, uint32_t index=0, uint32_t attributes=0)
Constructor.
Definition: CFont.h:79
std::string id() const
Returns unique font id.
uint32_t attributes() const
Returns font attributes.
Definition: CFont.h:137
String name() const
Returns font name.
Definition: CFont.h:105
uint32_t size() const
Returns font size.
Definition: CFont.h:113
uint32_t index() const
Returns font index in the fonts collection.
Definition: CFont.h:129
CFont(const CFont &font)
Copy constructor.
Definition: CFont.h:93
uint32_t color() const
Returns font color.
Definition: CFont.h:121
CFontsMap is a map font names to fonts.
Definition: CFont.h:157
~CFontsMap()
Destructor.
Definition: CFont.h:167
void clear()
Clears the fonts.
CFontsMap()=default
Constructor.
CFontsVector is a map font names to fonts.
Definition: CFont.h:184
CFontsVector()=default
Constructor.
uint32_t size() const
Definition: CFont.h:239
~CFontsVector()
Destructor.
Definition: CFont.h:204
void push_back(CFont *font)
Appends a font to fonts vector.
void clear()
Clears the fonts.
CFont * find(const String &fontName) const
Returns font by its name.
CFont * operator[](uint32_t index)
Returns font by index.
Definition: CFont.h:212
const CFont * operator[](uint32_t index) const
Returns font by index.
Definition: CFont.h:220
Definition: String.h:49

Fri Oct 14 2022 09:58:31: SPTK 5.4.1