The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
font.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2017 by Mark de Wever <koraq@xs4all.nl>
3  Part of the Battle for Wesnoth Project http://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_LIGHT) {
40  pango_font_description_set_weight(font_, PANGO_WEIGHT_LIGHT);
41  }
42  if(style & pango_text::STYLE_UNDERLINE) {
43  /* Do nothing here, underline is a property of the layout. */
44  }
45  }
46  }
47 
48  p_font(const p_font &) = delete;
49  p_font & operator = (const p_font &) = delete;
50 
51  ~p_font() { pango_font_description_free(font_); }
52 
53  PangoFontDescription* get() { return font_; }
54 
55 private:
56  PangoFontDescription *font_;
57 };
58 
59 } // namespace font
p_font & operator=(const p_font &)=delete
std::vector< char_t > string
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
size_t size(const utf8::string &str)
Length in characters of a UTF-8 string.
Definition: unicode.cpp:86
static const char * name(const std::vector< SDL_Joystick * > &joysticks, const size_t index)
Definition: joystick.cpp:48
PangoFontDescription * font_
Definition: font.hpp:56