FontFace.h
1/* Copyright (C) 2024 Marc Boris Duerner
2
3 This library is free software; you can redistribute it and/or
4 modify it under the terms of the GNU Lesser General Public
5 License as published by the Free Software Foundation; either
6 version 2.1 of the License, or (at your option) any later version.
7
8 As a special exception, you may use this file as part of a free
9 software library without restriction. Specifically, if other files
10 instantiate templates or use macros or inline functions from this
11 file, or you compile this file and link it with other files to
12 produce an executable, this file does not by itself cause the
13 resulting executable to be covered by the GNU General Public
14 License. This exception does not however invalidate any other
15 reasons why the executable file might be covered by the GNU Library
16 General Public License.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 02110-1301 USA
27*/
28
29#ifndef PT_GFX_FONTFACE_H
30#define PT_GFX_FONTFACE_H
31
32#include <Pt/Gfx/Font.h>
33#include <Pt/SmartPtr.h>
34
35#include <string>
36
37namespace Pt {
38
39namespace Gfx {
40
41class FontFaceData;
42
51class PT_GFX_API FontFace
52{
53 public:
54 typedef Font::Weight Weight;
55 typedef Font::Slant Slant;
56 typedef Font::Stretch Stretch;
57
58 FontFace();
59
60 FontFace(const std::string& family,
61 Weight weight = Weight::Normal,
62 Slant slant = Slant::Normal,
63 Stretch stretch = Stretch::Normal,
64 const std::string& styleName = std::string());
65
66 const std::string& family() const;
67
71 const std::string& name() const;
72
73 const std::string& styleName() const;
74
75 const std::string& style() const;
76
77 Weight weight() const;
78
79 Slant slant() const;
80
81 Stretch stretch() const;
82
83 private:
84 SmartPtr<FontFaceData> _faceData;
85};
86
87
88inline bool operator==(const FontFace& a, const FontFace& b)
89{
90 return a.family() == b.family() &&
91 a.weight() == b.weight() &&
92 a.slant() == b.slant() &&
93 a.stretch() == b.stretch() &&
94 a.styleName() == b.styleName();
95}
96
97
98inline bool operator!=(const FontFace& a, const FontFace& b)
99{
100 return a.family() != b.family() ||
101 a.weight() != b.weight() ||
102 a.slant() != b.slant() ||
103 a.stretch() != b.stretch() ||
104 a.styleName() != b.styleName();
105}
106
107
108inline bool operator<(const FontFace& a, const FontFace& b)
109{
110 if(a.family() != b.family())
111 return a.family() < b.family();
112
113 if(a.weight() != b.weight())
114 return a.weight() < b.weight();
115
116 if(a.slant() != b.slant())
117 return a.slant() < b.slant();
118
119 if(a.stretch() != b.stretch())
120 return a.stretch() < b.stretch();
121
122 return a.styleName() < b.styleName();
123}
124
125
126class FontFaceData
127{
128 public:
129 FontFaceData()
130 : _family()
131 , _style()
132 , _weight(Font::Weight::Normal)
133 , _slant(Font::Slant::Normal)
134 , _stretch(Font::Stretch::Normal)
135 {
136 }
137
138 FontFaceData(const std::string& family,
139 Font::Weight weight = Font::Weight::Normal,
140 Font::Slant slant = Font::Slant::Normal,
141 Font::Stretch stretch = Font::Stretch::Normal,
142 const std::string& styleName = std::string())
143 : _family(family)
144 , _style(styleName)
145 , _weight(weight)
146 , _slant(slant)
147 , _stretch(stretch)
148 {
149 }
150
151 const std::string& family() const
152 {
153 return _family;
154 }
155
156 const std::string& styleName() const
157 {
158 return _style;
159 }
160
161 const std::string& style() const
162 {
163 return _style;
164 }
165
166 Font::Weight weight() const
167 {
168 return _weight;
169 }
170
171 Font::Slant slant() const
172 {
173 return _slant;
174 }
175
176 Font::Stretch stretch() const
177 {
178 return _stretch;
179 }
180
181 private:
182 std::string _family;
183 std::string _style;
184 Font::Weight _weight;
185 Font::Slant _slant;
186 Font::Stretch _stretch;
187};
188
189} // namespace
190
191} // namespace
192
193#endif
Resolved font family and style.
Definition FontFace.h:52
const std::string & name() const
Returns the family of the font face. Alias for family().
Stretch
Describes the requested font stretch.
Definition Font.h:92
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Policy based smart pointer.
Definition SmartPtr.h:462
bool operator!=(const String &a, const String &b)
Compares two strings.
Definition Api-String.h:875
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33