Blame view

src/ParamOutputImpl/Plot/Label.hh 2.6 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
 * Label.hh
 *
 *  Created on: 25 nov. 2013
 *      Author: CS
 */

#ifndef LABEL_HH_
#define LABEL_HH_

#include "Font.hh"
#include "Color.hh"
#include <vector>
#include <boost/shared_ptr.hpp>

namespace plot {
typedef boost::shared_ptr<std::vector<std::string>> LabelRowInfo;

class Label {
public:
	static const std::string DELIMITER;

fbe3c2bb   Benjamin Renard   First commit
23
	Label() :
f6eaec4e   Benjamin Renard   Optimize plot ele...
24
			_color(0, 0, 0), _font(Font("", 0)) {
fbe3c2bb   Benjamin Renard   First commit
25
26
27
	}

	Label(Font font) :
f6eaec4e   Benjamin Renard   Optimize plot ele...
28
			_color(0, 0, 0), _font(font) {
fbe3c2bb   Benjamin Renard   First commit
29
30
31
	}

	Label(Font font, Color color) :
f6eaec4e   Benjamin Renard   Optimize plot ele...
32
			_color(color), _font(font) {
fbe3c2bb   Benjamin Renard   First commit
33
34
35
	}

	Label(const Label& label) :
f6eaec4e   Benjamin Renard   Optimize plot ele...
36
37
			_style(label._style), _text(
					label._text), _color(label._color), _font(label._font) {
fbe3c2bb   Benjamin Renard   First commit
38
39
40
41
42
	}

	virtual ~Label() {
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
	const Font& getFont() const {
		return _font;
	}

	void setFont(const Font& font) {
		_font = font;
	}

	void setFontStyle(Font::Style fontStyle) {
		_font._style = fontStyle;
	}

	void setFontWeight(int fontWeight) {
		_font._weight = fontWeight;
fbe3c2bb   Benjamin Renard   First commit
57
58
59
60
61
62
63
64
	}

	/**
	 * @brief Determine number of line that compose label.
	 */
	static LabelRowInfo getRowNumber(Label const& pLegend);

	/**
fbe3c2bb   Benjamin Renard   First commit
65
66
	 * Label style.
	 */
f6eaec4e   Benjamin Renard   Optimize plot ele...
67
	std::vector<Font::Style> _style;
fbe3c2bb   Benjamin Renard   First commit
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

	/**
	 * Label text.
	 */
	std::string _text;

	/**
	 * Text color
	 */
	Color _color;

	/**
	 * Dumps label properties, used for test.
	 */
	void dump(std::ostream& out, std::string& prefix);
f6eaec4e   Benjamin Renard   Optimize plot ele...
83
84
85
86
87
88

private:
	/**
	 * Label font name and size.
	 */
	Font _font;
fbe3c2bb   Benjamin Renard   First commit
89
90
91
};

inline std::ostream& operator <<(std::ostream& out,
f6eaec4e   Benjamin Renard   Optimize plot ele...
92
		Font::Style const & style) {
fbe3c2bb   Benjamin Renard   First commit
93
94
95

	std::string strStyle;
	switch (style) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
96
	case Font::Style::BOLD:
fbe3c2bb   Benjamin Renard   First commit
97
98
		strStyle = "bold";
		break;
f6eaec4e   Benjamin Renard   Optimize plot ele...
99
	case Font::Style::ITALIC:
fbe3c2bb   Benjamin Renard   First commit
100
101
		strStyle = "italic";
		break;
f6eaec4e   Benjamin Renard   Optimize plot ele...
102
	case Font::Style::NORMAL:
fbe3c2bb   Benjamin Renard   First commit
103
104
105
106
107
108
109
110
	default:
		strStyle = "normal";
	}
	out << strStyle;
	return out;
}

inline std::ostream& operator <<(std::ostream& out,
f6eaec4e   Benjamin Renard   Optimize plot ele...
111
		std::vector<Font::Style>const & styles) {
fbe3c2bb   Benjamin Renard   First commit
112
113
	std::string styleStr;
	for (size_t i = 0; i < styles.size(); ++i) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
114
		Font::Style style = styles[i];
fbe3c2bb   Benjamin Renard   First commit
115
		switch (style) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
116
		case Font::Style::BOLD:
fbe3c2bb   Benjamin Renard   First commit
117
118
			styleStr += "bold";
			break;
f6eaec4e   Benjamin Renard   Optimize plot ele...
119
		case Font::Style::ITALIC:
fbe3c2bb   Benjamin Renard   First commit
120
121
			styleStr += "italic";
			break;
f6eaec4e   Benjamin Renard   Optimize plot ele...
122
		case Font::Style::NORMAL:
fbe3c2bb   Benjamin Renard   First commit
123
124
125
126
127
128
129
130
131
132
133
134
135
		default:
			styleStr += "normal";
		}
		if (i < styles.size() - 1) {
			styleStr += ",";
		}
	}
	out << styleStr;
	return out;
}

inline std::ostream& operator <<(std::ostream& out, Label& label) {
	out << "[LABEL]" << std::endl;
f6eaec4e   Benjamin Renard   Optimize plot ele...
136
137
	out << "label.font.name=" << label.getFont()._name << std::endl;
	out << "label.font.size=" << label.getFont()._size << std::endl;
fbe3c2bb   Benjamin Renard   First commit
138
139
140
141
142
143
	out << "label.style=" << label._style << std::endl;
	out << "label.text=" << label._text << std::endl;
	out << "label.color=" << label._color << std::endl;
	return out;
}

fbe3c2bb   Benjamin Renard   First commit
144
145
146

} /* namespace plot */
#endif /* LABEL_HH_ */