bpp-core3  3.0.0
FontManager.h
Go to the documentation of this file.
1 //
2 // File: FontManager.h
3 // Authors:
4 // Julien Dutheil
5 // Created: 2008-03-08 00:00:00
6 //
7 
8 /*
9  Copyright or © or Copr. Bio++ Developement 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_FONTMANAGER_H
42 #define BPP_GRAPHICS_FONT_FONTMANAGER_H
43 
44 
45 #include "Font.h"
46 
47 // From the STL:
48 #include <vector>
49 
50 #include "../../Text/TextTools.h"
51 #include "../../Exceptions.h"
52 
53 namespace bpp
54 {
60 template<class CodeType>
62 {
63 public:
65  virtual ~FontManager() {}
66 
67 public:
72  virtual CodeType getCode(const Font& font) const = 0;
73 
79  virtual const Font& getFont(CodeType& code) const = 0;
80 
84  virtual std::vector<CodeType> getCodes() const = 0;
85 
89  virtual std::vector<Font> getFonts() const = 0;
90 
94  virtual size_t getNumberOfFonts() const = 0;
95 };
96 
97 
98 template<class CodeType>
100  public virtual FontManager<CodeType>
101 {
102 private:
103  std::vector<Font> fonts_;
104  std::vector<CodeType> codes_;
105 
106 public:
108 
109 public:
110  CodeType getCode(const Font& font) const
111  {
112  for (unsigned int i = 0; i < fonts_.size(); i++)
113  {
114  if (fonts_[i] == font)
115  {
116  return codes_[i];
117  }
118  }
119  throw Exception("AbstractFontManager::getCode. Unknown font: " + font.toString());
120  }
121 
122  const Font& getFont(int& code) const
123  {
124  for (unsigned int i = 0; i < codes_.size(); i++)
125  {
126  if (codes_[i] == code)
127  {
128  return fonts_[i];
129  }
130  }
131  throw Exception("AbstractFontManager::getColor. No font associated to this code: " + TextTools::toString(code));
132  }
133  std::vector<CodeType> getCodes() const { return codes_; }
134  std::vector<Font> getFonts() const { return fonts_; }
135  size_t getNumberOfFonts() const { return fonts_.size(); }
136 
137 protected:
138  void registerFont_(const Font& font, int code)
139  {
140  codes_.push_back(code);
141  fonts_.push_back(font);
142  }
143 };
144 } // end of namespace.
145 #endif // BPP_GRAPHICS_FONT_FONTMANAGER_H
void registerFont_(const Font &font, int code)
Definition: FontManager.h:138
std::vector< CodeType > codes_
Definition: FontManager.h:104
const Font & getFont(int &code) const
Definition: FontManager.h:122
size_t getNumberOfFonts() const
Definition: FontManager.h:135
std::vector< CodeType > getCodes() const
Definition: FontManager.h:133
std::vector< Font > fonts_
Definition: FontManager.h:103
std::vector< Font > getFonts() const
Definition: FontManager.h:134
CodeType getCode(const Font &font) const
Definition: FontManager.h:110
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
Definition: Exceptions.h:59
Associate special fonts to a code.
Definition: FontManager.h:62
virtual ~FontManager()
Definition: FontManager.h:65
virtual std::vector< CodeType > getCodes() const =0
virtual const Font & getFont(CodeType &code) const =0
virtual std::vector< Font > getFonts() const =0
virtual size_t getNumberOfFonts() const =0
virtual CodeType getCode(const Font &font) const =0
Data structure for fonts.
Definition: Font.h:59
std::string toString() const
Definition: Font.h:158
std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:153