FTGL: FTFont.h Source File

FTGL 2.4.0

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@hocevar.net>
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
38class FTFontImpl;
39
56 class FTGL_EXPORT FTFont
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 friend class FTTriangleExtractorFont;
86
93 FTFont(FTFontImpl *pImpl);
94
95 public:
96 virtual ~FTFont();
97
107 virtual bool Attach(const char* fontFilePath);
108
119 virtual bool Attach(const unsigned char *pBufferBytes,
120 size_t bufferSizeInBytes);
121
129 virtual void GlyphLoadFlags(FT_Int flags);
130
138 virtual bool CharMap(FT_Encoding encoding);
139
145 virtual unsigned int CharMapCount() const;
146
152 virtual FT_Encoding* CharMapList();
153
161 virtual bool FaceSize(const unsigned int size,
162 const unsigned int res = 72);
163
169 virtual unsigned int FaceSize() const;
170
177 virtual void Depth(float depth);
178
185 virtual void Outset(float outset);
186
194 virtual void Outset(float front, float back);
195
202 virtual void UseDisplayList(bool useList);
203
209 virtual float Ascender() const;
210
216 virtual float Descender() const;
217
223 virtual float LineHeight() const;
224
237 virtual FTBBox BBox(const char *string, const int len = -1,
238 FTPoint position = FTPoint(),
239 FTPoint spacing = FTPoint());
240
252 void BBox(const char* string, float& llx, float& lly, float& llz,
253 float& urx, float& ury, float& urz)
254 {
255 FTBBox b = BBox(string);
256 llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
257 urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
258 }
259
272 virtual FTBBox BBox(const wchar_t *string, const int len = -1,
273 FTPoint position = FTPoint(),
274 FTPoint spacing = FTPoint());
275
287 void BBox(const wchar_t* string, float& llx, float& lly, float& llz,
288 float& urx, float& ury, float& urz)
289 {
290 FTBBox b = BBox(string);
291 llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
292 urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
293 }
294
306 virtual float Advance(const char* string, const int len = -1,
307 FTPoint spacing = FTPoint());
308
320 virtual float Advance(const wchar_t* string, const int len = -1,
321 FTPoint spacing = FTPoint());
322
343 virtual FTPoint Render(const char* string, const int len = -1,
344 FTPoint position = FTPoint(),
345 FTPoint spacing = FTPoint(),
346 int renderMode = FTGL::RENDER_ALL);
347
368 virtual FTPoint Render(const wchar_t *string, const int len = -1,
369 FTPoint position = FTPoint(),
370 FTPoint spacing = FTPoint(),
371 int renderMode = FTGL::RENDER_ALL);
372
378 virtual FT_Error Error() const;
379
380 protected:
381 /* Allow impl to access MakeGlyph */
382 friend class FTFontImpl;
383
393 virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0;
394
395 private:
399 FTFontImpl *impl;
400};
401
402#endif //__cplusplus
403
404 FTGL_BEGIN_C_DECLS
405
413struct _FTGLFont;
414 typedef struct _FTGLfont FTGLfont;
415
424 FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath,
425 void *data,
426 FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
427
437 FTGL_EXPORT FTGLfont *ftglCreateCustomFontFromMem(const unsigned char *bytes,
438 size_t len, void *data,
439 FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
440
446 FTGL_EXPORT void ftglDestroyFont(FTGLfont* font);
447
457 FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path);
458
469 FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data,
470 size_t size);
471
480 FTGL_EXPORT void ftglSetFontGlyphLoadFlags(FTGLfont* font, FT_Int flags);
481
489 FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding);
490
497 FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font);
498
505 FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font);
506
516 FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size,
517 unsigned int res);
518
525 FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font);
526
534 FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth);
535
545 FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back);
546
554 FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList);
555
562 FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font);
563
570 FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font);
571
578 FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font);
579
590 FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
591 int len, float bounds[6]);
592
600 FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string);
601
609 FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode);
610
617 FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font);
618
619 FTGL_END_C_DECLS
620
621#endif // __FTFont__
622
ftglSetFontFaceSize
int ftglSetFontFaceSize(FTGLfont *font, unsigned int size, unsigned int res)
Set the char size for the current face.
ftglRenderFont
void ftglRenderFont(FTGLfont *font, const char *string, int mode)
Render a string of characters.
ftglGetFontAdvance
float ftglGetFontAdvance(FTGLfont *font, const char *string)
Get the advance width for a string.
ftglSetFontDisplayList
void ftglSetFontDisplayList(FTGLfont *font, int useList)
Enable or disable the use of Display Lists inside FTGL.
ftglGetFontCharMapCount
unsigned int ftglGetFontCharMapCount(FTGLfont *font)
Get the number of character maps in this face.
ftglGetFontDescender
float ftglGetFontDescender(FTGLfont *font)
Gets the global descender height for the face.
ftglCreateCustomFontFromMem
FTGLfont * ftglCreateCustomFontFromMem(const unsigned char *bytes, size_t len, void *data, FTGLglyph *(*makeglyphCallback)(FT_GlyphSlot, void *))
Create a custom FTGL font object from a buffer in memory.
ftglAttachFile
int ftglAttachFile(FTGLfont *font, const char *path)
Attach auxilliary file to font e.g.
ftglSetFontGlyphLoadFlags
void ftglSetFontGlyphLoadFlags(FTGLfont *font, FT_Int flags)
Set the glyph loading flags.
ftglGetFontAscender
float ftglGetFontAscender(FTGLfont *font)
Get the global ascender height for the face.
ftglGetFontError
FT_Error ftglGetFontError(FTGLfont *font)
Query a font for errors.
ftglGetFontFaceSize
unsigned int ftglGetFontFaceSize(FTGLfont *font)
Get the current face size in points (1/72 inch).
ftglSetFontCharMap
int ftglSetFontCharMap(FTGLfont *font, FT_Encoding encoding)
Set the character map for the face.
ftglSetFontDepth
void ftglSetFontDepth(FTGLfont *font, float depth)
Set the extrusion distance for the font.
ftglSetFontOutset
void ftglSetFontOutset(FTGLfont *font, float front, float back)
Set the outset distance for the font.
ftglGetFontCharMapList
FT_Encoding * ftglGetFontCharMapList(FTGLfont *font)
Get a list of character maps in this face.
ftglGetFontLineHeight
float ftglGetFontLineHeight(FTGLfont *font)
Gets the line spacing for the font.
ftglAttachData
int ftglAttachData(FTGLfont *font, const unsigned char *data, size_t size)
Attach auxilliary data to font, e.g.
ftglGetFontBBox
void ftglGetFontBBox(FTGLfont *font, const char *string, int len, float bounds[6])
Get the bounding box for a string.
ftglDestroyFont
void ftglDestroyFont(FTGLfont *font)
Destroy an FTGL font object.
FTGLfont
struct _FTGLfont FTGLfont
Definition FTFont.h:414
ftglCreateCustomFont
FTGLfont * ftglCreateCustomFont(char const *fontFilePath, void *data, FTGLglyph *(*makeglyphCallback)(FT_GlyphSlot, void *))
Create a custom FTGL font object.
FTGLglyph
struct _FTGLglyph FTGLglyph
Definition FTGlyph.h:134
FTBBox
FTBBox is a convenience class for handling bounding boxes.
Definition FTBBox.h:43
FTBBox::Lower
FTPoint const Lower() const
Definition FTBBox.h:165
FTBBox::Upper
FTPoint const Upper() const
Definition FTBBox.h:159
FTFont::Advance
virtual float Advance(const wchar_t *string, const int len=-1, FTPoint spacing=FTPoint())
Get the advance for a string.
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::FTExtrudeFont
friend class FTExtrudeFont
Definition FTFont.h:80
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.
FTFont::Descender
virtual float Descender() const
Gets the global descender height for the face.
FTFont::FTOutlineFont
friend class FTOutlineFont
Definition FTFont.h:81
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:252
FTFont::Outset
virtual void Outset(float front, float back)
Set the front and back outset distances for the font.
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.
FTFont::UseDisplayList
virtual void UseDisplayList(bool useList)
Enable or disable the use of Display Lists inside FTGL.
FTFont::CharMap
virtual bool CharMap(FT_Encoding encoding)
Set the character map for the face.
FTFont::Error
virtual FT_Error Error() const
Queries the Font for errors.
FTFont::FTTextureFont
friend class FTTextureFont
Definition FTFont.h:84
FTFont::FTFontImpl
friend class FTFontImpl
Definition FTFont.h:382
FTFont::FTBitmapFont
friend class FTBitmapFont
Definition FTFont.h:78
FTFont::CharMapCount
virtual unsigned int CharMapCount() const
Get the number of character maps in this face.
FTFont::Attach
virtual bool Attach(const char *fontFilePath)
Attach auxilliary file to font e.g font metrics.
FTFont::Depth
virtual void Depth(float depth)
Set the extrusion distance for the font.
FTFont::Ascender
virtual float Ascender() const
Get the global ascender height for the face.
FTFont::FaceSize
virtual unsigned int FaceSize() const
Get the current face size in points (1/72 inch).
FTFont::FTFont
FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
Open and read a font from a buffer in memory.
FTFont::Attach
virtual bool Attach(const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
Attach auxilliary data to font e.g font metrics, from memory.
FTFont::~FTFont
virtual ~FTFont()
FTFont::FaceSize
virtual bool FaceSize(const unsigned int size, const unsigned int res=72)
Set the char size for the current face.
FTFont::FTBufferFont
friend class FTBufferFont
Definition FTFont.h:79
FTFont::LineHeight
virtual float LineHeight() const
Gets the line spacing for the font.
FTFont::FTPolygonFont
friend class FTPolygonFont
Definition FTFont.h:83
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.
FTFont::FTPixmapFont
friend class FTPixmapFont
Definition FTFont.h:82
FTFont::FTTriangleExtractorFont
friend class FTTriangleExtractorFont
Definition FTFont.h:85
FTFont::MakeGlyph
virtual FTGlyph * MakeGlyph(FT_GlyphSlot slot)=0
Construct a glyph of the correct type.
FTFont::CharMapList
virtual FT_Encoding * CharMapList()
Get a list of character maps in this face.
FTFont::Advance
virtual float Advance(const char *string, const int len=-1, FTPoint spacing=FTPoint())
Get the advance for a string.
FTFont::GlyphLoadFlags
virtual void GlyphLoadFlags(FT_Int flags)
Set the glyph loading flags.
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:287
FTFont::FTFont
FTFont(char const *fontFilePath)
Open and read a font file.
FTFont::Outset
virtual void Outset(float outset)
Set the outset distance for the font.
FTGlyph
FTGlyph is the base class for FTGL glyphs.
Definition FTGlyph.h:51
FTPoint
FTPoint class is a basic 3-dimensional point or vector.
Definition FTPoint.h:43
FTPoint::Yf
FTGL_FLOAT Yf() const
Definition FTPoint.h:261
FTPoint::Xf
FTGL_FLOAT Xf() const
Definition FTPoint.h:260
FTPoint::FTPoint
FTPoint()
Default constructor.
Definition FTPoint.h:48
FTPoint::Zf
FTGL_FLOAT Zf() const
Definition FTPoint.h:262
ftgl.h
FTGL_BEGIN_C_DECLS
#define FTGL_BEGIN_C_DECLS
Definition ftgl.h:43
FTGL_END_C_DECLS
#define FTGL_END_C_DECLS
Definition ftgl.h:44
FTGL_EXPORT
#define FTGL_EXPORT
Definition ftgl.h:134
FTGL::RENDER_ALL
@ RENDER_ALL
Definition ftgl.h:58