Label.hh
2.6 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
* 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;
Label() :
_color(0, 0, 0), _font(Font("", 0)) {
}
Label(Font font) :
_color(0, 0, 0), _font(font) {
}
Label(Font font, Color color) :
_color(color), _font(font) {
}
Label(const Label& label) :
_style(label._style), _text(
label._text), _color(label._color), _font(label._font) {
}
virtual ~Label() {
}
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;
}
/**
* @brief Determine number of line that compose label.
*/
static LabelRowInfo getRowNumber(Label const& pLegend);
/**
* Label style.
*/
std::vector<Font::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);
private:
/**
* Label font name and size.
*/
Font _font;
};
inline std::ostream& operator <<(std::ostream& out,
Font::Style const & style) {
std::string strStyle;
switch (style) {
case Font::Style::BOLD:
strStyle = "bold";
break;
case Font::Style::ITALIC:
strStyle = "italic";
break;
case Font::Style::NORMAL:
default:
strStyle = "normal";
}
out << strStyle;
return out;
}
inline std::ostream& operator <<(std::ostream& out,
std::vector<Font::Style>const & styles) {
std::string styleStr;
for (size_t i = 0; i < styles.size(); ++i) {
Font::Style style = styles[i];
switch (style) {
case Font::Style::BOLD:
styleStr += "bold";
break;
case Font::Style::ITALIC:
styleStr += "italic";
break;
case Font::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.getFont()._name << std::endl;
out << "label.font.size=" << label.getFont()._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;
}
} /* namespace plot */
#endif /* LABEL_HH_ */