Font.hh
2.16 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Font.hh
*
* Created on: 30 oct. 2013
* Author: CS
*/
#ifndef FONT_HH_
#define FONT_HH_
#include <string>
#include <vector>
#include <plplot/plstream.h>
#include <ostream>
#include <boost/algorithm/string/trim.hpp>
namespace plot {
typedef std::pair<double, double> CharSize;
class Font {
public:
enum class Style {
NORMAL, ITALIC, OBLIQUE
};
enum class Weight {
NORMAL, BOLD
};
Font(const std::string& pname, int psize);
Font(const Font& pfont);
virtual ~Font();
static const std::vector<std::string> sFamily;
static const std::vector<std::string> sStyle;
static const std::vector<std::string> sWeight;
bool isSet(){
return !_name.empty() && _size > 0;
}
static Style getStyleByStr(std::string style) {
boost::trim(style);
if (style.compare("italic") == 0) {
return Style::ITALIC;
}
else if (style.compare("oblique") == 0) {
return Style::OBLIQUE;
}
return Style::NORMAL;
}
static Weight getWeightByStr(std::string weight) {
boost::trim(weight);
if (weight.compare("bold") == 0) {
return Weight::BOLD;
}
return Weight::NORMAL;
}
void setName (const std::string & name);
void setSize (int size);
void setStyle (Style style);
void setWeight (Weight weight);
std::string getName() const;
int getSize() const;
Style getStyle() const;
Weight getWeight() const;
void dump(std::ostream& out, std::string& prefix);
private:
std::string _name;
int _size;
Style _style;
Weight _weight;
};
inline std::ostream& operator <<(std::ostream& out,
Font::Style const & style) {
std::string strStyle;
switch (style) {
case Font::Style::ITALIC:
strStyle = "italic";
break;
case Font::Style::OBLIQUE:
strStyle = "oblique";
break;
case Font::Style::NORMAL:
default:
strStyle = "normal";
}
out << strStyle;
return out;
}
inline std::ostream& operator <<(std::ostream& out,
Font::Weight const & weight) {
std::string strWeight;
switch (weight) {
case Font::Weight::BOLD:
strWeight = "bold";
break;
case Font::Weight::NORMAL:
default:
strWeight = "normal";
}
out << strWeight;
return out;
}
std::ostream& operator << (std::ostream& out, const Font& font);
} /* namespace plot */
#endif /* FONT_HH_ */