xtd - Reference Guide 0.2.0
font.h
Go to the documentation of this file.
1 #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 
17 namespace 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 
44  class drawing_export_ font final : public xtd::object {
45  public:
47 
52  font(const font& prototype, float em_size);
53 
58  font(const font& prototype, float em_size, font_style style);
59 
63  font(const font& prototype, font_style style);
64 
74  font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit, uint8_t gdi_char_set, bool gdi_vertical_font);
75 
85  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) {}
86 
95  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) {}
96 
105  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) {}
106 
113  font(xtd::ustring family_name, float em_size, font_style style, graphics_unit unit) : font(family_name, em_size, style, unit, 0, false) {}
114 
121  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) {}
122 
128  font(xtd::ustring family_name, float em_size, font_style style) : font(family_name, em_size, style, graphics_unit::point, 0, false) {}
129 
135  font(const drawing::font_family& font_family, float em_size, font_style style) : font(font_family, em_size, style, graphics_unit::point, 0, false) {}
136 
142  font(xtd::ustring family_name, float em_size, graphics_unit unit) : font(family_name, em_size, font_style::regular, unit, 0, false) {}
143 
149  font(const drawing::font_family& font_family, float em_size, graphics_unit unit) : font(font_family, em_size, font_style::regular, unit, 0, false) {}
150 
155  font(xtd::ustring family_name, float em_size) : font(family_name, em_size, font_style::regular, graphics_unit::point, 0, false) {}
156 
161  font(const drawing::font_family& font_family, float em_size) : font(font_family, em_size, font_style::regular, graphics_unit::point, 0, false) {}
163 
165  font(const font& value);
166  font& operator =(const font& value);
167  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_;}
168  bool operator !=(const font& value) const {return !operator ==(value);}
169  ~font();
171 
173 
177  bool bold() const {return (data_->style_ & font_style::bold) == font_style::bold;}
178 
182  drawing::font_family font_family() const {return data_->font_family_;}
183 
209  uint8_t gdi_char_set() const {return data_->gdi_char_set_;}
210 
215  bool gdi_vertical_font() const {return data_->gdi_vertical_font_;}
216 
219  intptr_t handle() const {return data_->handle_;}
220 
227  int32_t height() const;
228 
232  bool is_system_font() const {return data_->is_system_font_;}
233 
236  bool italic() const {return (data_->style_ & font_style::italic) == font_style::italic;}
237 
240  const xtd::ustring& name() const {return data_->font_family_.name();}
241 
244  const xtd::ustring& original_font_name() const {return data_->original_font_name_;}
245 
248  float size() const {return data_->size_;}
249 
252  float size_in_points() const;
253 
256  bool strikeout() const {return (data_->style_ & font_style::strikeout) == font_style::strikeout;}
257 
260  font_style style() const {return data_->style_;}
261 
264  bool underline() const {return (data_->style_ & font_style::underline) == font_style::underline;}
265 
268  graphics_unit unit() const {return data_->unit_;}
270 
272 
277  static font from_hdc(const intptr_t hdc);
278 
282  static font from_hfont(const intptr_t hfont);
283 
288  float get_height() const;
289 
295  float get_height(const graphics& graphics) const;
296 
301  float get_height(float dpi) const;
302 
306  intptr_t to_hfont() const;
307 
310  xtd::ustring to_string() const noexcept override {
311  //return ustring::format("[{}: ]", ustring::class_name(*this));
312  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_);
313  }
315 
316  private:
317  friend class graphics;
318  friend class system_fonts;
319  friend class xtd::forms::native::font_dialog;
320  font() = default;
321  explicit font(intptr_t hfont);
322  struct data {
323  intptr_t handle_ = 0;
324  drawing::font_family font_family_;
325  uint8_t gdi_char_set_ = 1;
326  bool gdi_vertical_font_ = false;
327  bool is_system_font_ = false;
328  xtd::ustring original_font_name_;
329  float size_ = 8.25f;
330  xtd::ustring system_font_name_;
331  font_style style_ = font_style::regular;
332  graphics_unit unit_ = graphics_unit::point;
333  };
334  std::shared_ptr<data> data_ = std::make_shared<data>();
335  };
336  }
337 }
Defines a particular format for text, including font face, size, and style attributes. This class cannot be inherited.
Definition: font.h:44
bool strikeout() const
Gets a value that indicates whether this xtd::drawing::font is strikeout.
Definition: font.h:256
graphics_unit unit() const
Gets the unit of measure for this xtd::drawing::font.
Definition: font.h:268
Defines a group of type faces having a similar basic design and certain variations in styles...
Definition: font_family.h:37
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:128
bool italic() const
Gets a value that indicates whether this xtd::drawing::font is italic.
Definition: font.h:236
Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional ...
Definition: point.h:53
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:51
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:149
Specifies the fonts used to display text in Windows display elements.
Definition: system_fonts.h:25
xtd::ustring to_string() const noexcept override
Converts this font_family to a human-readable string representation.
Definition: font.h:310
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:95
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:121
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:209
Contains xtd::drawing::font_family class.
Specifies that the height of the control is defined.
drawing::font_family font_family() const
Gets the xtd::drawing::font_family associated with this xtd::drawing::font.
Definition: font.h:182
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:135
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:215
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:113
bool underline() const
Gets a value that indicates whether this xtd::drawing::font is underline.
Definition: font.h:264
Contains xtd::ustring class.
float size() const
Gets the em-size of this xtd::drawing::font measured in the units specified by the unit property...
Definition: font.h:248
const xtd::ustring & original_font_name() const
Gets the face name of this Font.
Definition: font.h:244
Contains xtd::object class.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:30
Contains xtd::drawing::graphics_unit enum class.
font_style
Specifies style information applied to text. This enumeration has a flags attribute that allows a bit...
Definition: font_style.h:17
static ustring class_name()
Gets the class name of the object_t.
Definition: ustring.h:459
font(const drawing::font_family &font_family, float em_size)
Initializes a new xtd::drawing::font using the specified size.
Definition: font.h:161
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:85
bool bold() const
Gets a value that indicates whether this xtd::drawing::font is bold.
Definition: font.h:177
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition: ustring.h:706
graphics_unit
Specifies the unit of measure for the given data. This enumeration has a flags attribute that allows ...
Definition: graphics_unit.h:17
const xtd::ustring & name() const
Gets the face name of this xtd::drawing::font.
Definition: font.h:240
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
intptr_t handle() const
Gets the window handle that the font is bound to.
Definition: font.h:219
Defines an object used to draw lines and curves. This class cannot be inherited.
Definition: graphics.h:70
font_style style() const
Gets style information for this xtd::drawing::font.
Definition: font.h:260
bool is_system_font() const
Gets a value indicating whether the font is a member of xtd::drawing::system_fonts.
Definition: font.h:232
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:142
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:105
font(xtd::ustring family_name, float em_size)
Initializes a new xtd::drawing::font using the specified size and unit.
Definition: font.h:155