Label.hh 2.6 KB
/*
 * 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_ */