EMAN2
emftgl.h
Go to the documentation of this file.
00001 
00005 /*
00006  * Author: David Woolford, 7/16/2008 (woolford@bcm.edu)
00007  * Copyright (c) 2000-2006 Baylor College of Medicine
00008  *
00009  * This software is issued under a joint BSD/GNU license. You may use the
00010  * source code in this file under either license. However, note that the
00011  * complete EMAN2 and SPARX software packages have some GPL dependencies,
00012  * so you are responsible for compliance with the licenses of these packages
00013  * if you opt to use BSD licensing. The warranty disclaimer below holds
00014  * in either instance.
00015  *
00016  * This complete copyright notice must be included in any revised version of the
00017  * source code. Additional authorship citations may be added, but existing
00018  * author citations must be preserved.
00019  *
00020  * This program is free software; you can redistribute it and/or modify
00021  * it under the terms of the GNU General Public License as published by
00022  * the Free Software Foundation; either version 2 of the License, or
00023  * (at your option) any later version.
00024  *
00025  * This program is distributed in the hope that it will be useful,
00026  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00027  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00028  * GNU General Public License for more details.
00029  *
00030  * You should have received a copy of the GNU General Public License
00031  * along with this program; if not, write to the Free Software
00032  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00033  *
00034  * */
00035 #ifndef emftgl_h__
00036 #define emftgl_h__
00037 
00038 #include <string>
00039 using std::string;
00040 
00041 #include <vector>
00042 using std::vector;
00043 
00044 #include <map>
00045 using std::map;
00046 
00047 #ifdef OLD_FTGL
00048         #include <FTGL/FTGL.h>
00049 #else
00050         #include <FTGL/ftgl.h>
00051 #endif
00052 
00053 
00054 #include <FTGL/FTFont.h>
00055 namespace EMAN {
00056 
00057 
00081 class EMFTGL
00082 {
00083         public:
00087 #ifdef __APPLE__
00088                 EMFTGL() : font_file_name("/Library/Fonts/Arial.ttf" ), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
00089 #else
00090 #ifdef WIN32
00091                 EMFTGL() : font_file_name("" ), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
00092 #else
00093                 EMFTGL() : font_file_name("/usr/share/fonts/dejavu/DejaVuSerif.ttf"), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
00094 #endif
00095 
00096 
00097 #endif
00098 
00100                 ~EMFTGL() {};
00101 
00102 
00108                 enum FontMode {
00109                         EXTRUDE,
00110                         PIXMAP,
00111                         TEXTURE,
00112                         BITMAP,
00113                         OUTLINE,
00114                         POLYGON
00115                 };
00116 
00121                 void render_string(const string& message);
00122 
00128                 vector<float> bounding_box(const string& message);
00129 
00133                 void set_font_file_name(const string& file_name) { font_file_name = file_name; }
00134 
00138                 void set_face_size(const unsigned int size) { face_size = size; }
00139 
00142                 void set_depth(const unsigned int d ) { depth = d; }
00143 
00146                 void set_using_display_lists(const bool b) { use_display_lists = b; }
00147 
00150                 void set_font_mode(const FontMode m ) { mode = m; }
00153                 string get_font_file_name() { return font_file_name; }
00156                 unsigned int get_face_size() {return face_size; }
00159                 unsigned int get_depth() { return depth; }
00162                 bool get_using_display_lists() { return use_display_lists; }
00165                 FontMode get_font_mode() { return mode; }
00166 
00167 
00168 
00169         private:
00171 //              EMFTGL(const EMFTGL& );  FIXME solve this issue
00173 //              EMFTGL& operator=(const EMFTGL& );
00174 
00175                 string font_file_name;
00176                 unsigned int face_size;
00177                 unsigned int depth;
00178                 bool use_display_lists;
00179 
00180                 FontMode mode;
00181 
00189                 class EMFTGLFontInstance
00190                 {
00191                         public:
00194                                 EMFTGLFontInstance(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int d, const bool use_dl);
00195                                 ~EMFTGLFontInstance();
00196 
00199                                 bool params_match(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int depth, const bool use_dl);
00200 
00203                                 FTFont* get_font() { return font; }
00204                         private:
00206 //                              EMFTGLFontInstance(const EMFTGLFontInstance& );
00208 //                              EMFTGLFontInstance& operator=(const EMFTGLFontInstance& );
00209 
00210                                 EMFTGL::FontMode font_mode;
00211                                 string font_file_name;
00212                                 unsigned int face_size;
00213                                 unsigned int depth;
00214                                 bool use_display_lists;
00215                                 FTFont* font;
00216                 };
00217 
00224                 class EMFTGLManager
00225                 {
00226                         public:
00227                                 EMFTGLManager();
00228 //              static EMFTGLManager& instance();
00229 
00230                                 ~EMFTGLManager();
00231 
00234                                 FTFont* get_font(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int d, const bool use_dl);
00235                         private:
00237 //                              EMFTGLManager(const EMFTGLManager& );
00239 //                              EMFTGLManager& operator=(const EMFTGLManager& );
00240 
00241                                 vector<EMFTGLFontInstance*> font_instances;
00242                 };
00243 
00244                 EMFTGLManager fm;
00245 };
00246 
00247 
00248 
00249 
00250 } // namespace EMAN
00251 
00252 #endif //emftgl_h__