The Battle for Wesnoth  1.19.5+dev
font.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2024
3  by Mark de Wever <koraq@xs4all.nl>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #pragma once
17 
18 #include "font/text.hpp"
19 #include <pango/pango.h>
20 
21 namespace font {
22 
23 /** Small helper class to make sure the pango font object is destroyed properly. */
24 class p_font
25 {
26 public:
27  p_font(const std::string& name, const unsigned size, font::pango_text::FONT_STYLE style)
28  : font_(pango_font_description_new())
29  {
30  pango_font_description_set_family(font_, name.c_str());
31  pango_font_description_set_size(font_, size * PANGO_SCALE);
32 
33  if(style != pango_text::STYLE_NORMAL) {
34  if(style & pango_text::STYLE_ITALIC) {
35  pango_font_description_set_style(font_, PANGO_STYLE_ITALIC);
36  }
37  if(style & pango_text::STYLE_BOLD) {
38  pango_font_description_set_weight(font_, PANGO_WEIGHT_BOLD);
39  }
40  if(style & pango_text::STYLE_UNDERLINE) {
41  /* Do nothing here, underline is a property of the layout. */
42  }
43  }
44  }
45 
46  p_font(const p_font &) = delete;
47  p_font & operator = (const p_font &) = delete;
48 
49  ~p_font() { pango_font_description_free(font_); }
50 
51  PangoFontDescription* get() { return font_; }
52 
53 private:
54  PangoFontDescription *font_;
55 };
56 
57 } // namespace font
Small helper class to make sure the pango font object is destroyed properly.
Definition: font.hpp:25
p_font(const std::string &name, const unsigned size, font::pango_text::FONT_STYLE style)
Definition: font.hpp:27
PangoFontDescription * font_
Definition: font.hpp:54
p_font & operator=(const p_font &)=delete
p_font(const p_font &)=delete
PangoFontDescription * get()
Definition: font.hpp:51
Graphical text output.
std::size_t size(const std::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:85