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