Blame view

src/ParamOutputImpl/Plot/Label.cc 1.84 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
/*
 * Label.cc
 *
 *  Created on: 27 nov. 2013
 *      Author: CS
 */

#include "Label.hh"
#include <sstream>
#include <algorithm>
#include <boost/regex.hpp>
#include <boost/algorithm/string/regex.hpp>

namespace plot {

const std::string Label::DELIMITER = "/breakline/";

LabelRowInfo Label::getRowNumber(Label const& pLegend) {
	LabelRowInfo lSplittedLegend(new std::vector<std::string>());

	if (!pLegend._text.empty()) {
		boost::split_regex(*lSplittedLegend.get(), pLegend._text,
				boost::regex(Label::DELIMITER));
	}

	return lSplittedLegend;
}

PLINT getPlFontStyle(const std::vector<Label::Style>& styles) {
	for (auto style : styles) {
		std::ostringstream strStyle;
		strStyle << style;
		for (size_t i = 0; i < Font::sStyle.size(); ++i) {
			if (Font::sStyle[i] == strStyle.str()) {
				return i;
			}
		}
	}
	return 0; // upright
}

PLINT getPlFontWeight(const std::vector<Label::Style>& styles) {
	for (auto style : styles) {
		std::ostringstream strStyle;
		strStyle << style;
		for (size_t i = 0; i < Font::sWeight.size(); ++i) {
			if (Font::sWeight[i] == strStyle.str()) {
				return i;
			}
		}
	}
	return 0; // medium
}

void Label::dump(std::ostream& out, std::string& prefix) {
		prefix += "label.";
		out << prefix << "font.name=" << _font._name << std::endl;
		out << prefix << "font.size=" << _font._size << std::endl;
		out << prefix << "style=";
		std::string styleStr;
		for (size_t i = 0; i < _style.size(); ++i) {
			Label::Style style = _style[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 < _style.size() - 1) {
				styleStr += ",";
			}
		}
		out << styleStr << std::endl;
		out << prefix << "text=" << _text << std::endl;
		_color.dump(out, prefix);
	}

}