Label.cc 1.84 KB
/*
 * 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);
	}

}