xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
font.h
Go to the documentation of this file.
1
4#pragma once
5#include <cstdint>
6#include <memory>
7#include <ostream>
8#include <stdexcept>
9#include <vector>
10#include <xtd/object.h>
11#include <xtd/ustring.h>
12#include "../drawing_export.h"
13#include "font_family.h"
14#include "graphics_unit.h"
15
17namespace xtd {
19 namespace forms {
20 namespace native {
21 class font_dialog;
22 }
23 }
25
27 namespace drawing {
29 class graphics;
30 class system_fonts;
32
39 class drawing_export_ font final : public object {
40 public:
44 font (const font& prototype, float em_size);
45
50 font (const font& prototype, float em_size, font_style style);
51
55 font (const font& prototype, font_style style);
56
66 font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set, bool gdi_vertical_font);
67
77 font(const drawing::font_family& font_family, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set, bool gdi_vertical_font) : font(font_family.name(), em_size, style, unit, gdi_char_set, gdi_vertical_font) {}
78
87 font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set) : font(family_name, em_size, style, unit, gdi_char_set, false) {}
88
97 font(const drawing::font_family& font_family, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set) : font(font_family, em_size, style, unit, gdi_char_set, false) {}
98
105 font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit) : font(family_name, em_size, style, unit, 0, false) {}
106
113 font(const drawing::font_family& font_family, float em_size, font_style style, graphics_unit unit) : font(font_family, em_size, style, unit, 0, false) {}
114
120 font(xtd::ustring family_name, float em_size, font_style style) : font(family_name, em_size, style, graphics_unit::point, 0, false) {}
121
127 font(const drawing::font_family& font_family, float em_size, font_style style) : font(font_family, em_size, style, graphics_unit::point, 0, false) {}
128
134 font(xtd::ustring family_name, float em_size, graphics_unit unit) : font(family_name, em_size, font_style::regular, unit, 0, false) {}
135
141 font(const drawing::font_family& font_family, float em_size, graphics_unit unit) : font(font_family, em_size, font_style::regular, unit, 0, false) {}
142
147 font(xtd::ustring family_name, float em_size) : font(family_name, em_size, font_style::regular, graphics_unit::point, 0, false) {}
148
153 font(const drawing::font_family& font_family, float em_size) : font(font_family, em_size, font_style::regular, graphics_unit::point, 0, false) {}
154
156 font(const font& value);
157 font& operator=(const font& value);
158 bool operator==(const font& value) const {return data_->font_family_ == value.data_->font_family_ && data_->gdi_char_set_ == value.data_->gdi_char_set_ && data_->gdi_vertical_font_ == value.data_->gdi_vertical_font_ && data_->style_ == value.data_->style_ && data_->size_ == value.data_->size_ && data_->unit_ == value.data_->unit_;}
159 bool operator!=(const font& value) const {return !operator==(value);}
160 ~font();
162
165 xtd::ustring to_string() const noexcept override {
166 //return ustring::format("[{}: ]", ustring::class_name(*this));
167 return ustring::format("[{}: name={}, size={}, units={}, gdi_char_set={}, gdi_vertical_font={}]", ustring::class_name(*this), data_->font_family_.name(), data_->size_, (int32_t)data_->unit_, data_->gdi_char_set_, data_->gdi_vertical_font_);
168 }
169
171 friend std::ostream& operator<<(std::ostream& os, const xtd::drawing::font& font) noexcept {return os << font.to_string();}
173
176 bool bold() const {return (data_->style_ & font_style::bold) == font_style::bold;}
177
181 drawing::font_family font_family() const {return data_->font_family_;}
182
208 uint8_t gdi_char_set() const {return data_->gdi_char_set_;}
209
214 bool gdi_vertical_font() const {return data_->gdi_vertical_font_;}
215
218 intptr_t handle() const {return data_->handle_;}
219
226 int32_t height() const;
227
231 bool is_system_font() const {return data_->is_system_font_;}
232
235 bool italic() const {return (data_->style_ & font_style::italic) == font_style::italic;}
236
239 const xtd::ustring& name() const {return data_->font_family_.name();}
240
243 const xtd::ustring& original_font_name() const {return data_->original_font_name_;}
244
247 float size() const {return data_->size_;}
248
251 float size_in_points() const;
252
255 bool strikeout() const {return (data_->style_ & font_style::strikeout) == font_style::strikeout;}
256
259 font_style style() const {return data_->style_;}
260
263 bool underline() const {return (data_->style_ & font_style::underline) == font_style::underline;}
264
267 graphics_unit unit() const {return data_->unit_;}
268
272 static font from_hdc(const intptr_t hdc);
273
277 static font from_hfont(const intptr_t hfont);
278
283 float get_height() const;
284
290 float get_height(const graphics& graphics) const;
291
296 float get_height(float dpi) const;
297
301 intptr_t to_hfont() const;
302
303 private:
304 friend class graphics;
305 friend class system_fonts;
306 friend class xtd::forms::native::font_dialog;
307 font() = default;
308 font(intptr_t hfont);
309 struct data {
310 intptr_t handle_ = 0;
311 drawing::font_family font_family_;
312 uint8_t gdi_char_set_ = 1;
313 bool gdi_vertical_font_ = false;
314 bool is_system_font_ = false;
315 xtd::ustring original_font_name_;
316 float size_ = 8.25f;
317 xtd::ustring system_font_name_;
318 font_style style_ = font_style::regular;
319 graphics_unit unit_ = graphics_unit::point;
320 };
321 std::shared_ptr<data> data_ = std::make_shared<data>();
322 };
323 }
324}
Defines a group of type faces having a similar basic design and certain variations in styles....
Definition: font_family.h:32
Defines a particular format for text, including font face, size, and style attributes....
Definition: font.h:39
font(const font &prototype, float em_size)
IInitializes a new Font that uses the specified existing xtd::drawing::font and size.
font(const drawing::font_family &font_family, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set)
Initializes a new xtd::drawing::font using the specified size, style, unit, and character set.
Definition: font.h:97
int32_t height() const
Gets the line spacing of this font.
font(const drawing::font_family &font_family, float em_size, font_style style, graphics_unit unit)
Initializes a new xtd::drawing::font using the specified size, style and unit.
Definition: font.h:113
float get_height(const graphics &graphics) const
Returns the line spacing, in the current unit of a specified xtd::drawing::graphics,...
uint8_t gdi_char_set() const
Gets a byte value that specifies the GDI character set that this xtd::drawing::font uses.
Definition: font.h:208
intptr_t handle() const
Gets the window handle that the font is bound to.
Definition: font.h:218
font(const drawing::font_family &font_family, float em_size, graphics_unit unit)
Initializes a new xtd::drawing::font using the specified size and unit.
Definition: font.h:141
xtd::ustring to_string() const noexcept override
Converts this font_family to a human-readable string representation.
Definition: font.h:165
bool gdi_vertical_font() const
Gets a Boolean value that indicates whether this xtd::drawing::font is derived from a GDI vertical fo...
Definition: font.h:214
font(const drawing::font_family &font_family, float em_size, font_style style)
Initializes a new xtd::drawing::font using the specified size and style.
Definition: font.h:127
font(const font &prototype, float em_size, font_style style)
IInitializes a new Font that uses the specified existing xtd::drawing::font, size and font_style enum...
bool underline() const
Gets a value that indicates whether this xtd::drawing::font is underline.
Definition: font.h:263
const xtd::ustring & original_font_name() const
Gets the face name of this Font.
Definition: font.h:243
float size_in_points() const
font(const drawing::font_family &font_family, float em_size)
Initializes a new xtd::drawing::font using the specified size.
Definition: font.h:153
intptr_t to_hfont() const
bool bold() const
Gets a value that indicates whether this xtd::drawing::font is bold.
Definition: font.h:176
font(const font &prototype, font_style style)
IInitializes a new Font that uses the specified existing xtd::drawing::font and font_style enumeratio...
font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set, bool gdi_vertical_font)
IInitializes a new xtd::drawing::font using the specified size, style, unit, and character set.
float size() const
Gets the em-size of this xtd::drawing::font measured in the units specified by the unit property.
Definition: font.h:247
const xtd::ustring & name() const
Gets the face name of this xtd::drawing::font.
Definition: font.h:239
graphics_unit unit() const
Gets the unit of measure for this xtd::drawing::font.
Definition: font.h:267
font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set)
Initializes a new xtd::drawing::font using the specified size, style, unit, and character set.
Definition: font.h:87
float get_height(float dpi) const
Returns the height, in pixels, of this Font when drawn to a device with the specified vertical resolu...
font(xtd::ustring family_name, float em_size, font_style style)
Initializes a new xtd::drawing::font using the specified size and style.
Definition: font.h:120
static font from_hdc(const intptr_t hdc)
Creates a font from the specified Windows handle to a device context.
font_style style() const
Gets style information for this xtd::drawing::font.
Definition: font.h:259
bool italic() const
Gets a value that indicates whether this xtd::drawing::font is italic.
Definition: font.h:235
bool strikeout() const
Gets a value that indicates whether this xtd::drawing::font is strikeout.
Definition: font.h:255
font(xtd::ustring family_name, float em_size, graphics_unit unit)
Initializes a new xtd::drawing::font using the specified size and unit.
Definition: font.h:134
font(xtd::ustring family_name, float em_size)
Initializes a new xtd::drawing::font using the specified size and unit.
Definition: font.h:147
bool is_system_font() const
Gets a value indicating whether the font is a member of xtd::drawing::system_fonts.
Definition: font.h:231
drawing::font_family font_family() const
Gets the xtd::drawing::font_family associated with this xtd::drawing::font.
Definition: font.h:181
font(const drawing::font_family &font_family, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set, bool gdi_vertical_font)
Initializes a new xtd::drawing::font using the specified size, style, unit, and character set.
Definition: font.h:77
font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit)
Initializes a new xtd::drawing::font using the specified size, style and unit.
Definition: font.h:105
float get_height() const
Returns the line spacing, in pixels, of this font.
static font from_hfont(const intptr_t hfont)
Creates a font from the specified Windows handle.
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:48
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:48
Specifies the fonts used to display text in Windows display elements.
Definition: system_fonts.h:20
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition: object.h:26
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::drawing::font_family class.
Contains xtd::drawing::graphics_unit enum class.
#define drawing_export_
Define shared library export.
Definition: drawing_export.h:13
graphics_unit
Specifies the unit of measure for the given data. This enumeration has a flags attribute that allows ...
Definition: graphics_unit.h:17
font_style
Specifies style information applied to text. This enumeration has a flags attribute that allows a bit...
Definition: font_style.h:17
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17
Contains xtd::object class.
Contains xtd::ustring class.