FTGL  2.2.0
FTFont.h
Go to the documentation of this file.
00001 /*
00002  * FTGL - OpenGL font library
00003  *
00004  * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
00005  * Copyright (c) 2008 Sam Hocevar <sam@hocevar.net>
00006  * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining
00009  * a copy of this software and associated documentation files (the
00010  * "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to
00013  * permit persons to whom the Software is furnished to do so, subject to
00014  * the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be
00017  * included in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00020  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00021  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00022  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00023  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00024  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00025  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00026  */
00027 
00028 #ifndef __ftgl__
00029 #   warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
00030 #   include <FTGL/ftgl.h>
00031 #endif
00032 
00033 #ifndef __FTFont__
00034 #define __FTFont__
00035 
00036 #ifdef __cplusplus
00037 
00038 class FTFontImpl;
00039 
00056 class FTGL_EXPORT FTFont
00057 {
00058     protected:
00064         FTFont(char const *fontFilePath);
00065 
00074         FTFont(const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
00075 
00076     private:
00077         /* Allow our internal subclasses to access the private constructor */
00078         friend class FTBitmapFont;
00079         friend class FTBufferFont;
00080         friend class FTExtrudeFont;
00081         friend class FTOutlineFont;
00082         friend class FTPixmapFont;
00083         friend class FTPolygonFont;
00084         friend class FTTextureFont;
00085 
00092         FTFont(FTFontImpl *pImpl);
00093 
00094     public:
00095         virtual ~FTFont();
00096 
00106         virtual bool Attach(const char* fontFilePath);
00107 
00118         virtual bool Attach(const unsigned char *pBufferBytes,
00119                             size_t bufferSizeInBytes);
00120 
00128         virtual void GlyphLoadFlags(FT_Int flags);
00129 
00137         virtual bool CharMap(FT_Encoding encoding);
00138 
00144         virtual unsigned int CharMapCount() const;
00145 
00151         virtual FT_Encoding* CharMapList();
00152 
00160         virtual bool FaceSize(const unsigned int size,
00161                               const unsigned int res = 72);
00162 
00168         virtual unsigned int FaceSize() const;
00169 
00176         virtual void Depth(float depth);
00177 
00184         virtual void Outset(float outset);
00185 
00193         virtual void Outset(float front, float back);
00194 
00201         virtual void UseDisplayList(bool useList);
00202 
00208         virtual float Ascender() const;
00209 
00215         virtual float Descender() const;
00216 
00222         virtual float LineHeight() const;
00223 
00236         virtual FTBBox BBox(const char *string, const int len = -1,
00237                             FTPoint position = FTPoint(),
00238                             FTPoint spacing = FTPoint());
00239 
00251         void BBox(const char* string, float& llx, float& lly, float& llz,
00252                   float& urx, float& ury, float& urz)
00253         {
00254             FTBBox b = BBox(string);
00255             llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
00256             urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
00257         }
00258 
00271         virtual FTBBox BBox(const wchar_t *string, const int len = -1,
00272                             FTPoint position = FTPoint(),
00273                             FTPoint spacing = FTPoint());
00274 
00286         void BBox(const wchar_t* string, float& llx, float& lly, float& llz,
00287                   float& urx, float& ury, float& urz)
00288         {
00289             FTBBox b = BBox(string);
00290             llx = b.Lower().Xf(); lly = b.Lower().Yf(); llz = b.Lower().Zf();
00291             urx = b.Upper().Xf(); ury = b.Upper().Yf(); urz = b.Upper().Zf();
00292         }
00293 
00305         virtual float Advance(const char* string, const int len = -1,
00306                               FTPoint spacing = FTPoint());
00307 
00319         virtual float Advance(const wchar_t* string, const int len = -1,
00320                               FTPoint spacing = FTPoint());
00321 
00342         virtual FTPoint Render(const char* string, const int len = -1,
00343                                FTPoint position = FTPoint(),
00344                                FTPoint spacing = FTPoint(),
00345                                int renderMode = FTGL::RENDER_ALL);
00346 
00367         virtual FTPoint Render(const wchar_t *string, const int len = -1,
00368                                FTPoint position = FTPoint(),
00369                                FTPoint spacing = FTPoint(),
00370                                int renderMode = FTGL::RENDER_ALL);
00371 
00377         virtual FT_Error Error() const;
00378 
00379     protected:
00380         /* Allow impl to access MakeGlyph */
00381         friend class FTFontImpl;
00382 
00392         virtual FTGlyph* MakeGlyph(FT_GlyphSlot slot) = 0;
00393 
00394     private:
00398         FTFontImpl *impl;
00399 };
00400 
00401 #endif //__cplusplus
00402 
00403 FTGL_BEGIN_C_DECLS
00404 
00412 struct _FTGLFont;
00413 typedef struct _FTGLfont FTGLfont;
00414 
00423 FTGL_EXPORT FTGLfont *ftglCreateCustomFont(char const *fontFilePath,
00424                                            void *data,
00425                    FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
00426 
00436 FTGL_EXPORT FTGLfont *ftglCreateCustomFontFromMem(const unsigned char *bytes,
00437                                                   size_t len, void *data,
00438                    FTGLglyph * (*makeglyphCallback) (FT_GlyphSlot, void *));
00439 
00445 FTGL_EXPORT void ftglDestroyFont(FTGLfont* font);
00446 
00456 FTGL_EXPORT int ftglAttachFile(FTGLfont* font, const char* path);
00457 
00468 FTGL_EXPORT int ftglAttachData(FTGLfont* font, const unsigned char * data,
00469                                size_t size);
00470 
00479 FTGL_EXPORT void ftglSetFontGlyphLoadFlags(FTGLfont* font, FT_Int flags);
00480 
00488 FTGL_EXPORT int ftglSetFontCharMap(FTGLfont* font, FT_Encoding encoding);
00489 
00496 FTGL_EXPORT unsigned int ftglGetFontCharMapCount(FTGLfont* font);
00497 
00504 FTGL_EXPORT FT_Encoding* ftglGetFontCharMapList(FTGLfont* font);
00505 
00515 FTGL_EXPORT int ftglSetFontFaceSize(FTGLfont* font, unsigned int size,
00516                                     unsigned int res);
00517 
00524 FTGL_EXPORT unsigned int ftglGetFontFaceSize(FTGLfont* font);
00525 
00533 FTGL_EXPORT void ftglSetFontDepth(FTGLfont* font, float depth);
00534 
00544 FTGL_EXPORT void ftglSetFontOutset(FTGLfont* font, float front, float back);
00545 
00553 FTGL_EXPORT void ftglSetFontDisplayList(FTGLfont* font, int useList);
00554 
00561 FTGL_EXPORT float ftglGetFontAscender(FTGLfont* font);
00562 
00569 FTGL_EXPORT float ftglGetFontDescender(FTGLfont* font);
00570 
00577 FTGL_EXPORT float ftglGetFontLineHeight(FTGLfont* font);
00578 
00589 FTGL_EXPORT void ftglGetFontBBox(FTGLfont* font, const char *string,
00590                                  int len, float bounds[6]);
00591 
00599 FTGL_EXPORT float ftglGetFontAdvance(FTGLfont* font, const char *string);
00600 
00608 FTGL_EXPORT void ftglRenderFont(FTGLfont* font, const char *string, int mode);
00609 
00616 FTGL_EXPORT FT_Error ftglGetFontError(FTGLfont* font);
00617 
00618 FTGL_END_C_DECLS
00619 
00620 #endif  //  __FTFont__
00621