EMAN2
emftgl.h
Go to the documentation of this file.
1/*
2 * Author: David Woolford, 7/16/2008 (woolford@bcm.edu)
3 * Copyright (c) 2000-2006 Baylor College of Medicine
4 *
5 * This software is issued under a joint BSD/GNU license. You may use the
6 * source code in this file under either license. However, note that the
7 * complete EMAN2 and SPARX software packages have some GPL dependencies,
8 * so you are responsible for compliance with the licenses of these packages
9 * if you opt to use BSD licensing. The warranty disclaimer below holds
10 * in either instance.
11 *
12 * This complete copyright notice must be included in any revised version of the
13 * source code. Additional authorship citations may be added, but existing
14 * author citations must be preserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 *
30 * */
31#ifndef emftgl_h__
32#define emftgl_h__
33
34#include <string>
35using std::string;
36
37#include <vector>
38using std::vector;
39
40#include <map>
41using std::map;
42
43#include <FTGL/ftgl.h>
44#include <FTGL/FTFont.h>
45namespace EMAN {
46
47
71class EMFTGL
72{
73 public:
77#ifdef __APPLE__
78 EMFTGL() : font_file_name("/Library/Fonts/Arial.ttf" ), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
79#else
80#ifdef WIN32
81 EMFTGL() : font_file_name("" ), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
82#else
83 EMFTGL() : font_file_name("/usr/share/fonts/dejavu/DejaVuSerif.ttf"), face_size(32), depth(32), use_display_lists(true), mode(TEXTURE) {};
84#endif
85
86
87#endif
90 ~EMFTGL() {};
91
92
98 enum FontMode {
104 POLYGON
105 };
106
111 void render_string(const string& message);
112
118 vector<float> bounding_box(const string& message);
119
123 void set_font_file_name(const string& file_name) { font_file_name = file_name; }
124
128 void set_face_size(const unsigned int size) { face_size = size; }
129
132 void set_depth(const unsigned int d ) { depth = d; }
133
136 void set_using_display_lists(const bool b) { use_display_lists = b; }
137
140 void set_font_mode(const FontMode m ) { mode = m; }
146 unsigned int get_face_size() {return face_size; }
149 unsigned int get_depth() { return depth; }
156
157
158
159 private:
161// EMFTGL(const EMFTGL& ); FIXME solve this issue
163// EMFTGL& operator=(const EMFTGL& );
164
166 unsigned int face_size;
167 unsigned int depth;
169
171
180 {
181 public:
184 EMFTGLFontInstance(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int d, const bool use_dl);
186
189 bool params_match(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int depth, const bool use_dl);
190
193 FTFont* get_font() { return font; }
194 private:
196// EMFTGLFontInstance(const EMFTGLFontInstance& );
198// EMFTGLFontInstance& operator=(const EMFTGLFontInstance& );
199
202 unsigned int face_size;
203 unsigned int depth;
205 FTFont* font;
206 };
207
215 {
216 public:
218// static EMFTGLManager& instance();
219
221
224 FTFont* get_font(EMFTGL::FontMode mode, const string& file_name, const unsigned int face_size, const unsigned int d, const bool use_dl);
225 private:
227// EMFTGLManager(const EMFTGLManager& );
229// EMFTGLManager& operator=(const EMFTGLManager& );
230
231 vector<EMFTGLFontInstance*> font_instances;
232 };
233
235};
236
237
238
239
240} // namespace EMAN
241
242#endif //emftgl_h__
A class for encapsulatiing a particular instance of an FTFont (pointer) Each FTFont is characterised ...
Definition: emftgl.h:180
EMFTGLFontInstance(EMFTGL::FontMode mode, const string &file_name, const unsigned int face_size, const unsigned int d, const bool use_dl)
Constructor - must supply the 5 important parameters.
EMFTGL::FontMode font_mode
Disallow copy construction.
Definition: emftgl.h:200
FTFont * get_font()
Get the pointer to the font.
Definition: emftgl.h:193
bool params_match(EMFTGL::FontMode mode, const string &file_name, const unsigned int face_size, const unsigned int depth, const bool use_dl)
Checks to see if the argument params match the internally stored equivalents.
A class for managing multiple instances of EMFTGLFontInstances, in particular for caching them,...
Definition: emftgl.h:215
vector< EMFTGLFontInstance * > font_instances
Disallow copy construction.
Definition: emftgl.h:231
FTFont * get_font(EMFTGL::FontMode mode, const string &file_name, const unsigned int face_size, const unsigned int d, const bool use_dl)
Get a font with the associated parameters.
EMFTGL is an interface for rendering fonts in EMAN2 using FTGL.
Definition: emftgl.h:72
unsigned int depth
Definition: emftgl.h:167
void set_using_display_lists(const bool b)
Set whether or not the font render should be using display lists.
Definition: emftgl.h:136
bool get_using_display_lists()
Get whether or not font renderer is currently using display lists.
Definition: emftgl.h:152
FontMode mode
Definition: emftgl.h:170
void set_depth(const unsigned int d)
Set the depth of the rendered text - only useful if this->mode = EXTRUDE.
Definition: emftgl.h:132
string font_file_name
Disallow copy construction.
Definition: emftgl.h:165
vector< float > bounding_box(const string &message)
Obtains the bounding box of the given message, as would be rendered using the current state variables...
FontMode get_font_mode()
Get the current font mode.
Definition: emftgl.h:155
FontMode
FontModes correspond to the different FTFont types - this correspondence is EXTRUDE - FTGLExtrdFont,...
Definition: emftgl.h:98
void render_string(const string &message)
Render string performs OpenGL rendering of the string using the current state variables of this class...
void set_font_file_name(const string &file_name)
Set the font file name - should be a .ttf file.
Definition: emftgl.h:123
bool use_display_lists
Definition: emftgl.h:168
unsigned int get_face_size()
Get the currently used face size.
Definition: emftgl.h:146
EMFTGL()
Constructor is OS dependent - it attempts to reference an Operating System specific fonts file by def...
Definition: emftgl.h:83
void set_face_size(const unsigned int size)
Set the face size of the rendered text.
Definition: emftgl.h:128
string get_font_file_name()
Get the name of the current font file in use.
Definition: emftgl.h:143
void set_font_mode(const FontMode m)
Set the font mode.
Definition: emftgl.h:140
unsigned int face_size
Definition: emftgl.h:166
unsigned int get_depth()
Get the currently used depth.
Definition: emftgl.h:149
EMFTGLManager fm
Definition: emftgl.h:234
~EMFTGL()
Destructor.
Definition: emftgl.h:90
E2Exception class.
Definition: aligner.h:40