bpp-core3  3.0.0
Font.h
Go to the documentation of this file.
1 //
2 // File: Font.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2008-03-03 00:00:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide utilitary
12  classes. This file belongs to the Bio++ Project.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_GRAPHICS_FONT_FONT_H
42 #define BPP_GRAPHICS_FONT_FONT_H
43 
44 
45 #include "../../Clonable.h"
46 #include "../../Text/TextTools.h"
47 
48 // From the STL:
49 #include <map>
50 #include <string>
51 
52 namespace bpp
53 {
57 class Font :
58  public virtual Clonable
59 {
60 private:
61  std::string family_;
62  short int style_;
63  short int weight_;
64  unsigned int size_;
65  mutable std::map<short int, std::string> styleDesc_;
66  mutable std::map<short int, std::string> weightDesc_;
67 
68 public:
69  Font(const std::string& family = "Default", short int style = STYLE_NORMAL, short int weight = WEIGHT_NORMAL, unsigned int size = 12) :
70  family_(family), style_(style), weight_(weight), size_(size), styleDesc_(), weightDesc_()
71  {
72  init_();
73  }
74 
75  virtual ~Font() {}
76 
77  Font* clone() const { return new Font(*this); }
78 
79 private:
80  void init_();
81 
82 public:
83  bool operator==(const Font& font) const
84  {
85  return family_ == font.family_
86  && style_ == font.style_
87  && weight_ == font.weight_;
88  }
89 
93  const std::string& getFamily() const { return family_; }
94 
98  short int getStyle() const { return style_; }
99 
104  short int getShape() const { return style_; }
105 
109  short int getWeight() const { return weight_; }
110 
115  short int getSeries() const { return weight_; }
116 
120  const unsigned int& getSize() const { return size_; }
121 
125  void setFamily(const std::string& family) { family_ = family; }
126 
130  void setStyle(short int style) { style_ = style; }
131 
136  void setShape(short int shape) { style_ = shape; }
137 
138 
142  void setWeight(short int weight) { weight_ = weight; }
143 
148  void setSeries(short int series) { weight_ = series; }
149 
153  void setSize(unsigned int size) { size_ = size; }
154 
158  std::string toString() const
159  {
160  return family_ + "/" + styleDesc_[style_] + "/" + weightDesc_[weight_] + "/" + TextTools::toString(size_);
161  }
162 
163 public:
164  static const short int STYLE_NORMAL;
165  static const short int STYLE_ITALIC;
166 
167  static const short int WEIGHT_NORMAL;
168  static const short int WEIGHT_BOLD;
169 };
170 } // end of namespace bpp.
171 #endif // BPP_GRAPHICS_FONT_FONT_H
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:103
Data structure for fonts.
Definition: Font.h:59
std::map< short int, std::string > weightDesc_
Definition: Font.h:66
static const short int STYLE_NORMAL
Definition: Font.h:164
void init_()
Definition: Font.cpp:52
short int weight_
Definition: Font.h:63
unsigned int size_
Definition: Font.h:64
bool operator==(const Font &font) const
Definition: Font.h:83
const std::string & getFamily() const
Definition: Font.h:93
std::string toString() const
Definition: Font.h:158
static const short int STYLE_ITALIC
Definition: Font.h:165
short int getStyle() const
Definition: Font.h:98
void setSize(unsigned int size)
Definition: Font.h:153
std::map< short int, std::string > styleDesc_
Definition: Font.h:65
void setStyle(short int style)
Definition: Font.h:130
void setShape(short int shape)
Alias function for setStyle.
Definition: Font.h:136
void setSeries(short int series)
Alias function for setWeight.
Definition: Font.h:148
virtual ~Font()
Definition: Font.h:75
Font * clone() const
Create a copy of this object and send a pointer to it.
Definition: Font.h:77
Font(const std::string &family="Default", short int style=STYLE_NORMAL, short int weight=WEIGHT_NORMAL, unsigned int size=12)
Definition: Font.h:69
void setWeight(short int weight)
Definition: Font.h:142
const unsigned int & getSize() const
Definition: Font.h:120
short int getWeight() const
Definition: Font.h:109
void setFamily(const std::string &family)
Definition: Font.h:125
static const short int WEIGHT_NORMAL
Definition: Font.h:167
static const short int WEIGHT_BOLD
Definition: Font.h:168
short int getSeries() const
Alias function for getWeight.
Definition: Font.h:115
short int getShape() const
Alias function for getStyle.
Definition: Font.h:104
short int style_
Definition: Font.h:62
std::string family_
Definition: Font.h:61
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153