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