Blame view

src/ParamOutputImpl/Plot/Label.hh 2.68 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
 * 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;

	enum Style {
		BOLD, ITALIC, NORMAL
	};

	Label() :
			_font(Font("", 0)), _color(0, 0, 0) {
	}

	Label(Font font) :
			_font(font), _color(0, 0, 0) {
	}

	Label(Font font, Color color) :
			_font(font), _color(color) {
	}

	Label(const Label& label) :
			_font(label._font), _style(label._style), _text(
					label._text), _color(label._color) {
	}

	virtual ~Label() {
	}

	static Style getStyle(std::string style) {
		if (style == "italic") {
			return Style::ITALIC;
		} else if (style == "bold") {
			return Style::BOLD;
		}
		return Style::NORMAL;
	}

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

	/**
	 * Label font name and size.
	 */
	Font _font;

	/**
	 * Label style.
	 */
	std::vector<Style> _style;

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

	/**
	 * Text color
	 */
	Color _color;

	/**
	 * Dumps label properties, used for test.
	 */
	void dump(std::ostream& out, std::string& prefix);
};

inline std::ostream& operator <<(std::ostream& out,
		Label::Style const & style) {

	std::string strStyle;
	switch (style) {
	case Label::Style::BOLD:
		strStyle = "bold";
		break;
	case Label::Style::ITALIC:
		strStyle = "italic";
		break;
	case Label::Style::NORMAL:
	default:
		strStyle = "normal";
	}
	out << strStyle;
	return out;
}

inline std::ostream& operator <<(std::ostream& out,
		std::vector<Label::Style>const & styles) {
	std::string styleStr;
	for (size_t i = 0; i < styles.size(); ++i) {
		Label::Style style = styles[i];
		switch (style) {
		case Label::Style::BOLD:
			styleStr += "bold";
			break;
		case Label::Style::ITALIC:
			styleStr += "italic";
			break;
		case Label::Style::NORMAL:
		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;
	out << "label.font.name=" << label._font._name << std::endl;
	out << "label.font.size=" << label._font._size << std::endl;
	out << "label.style=" << label._style << std::endl;
	out << "label.text=" << label._text << std::endl;
	out << "label.color=" << label._color << std::endl;
	return out;
}

PLINT getPlFontWeight(const std::vector<Label::Style>& styles);
PLINT getPlFontStyle(const std::vector<Label::Style>& styles);

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