FTGL  2.1.3~rc5
FTFont.h
Go to the documentation of this file.
1 /*
2  * FTGL - OpenGL font library
3  *
4  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5  * Copyright (c) 2008 Sam Hocevar <sam@zoy.org>
6  * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #ifndef __ftgl__
29 # warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
30 # include <FTGL/ftgl.h>
31 #endif
32 
33 #ifndef __FTFont__
34 #define __FTFont__
35 
36 #ifdef __cplusplus
37 
38 class FTFontImpl;
39 
57 {
58  protected:
64  FTFont(char const *fontFilePath);
65 
74  FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
75 
76  private:
77  /* Allow our internal subclasses to access the private constructor */
78  friend class FTBitmapFont;
79  friend class FTBufferFont;
80  friend class FTExtrudeFont;
81  friend class FTOutlineFont;
82  friend class FTPixmapFont;
83  friend class FTPolygonFont;
84  friend class FTTextureFont;
85 
92  FTFont(FTFontImpl *pImpl);
93 
94  public:
95  virtual ~FTFont();
96 
106  virtual bool Attach(const char* fontFilePath);
107 
118  virtual bool Attach(const unsigned char *pBufferBytes,
119  size_t bufferSizeInBytes);
120 
128  virtual void GlyphLoadFlags(FT_Int flags);
129 
137  virtual bool CharMap(FT_Encoding encoding);
138 
144  virtual unsigned int CharMapCount() const;
145 
151  virtual FT_Encoding* CharMapList();
152 
160  virtual bool FaceSize(const unsigned int size,
161  const unsigned int res = 72);
162 
168  virtual unsigned int FaceSize() const;
169 
176  virtual void Depth(float depth);
177 
184  virtual void Outset(float outset);
185 
193  virtual void Outset(float front, float back);
194 
201  virtual void UseDisplayList(bool useList);
202 
208  virtual float Ascender() const;
209 
215  virtual float Descender() const;
216 
222  virtual float LineHeight() const;
223 
236  virtual FTBBox BBox(const char *string, const int len = -1,
237  FTPoint position = FTPoint(),
238  FTPoint spacing = FTPoint());
239 
251  void BBox(const char* string, float& llx, float& lly, float& llz,
252  float& urx, float& ury, float& urz)
253  {
254  FTBBox b = BBox(string);
255  llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
256  urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
257  }
258 
271  virtual FTBBox BBox(const wchar_t *string, const int len = -1,
272  FTPoint position = FTPoint(),
273  FTPoint spacing = FTPoint());
274 
286  void BBox(const wchar_t* string, float& llx, float& lly, float& llz,
287  float& urx, float& ury, float& urz)
288  {
289  FTBBox b = BBox(string);
290  llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
291  urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
292  }
293 
305  virtual float Advance(const char* string, const int len = -1,
306  FTPoint spacing = FTPoint());
307 
319  virtual float Advance(const wchar_t* string, const int len = -1,
320  FTPoint spacing = FTPoint());
321 
335  virtual FTPoint Render(const char* string, const int len = -1,
336  FTPoint position = FTPoint(),
337  FTPoint spacing = FTPoint(),
338  int renderMode = FTGL::RENDER_ALL);
339 
353  virtual FTPoint Render(const wchar_t *string, const int len = -1,
354  FTPoint position = FTPoint(),
355  FTPoint spacing = FTPoint(),
356  int renderMode = FTGL::RENDER_ALL);
357 
363  virtual FT_Error Error() const;
364 
365  protected:
366  /* Allow impl to access MakeGlyph */
367  friend class FTFontImpl;
368 
378  virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0;
379 
380  private:
384  FTFontImpl *impl;
385 };
386 
387 #endif //__cplusplus
388 
390 
398 struct _FTGLFont;
399 typedef struct _FTGLfont FTGLfont;
400 
409 FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath,
410  void *data,
411  FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
412 
419 
429 FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path);
430 
441 FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data,
442  size_t size);
443 
451 FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding);
452 
460 
468 
478 FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size,
479  unsigned int res);
480 
488 
496 FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth);
497 
507 FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back);
508 
516 FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList);
517 
525 
533 
541 
552 FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
553  int len, float bounds[6]);
554 
562 FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string);
563 
571 FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode);
572 
580 
582 
583 #endif // __FTFont__
584 
FTGlyph
FTGlyph is the base class for FTGL glyphs.
Definition: FTGlyph.h:51
FTFont::Error
virtual FT_Error Error() const
Queries the Font for errors.
ftglDestroyFont
void ftglDestroyFont(FTGLfont *font)
Destroy an FTGL font object.
FTGLglyph
struct _FTGLglyph FTGLglyph
Definition: FTGlyph.h:133
FTFont::FTFont
FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
Open and read a font from a buffer in memory.
ftglGetFontFaceSize
unsigned int ftglGetFontFaceSize(FTGLfont *font)
Get the current face size in points (1/72 inch).
FTPolygonFont
FTPolygonFont is a specialisation of the FTFont class for handling tesselated Polygon Mesh fonts.
Definition: FTGLPolygonFont.h:46
FTFont::Descender
virtual float Descender() const
Gets the global descender height for the face.
ftglAttachFile
int ftglAttachFile(FTGLfont *font, const char *path)
Attach auxilliary file to font e.g.
FTFont::Render
virtual FTPoint Render(const char *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint(), int renderMode=FTGL::RENDER_ALL)
Render a string of characters.
ftglSetFontOutset
void ftglSetFontOutset(FTGLfont *font, float front, float back)
Set the outset distance for the font.
FTFont::UseDisplayList
virtual void UseDisplayList(bool useList)
Enable or disable the use of Display Lists inside FTGL.
FTFont::CharMapCount
virtual unsigned int CharMapCount() const
Get the number of character maps in this face.
ftglCreateCustomFont
FTGLfont * ftglCreateCustomFont(char const *fontFilePath, void *data, FTGLglyph *(*makeglyphCallback)(FT_GlyphSlot, void *))
Create a custom FTGL font object.
FTPixmapFont
FTPixmapFont is a specialisation of the FTFont class for handling Pixmap (Grey Scale) fonts.
Definition: FTGLPixmapFont.h:46
FTFont::BBox
virtual FTBBox BBox(const wchar_t *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint())
Get the bounding box for a string.
FTPoint::Xf
FTGL_FLOAT Xf() const
Definition: FTPoint.h:260
FTOutlineFont
FTOutlineFont is a specialisation of the FTFont class for handling Vector Outline fonts.
Definition: FTGLOutlineFont.h:46
FTGL_END_C_DECLS
#define FTGL_END_C_DECLS
Definition: ftgl.h:44
FTFont::Outset
virtual void Outset(float front, float back)
Set the front and back outset distances for the font.
FTFont::FTFontImpl
friend class FTFontImpl
Definition: FTFont.h:367
FTBBox::Upper
FTPoint const Upper() const
Definition: FTBBox.h:159
FTFont::BBox
void BBox(const wchar_t *string, float &llx, float &lly, float &llz, float &urx, float &ury, float &urz)
Get the bounding box for a string (deprecated).
Definition: FTFont.h:286
FTFont::Render
virtual FTPoint Render(const wchar_t *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint(), int renderMode=FTGL::RENDER_ALL)
Render a string of characters.
FTBBox
FTBBox is a convenience class for handling bounding boxes.
Definition: FTBBox.h:43
FTFont::Advance
virtual float Advance(const char *string, const int len=-1, FTPoint spacing=FTPoint())
Get the advance for a string.
FTFont::~FTFont
virtual ~FTFont()
ftglSetFontFaceSize
int ftglSetFontFaceSize(FTGLfont *font, unsigned int size, unsigned int res)
Set the char size for the current face.
FTExtrudeFont
FTExtrudeFont is a specialisation of the FTFont class for handling extruded Polygon fonts.
Definition: FTGLExtrdFont.h:47
FTPoint
FTPoint class is a basic 3-dimensional point or vector.
Definition: FTPoint.h:43
ftglGetFontBBox
void ftglGetFontBBox(FTGLfont *font, const char *string, int len, float bounds[6])
Get the bounding box for a string.
FTFont::MakeGlyph
virtual FTGlyph * MakeGlyph(FT_GlyphSlot slot)=0
Construct a glyph of the correct type.
ftglGetFontAdvance
float ftglGetFontAdvance(FTGLfont *font, const char *string)
Get the advance width for a string.
ftglRenderFont
void ftglRenderFont(FTGLfont *font, const char *string, int mode)
Render a string of characters.
ftglSetFontDepth
void ftglSetFontDepth(FTGLfont *font, float depth)
Set the extrusion distance for the font.
FTTextureFont
FTTextureFont is a specialisation of the FTFont class for handling Texture mapped fonts.
Definition: FTGLTextureFont.h:46
FTGL::RENDER_ALL
@ RENDER_ALL
Definition: ftgl.h:58
ftgl.h
FTFont::FTFont
FTFont(char const *fontFilePath)
Open and read a font file.
FTGLfont
struct _FTGLfont FTGLfont
Definition: FTFont.h:399
FTPoint::Yf
FTGL_FLOAT Yf() const
Definition: FTPoint.h:261
FTFont::BBox
void BBox(const char *string, float &llx, float &lly, float &llz, float &urx, float &ury, float &urz)
Get the bounding box for a string (deprecated).
Definition: FTFont.h:251
FTPoint::Zf
FTGL_FLOAT Zf() const
Definition: FTPoint.h:262
FTGL_BEGIN_C_DECLS
#define FTGL_BEGIN_C_DECLS
Definition: ftgl.h:43
ftglSetFontCharMap
int ftglSetFontCharMap(FTGLfont *font, FT_Encoding encoding)
Set the character map for the face.
ftglGetFontAscender
float ftglGetFontAscender(FTGLfont *font)
Get the global ascender height for the face.
FTFont::Attach
virtual bool Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
Attach auxilliary data to font e.g font metrics, from memory.
FTFont::LineHeight
virtual float LineHeight() const
Gets the line spacing for the font.
FTFont::GlyphLoadFlags
virtual void GlyphLoadFlags(FT_Int flags)
Set the glyph loading flags.
FTFont
FTFont is the public interface for the FTGL library.
Definition: FTFont.h:57
FTFont::Attach
virtual bool Attach(const char *fontFilePath)
Attach auxilliary file to font e.g font metrics.
FTFont::Ascender
virtual float Ascender() const
Get the global ascender height for the face.
ftglGetFontCharMapCount
unsigned int ftglGetFontCharMapCount(FTGLfont *font)
Get the number of character maps in this face.
ftglAttachData
int ftglAttachData(FTGLfont *font, const unsigned char *data, size_t size)
Attach auxilliary data to font, e.g.
FTFont::CharMapList
virtual FT_Encoding * CharMapList()
Get a list of character maps in this face.
FTBBox::Lower
FTPoint const Lower() const
Definition: FTBBox.h:165
ftglGetFontDescender
float ftglGetFontDescender(FTGLfont *font)
Gets the global descender height for the face.
FTFont::FaceSize
virtual bool FaceSize(const unsigned int size, const unsigned int res=72)
Set the char size for the current face.
FTFont::FaceSize
virtual unsigned int FaceSize() const
Get the current face size in points (1/72 inch).
ftglSetFontDisplayList
void ftglSetFontDisplayList(FTGLfont *font, int useList)
Enable or disable the use of Display Lists inside FTGL.
ftglGetFontLineHeight
float ftglGetFontLineHeight(FTGLfont *font)
Gets the line spacing for the font.
ftglGetFontError
FT_Error ftglGetFontError(FTGLfont *font)
Query a font for errors.
FTFont::Depth
virtual void Depth(float depth)
Set the extrusion distance for the font.
FTBufferFont
FTBufferFont is a specialisation of the FTFont class for handling memory buffer fonts.
Definition: FTBufferFont.h:44
FTGL_EXPORT
#define FTGL_EXPORT
Definition: ftgl.h:107
FTBitmapFont
FTBitmapFont is a specialisation of the FTFont class for handling Bitmap fonts.
Definition: FTGLBitmapFont.h:46
FTFont::Advance
virtual float Advance(const wchar_t *string, const int len=-1, FTPoint spacing=FTPoint())
Get the advance for a string.
ftglGetFontCharMapList
FT_Encoding * ftglGetFontCharMapList(FTGLfont *font)
Get a list of character maps in this face.
FTFont::CharMap
virtual bool CharMap(FT_Encoding encoding)
Set the character map for the face.
FTFont::BBox
virtual FTBBox BBox(const char *string, const int len=-1, FTPoint position=FTPoint(), FTPoint spacing=FTPoint())
Get the bounding box for a string.
FTFont::Outset
virtual void Outset(float outset)
Set the outset distance for the font.