Blame view

src/ParamOutputImpl/Plot/Font.hh 2.16 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
 * 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>
df45df5e   Benjamin Renard   Introduce AxisLeg...
15
#include <boost/algorithm/string/trim.hpp>
fbe3c2bb   Benjamin Renard   First commit
16
17
18

namespace plot {

f6eaec4e   Benjamin Renard   Optimize plot ele...
19
typedef std::pair<double, double> CharSize;
fbe3c2bb   Benjamin Renard   First commit
20
21
22

class Font {
public:
df45df5e   Benjamin Renard   Introduce AxisLeg...
23
24
25
26
27
28
	enum class Style {
		NORMAL, ITALIC, OBLIQUE
	};

	enum class Weight {
		NORMAL, BOLD
f6eaec4e   Benjamin Renard   Optimize plot ele...
29
	};
fbe3c2bb   Benjamin Renard   First commit
30
31
32
33
34
35
36

	Font(const std::string& pname, int psize);

	Font(const Font& pfont);

	virtual ~Font();

fbe3c2bb   Benjamin Renard   First commit
37
38
39
40
	static const std::vector<std::string> sFamily;
	static const std::vector<std::string> sStyle;
	static const std::vector<std::string> sWeight;

fbe3c2bb   Benjamin Renard   First commit
41
42
43
44
	bool isSet(){
		return !_name.empty() && _size > 0;
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
45
	static Style getStyleByStr(std::string style) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
46
47
		boost::trim(style);
		if (style.compare("italic") == 0) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
48
			return Style::ITALIC;
df45df5e   Benjamin Renard   Introduce AxisLeg...
49
50
51
		}
		else if (style.compare("oblique") == 0) {
			return Style::OBLIQUE;
f6eaec4e   Benjamin Renard   Optimize plot ele...
52
53
54
55
		}
		return Style::NORMAL;
	}

df45df5e   Benjamin Renard   Introduce AxisLeg...
56
57
58
59
60
61
62
63
	static Weight getWeightByStr(std::string weight) {
		boost::trim(weight);
		if (weight.compare("bold") == 0) {
			return Weight::BOLD;
		}
		return Weight::NORMAL;
	}

fbe3c2bb   Benjamin Renard   First commit
64
65
	void setName (const std::string & name);
	void setSize (int size);
df45df5e   Benjamin Renard   Introduce AxisLeg...
66
67
68
69
70
71
72
	void setStyle (Style style);
	void setWeight (Weight weight);

	std::string getName() const;
	int getSize() const;
	Style getStyle() const;
	Weight getWeight() const;
fbe3c2bb   Benjamin Renard   First commit
73

df45df5e   Benjamin Renard   Introduce AxisLeg...
74
75
76
77
78
79
80
	void dump(std::ostream& out, std::string& prefix);

private:
	std::string _name;
	int _size;
	Style _style;
	Weight _weight;
fbe3c2bb   Benjamin Renard   First commit
81
82
83

};

df45df5e   Benjamin Renard   Introduce AxisLeg...
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
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;
}

fbe3c2bb   Benjamin Renard   First commit
117
118
std::ostream& operator << (std::ostream& out, const Font& font);

fbe3c2bb   Benjamin Renard   First commit
119
120
} /* namespace plot */
#endif /* FONT_HH_ */