bpp-core3  3.0.0
Font.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPHICS_FONT_FONT_H
6 #define BPP_GRAPHICS_FONT_FONT_H
7 
8 
9 #include "../../Clonable.h"
10 #include "../../Text/TextTools.h"
11 
12 // From the STL:
13 #include <map>
14 #include <string>
15 
16 namespace bpp
17 {
21 class Font :
22  public virtual Clonable
23 {
24 private:
25  std::string family_;
26  short int style_;
27  short int weight_;
28  unsigned int size_;
29  mutable std::map<short int, std::string> styleDesc_;
30  mutable std::map<short int, std::string> weightDesc_;
31 
32 public:
33  Font(const std::string& family = "Default", short int style = STYLE_NORMAL, short int weight = WEIGHT_NORMAL, unsigned int size = 12) :
34  family_(family), style_(style), weight_(weight), size_(size), styleDesc_(), weightDesc_()
35  {
36  init_();
37  }
38 
39  virtual ~Font() {}
40 
41  Font* clone() const { return new Font(*this); }
42 
43 private:
44  void init_();
45 
46 public:
47  bool operator==(const Font& font) const
48  {
49  return family_ == font.family_
50  && style_ == font.style_
51  && weight_ == font.weight_;
52  }
53 
57  const std::string& getFamily() const { return family_; }
58 
62  short int getStyle() const { return style_; }
63 
68  short int getShape() const { return style_; }
69 
73  short int getWeight() const { return weight_; }
74 
79  short int getSeries() const { return weight_; }
80 
84  const unsigned int& getSize() const { return size_; }
85 
89  void setFamily(const std::string& family) { family_ = family; }
90 
94  void setStyle(short int style) { style_ = style; }
95 
100  void setShape(short int shape) { style_ = shape; }
101 
102 
106  void setWeight(short int weight) { weight_ = weight; }
107 
112  void setSeries(short int series) { weight_ = series; }
113 
117  void setSize(unsigned int size) { size_ = size; }
118 
122  std::string toString() const
123  {
124  return family_ + "/" + styleDesc_[style_] + "/" + weightDesc_[weight_] + "/" + TextTools::toString(size_);
125  }
126 
127 public:
128  static const short int STYLE_NORMAL;
129  static const short int STYLE_ITALIC;
130 
131  static const short int WEIGHT_NORMAL;
132  static const short int WEIGHT_BOLD;
133 };
134 } // end of namespace bpp.
135 #endif // BPP_GRAPHICS_FONT_FONT_H
std::string family_
Definition: Font.h:25
static const short int WEIGHT_NORMAL
Definition: Font.h:131
void setSeries(short int series)
Alias function for setWeight.
Definition: Font.h:112
bool operator==(const Font &font) const
Definition: Font.h:47
static const short int STYLE_NORMAL
Definition: Font.h:128
Data structure for fonts.
Definition: Font.h:21
short int getStyle() const
Definition: Font.h:62
short int style_
Definition: Font.h:26
std::string toString() const
Definition: Font.h:122
static const short int STYLE_ITALIC
Definition: Font.h:129
Font * clone() const
Create a copy of this object and send a pointer to it.
Definition: Font.h:41
void setWeight(short int weight)
Definition: Font.h:106
void setFamily(const std::string &family)
Definition: Font.h:89
short int weight_
Definition: Font.h:27
std::map< short int, std::string > weightDesc_
Definition: Font.h:30
void setSize(unsigned int size)
Definition: Font.h:117
static const short int WEIGHT_BOLD
Definition: Font.h:132
unsigned int size_
Definition: Font.h:28
const unsigned int & getSize() const
Definition: Font.h:84
void setShape(short int shape)
Alias function for setStyle.
Definition: Font.h:100
std::map< short int, std::string > styleDesc_
Definition: Font.h:29
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:63
short int getSeries() const
Alias function for getWeight.
Definition: Font.h:79
Font(const std::string &family="Default", short int style=STYLE_NORMAL, short int weight=WEIGHT_NORMAL, unsigned int size=12)
Definition: Font.h:33
short int getShape() const
Alias function for getStyle.
Definition: Font.h:68
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:115
const std::string & getFamily() const
Definition: Font.h:57
virtual ~Font()
Definition: Font.h:39
void setStyle(short int style)
Definition: Font.h:94
short int getWeight() const
Definition: Font.h:73
void init_()
Definition: Font.cpp:15