Font.cc 1.95 KB
/*
 * Font.cc
 *
 *  Created on: 30 oct. 2013
 *      Author: CS
 */

#include "Font.hh"
#include "DefaultPlotConfiguration.hh"
#include <ostream>

namespace plot {

const std::vector<std::string> Font::sFamily { "sans-serif", "serif", "monospace", "script", "symbol" };
const std::vector<std::string> Font::sStyle { "upright", "italic", "oblique" };
const std::vector<std::string> Font::sWeight { "medium", "bold" };

const float Font::DEFAULT_CHARACTER_SIZE = 23.0;

Font::Font(const std::string& pname, int psize) :
		_name(pname), _size(psize), _style(0), _weight(0) {
}

Font::Font(const Font& pfont) :
		_name(pfont._name), _size(pfont._size), _style(pfont._style), _weight(pfont._weight) {
}

Font::~Font() {
}

void Font::setName (const std::string & name) {
	_name = name;
}

void Font::setSize (int size) {
	_size = size;
}

void Font::setStyle (const std::string & style) {
	for (size_t i = 0; i < sStyle.size(); ++i) {
		if (style.compare(sStyle[i]) == 0) {
			_style = i;
		}
	}
}

void Font::setWeight (const std::string & weight) {
	for (size_t i = 0; i < sWeight.size(); ++i) {
		if (weight.compare(sWeight[i]) == 0) {
			_weight = i;
		}
	}
}

std::ostream& operator <<(std::ostream& out,const Font& font) {
	out << "[FONT]" << std::endl;
	out << "font.name=" << font._name << std::endl;
	out << "font.size=" << font._size << std::endl;
	out << "font.style=" << font.sStyle[font._style] << std::endl;
	out << "font.weight=" << font.sWeight[font._weight] << std::endl;
	return out;
}

PLINT getPlFontFamily(Font& font) {
	for (size_t i = 0; i < Font::sFamily.size(); ++i) {
		if (Font::sFamily[i] == font._name) {
			return i;
		}
	}
	return 1; // sans-serif
}

PLFLT getPlFontScaleFactor(Font& font) {
	return (float) font._size / Font::DEFAULT_CHARACTER_SIZE;
}

PLFLT getPlFontDef(Font& /*font*/) {
	return 0.0; // keep default font
}

PLINT getPlFontStyle(Font& font) {
	return font._style;
}

PLINT getPlFontWeight(Font& font) {
	return font._weight;
}

} /* namespace plot */