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