Font.cc
1.95 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
/*
* 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 */