|
bpp-core
2.1.0
|
00001 // 00002 // File: FontManager.h 00003 // Created by: Julien Dutheil 00004 // Created on: Sat Mar 08 2008 00005 // 00006 00007 /* 00008 Copyright or © or Copr. Bio++ Developement Team, (November 17, 2004) 00009 00010 This software is a computer program whose purpose is to provide utilitary 00011 classes. This file belongs to the Bio++ Project. 00012 00013 This software is governed by the CeCILL license under French law and 00014 abiding by the rules of distribution of free software. You can use, 00015 modify and/ or redistribute the software under the terms of the CeCILL 00016 license as circulated by CEA, CNRS and INRIA at the following URL 00017 "http://www.cecill.info". 00018 00019 As a counterpart to the access to the source code and rights to copy, 00020 modify and redistribute granted by the license, users are provided only 00021 with a limited warranty and the software's author, the holder of the 00022 economic rights, and the successive licensors have only limited 00023 liability. 00024 00025 In this respect, the user's attention is drawn to the risks associated 00026 with loading, using, modifying and/or developing or reproducing the 00027 software by the user in light of its specific status of free software, 00028 that may mean that it is complicated to manipulate, and that also 00029 therefore means that it is reserved for developers and experienced 00030 professionals having in-depth computer knowledge. Users are therefore 00031 encouraged to load and test the software's suitability as regards their 00032 requirements in conditions enabling the security of their systems and/or 00033 data to be ensured and, more generally, to use and operate it in the 00034 same conditions as regards security. 00035 00036 The fact that you are presently reading this means that you have had 00037 knowledge of the CeCILL license and that you accept its terms. 00038 */ 00039 00040 #ifndef _FONTMANAGER_H_ 00041 #define _FONTMANAGER_H_ 00042 00043 #include "Font.h" 00044 00045 // From the STL: 00046 #include <vector> 00047 00048 #include "../../Text/TextTools.h" 00049 00050 namespace bpp 00051 { 00052 00058 template<class CodeType> 00059 class FontManager 00060 { 00061 public: 00062 FontManager() {} 00063 virtual ~FontManager() {} 00064 00065 public: 00066 00071 virtual CodeType getCode(const Font& font) const throw (Exception) = 0; 00072 00078 virtual const Font& getFont(CodeType& code) const throw (Exception) = 0; 00079 00083 virtual std::vector<CodeType> getCodes() const = 0; 00084 00088 virtual std::vector<Font> getFonts() const = 0; 00089 00093 virtual size_t getNumberOfFonts() const = 0; 00094 }; 00095 00096 00097 00098 template<class CodeType> 00099 class AbstractFontManager : 00100 public virtual FontManager<CodeType> 00101 { 00102 private: 00103 std::vector<Font> fonts_; 00104 std::vector<CodeType> codes_; 00105 00106 public: 00107 AbstractFontManager() : fonts_(), codes_() {} 00108 00109 public: 00110 CodeType getCode(const Font& font) const throw (Exception) 00111 { 00112 for (unsigned int i = 0; i < fonts_.size(); i++) 00113 { 00114 if (fonts_[i] == font) 00115 { 00116 return codes_[i]; 00117 } 00118 } 00119 throw Exception("AbstractFontManager::getCode. Unknown font: " + font.toString()); 00120 } 00121 00122 const Font& getFont(int &code) const throw (Exception) 00123 { 00124 for (unsigned int i = 0; i < codes_.size(); i++) 00125 { 00126 if (codes_[i] == code) 00127 { 00128 return fonts_[i]; 00129 } 00130 } 00131 throw Exception("AbstractFontManager::getColor. No font associated to this code: " + TextTools::toString(code)); 00132 } 00133 std::vector<CodeType> getCodes() const { return codes_; } 00134 std::vector<Font> getFonts() const { return fonts_; } 00135 size_t getNumberOfFonts() const { return fonts_.size(); } 00136 00137 protected: 00138 void registerFont_(const Font& font, int code) 00139 { 00140 codes_.push_back(code); 00141 fonts_.push_back(font); 00142 } 00143 00144 }; 00145 00146 } // end of namespace. 00147 00148 #endif //_FONTMANAGER_H_ 00149