The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
font_description.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2015 - 2017 by Chris Beck<render787@gmail.com>
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 "config.hpp"
18 #include "lexical_cast.hpp"
20 
21 #include <boost/optional.hpp>
22 #include <string>
23 #include <utility>
24 #include <vector>
25 
26 namespace font {
27 
28 // structure used to describe a font, and the subset of the Unicode character
29 // set it covers.
30 //
31 // used by font_config interface (not specific to sdl_ttf or pango)
33 {
35  : name()
36  , bold_name()
37  , italic_name()
39  {
40  }
41 
42  explicit subset_descriptor(const config & font)
43  : name(font["name"].str())
44  , bold_name()
45  , italic_name()
47  {
48  if (font.has_attribute("bold_name")) {
49  bold_name = font["bold_name"].str();
50  }
51 
52  if (font.has_attribute("italic_name")) {
53  italic_name = font["italic_name"].str();
54  }
55 
56  std::vector<std::string> ranges = utils::split(font["codepoints"]);
57 
58  for (const std::string & i : ranges) {
59  std::vector<std::string> r = utils::split(i, '-');
60  if(r.size() == 1) {
61  size_t r1 = lexical_cast_default<size_t>(r[0], 0);
62  present_codepoints.emplace_back(r1, r1);
63  } else if(r.size() == 2) {
64  size_t r1 = lexical_cast_default<size_t>(r[0], 0);
65  size_t r2 = lexical_cast_default<size_t>(r[1], 0);
66 
67  present_codepoints.emplace_back(r1, r2);
68  }
69  }
70  }
71 
73  boost::optional<std::string> bold_name; //If we are using another font for styled characters in this font, rather than SDL TTF method
74  boost::optional<std::string> italic_name;
75 
76  typedef std::pair<int, int> range;
77  std::vector<range> present_codepoints;
78 };
79 
80 } // end namespace font
std::vector< char_t > string
Note: Specific to sdl_ttf.
New lexcical_cast header.
subset_descriptor(const config &font)
Definitions for the interface to Wesnoth Markup Language (WML).
std::vector< std::string > split(const std::string &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::vector< range > present_codepoints
bool has_attribute(config_key_type key) const
Definition: config.cpp:196
std::pair< int, int > range
#define i
boost::optional< std::string > bold_name
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
boost::optional< std::string > italic_name