Debian Codegraph @

garglk/font.h

raw symbols SCIP
1 #ifndef GARGLK_FONT_H
2 #define GARGLK_FONT_H
3
4 #include <string>
5 #include <unordered_map>
6
7 #include "optional.hpp"
8
9 #include "garglk.h"
10
11 class FontFiller {
12 public:
13 enum class Style {
14 Regular,
15 Bold,
16 Italic,
17 BoldItalic
18 };
19
20 explicit FontFiller(FontType type) :
21 m_type(type)
22 {
23 }
24
25 void add(Style style, nonstd::optional<std::string> path) {
26 m_fonts.insert({style, std::move(path)});
27 }
28
29 bool fill() {
30 const auto &regular = m_fonts[Style::Regular];
31 if (!regular.has_value()) {
32 return false;
33 }
34
35 FontFiles &files = m_type == FontType::Monospace ? gli_conf_mono
36 : gli_conf_prop;
37
38 files.r.base = *regular;
39 files.b.base = *regular;
40 files.i.base = *regular;
41 files.z.base = *regular;
42
43 const auto &bold = m_fonts[Style::Bold];
44 if (bold.has_value()) {
45 files.b.base = *bold;
46 files.z.base = *bold;
47 };
48
49 const auto &italic = m_fonts[Style::Italic];
50 if (italic.has_value()) {
51 files.i.base = *italic;
52 files.z.base = *italic;
53 }
54
55 const auto &bolditalic = m_fonts[Style::BoldItalic];
56 if (bolditalic.has_value()) {
57 files.z.base = *bolditalic;
58 }
59
60 return true;
61 }
62
63 private:
64 FontType m_type;
65 std::unordered_map<Style, nonstd::optional<std::string>> m_fonts;
66 };
67
68 #endif