FTFace.h

Go to the documentation of this file.
00001 #ifndef     __FTFace__
00002 #define     __FTFace__
00003 
00004 #include <ft2build.h>
00005 #include FT_FREETYPE_H
00006 #include FT_GLYPH_H
00007 
00008 #include "FTGL.h"
00009 #include "FTPoint.h"
00010 #include "FTSize.h"
00011 
00012 /**
00013  * FTFace class provides an abstraction layer for the Freetype Face.
00014  *
00015  * @see "Freetype 2 Documentation"
00016  *
00017  */
00018 class FTGL_EXPORT FTFace
00019 {
00020     public:
00021         /**
00022          * Opens and reads a face file. Error is set.
00023          *
00024          * @param fontFilePath  font file path.
00025          */
00026         FTFace( const char* fontFilePath);
00027 
00028         /**
00029          * Read face data from an in-memory buffer. Error is set.
00030          *
00031          * @param pBufferBytes  the in-memory buffer
00032          * @param bufferSizeInBytes  the length of the buffer in bytes
00033          */
00034         FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes );
00035 
00036         /**
00037          * Destructor
00038          *
00039          * Disposes of the current Freetype Face.
00040          */
00041         virtual ~FTFace();
00042 
00043         /**
00044          * Attach auxilliary file to font (e.g., font metrics).
00045          *
00046          * @param fontFilePath  auxilliary font file path.
00047          * @return          <code>true</code> if file has opened
00048          *                  successfully.
00049          */
00050         bool Attach( const char* fontFilePath);
00051 
00052         /**
00053          * Attach auxilliary data to font (e.g., font metrics) from memory
00054          *
00055          * @param pBufferBytes  the in-memory buffer
00056          * @param bufferSizeInBytes  the length of the buffer in bytes
00057          * @return          <code>true</code> if file has opened
00058          *                  successfully.
00059          */
00060         bool Attach( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
00061 
00062         /**
00063          * Get the freetype face object..
00064          *
00065          * @return pointer to an FT_Face.
00066          */
00067         FT_Face* Face() const { return ftFace;}
00068         
00069         /**
00070          * Sets the char size for the current face.
00071          *
00072          * This doesn't guarantee that the size was set correctly. Clients
00073          * should check errors.
00074          *
00075          * @param size      the face size in points (1/72 inch)
00076          * @param res       the resolution of the target device.
00077          * @return          <code>FTSize</code> object
00078          */
00079         const FTSize& Size( const unsigned int size, const unsigned int res);
00080 
00081         /**
00082          * Get the number of character maps in this face.
00083          *
00084          * @return character map count.
00085          */
00086         unsigned int CharMapCount();
00087 
00088         /**
00089          * Get a list of character maps in this face.
00090          *
00091          * @return pointer to the first encoding.
00092          */
00093         FT_Encoding* CharMapList();
00094         
00095         /**
00096          * Gets the kerning vector between two glyphs
00097          */
00098         FTPoint KernAdvance( unsigned int index1, unsigned int index2);
00099 
00100         /**
00101          * Loads and creates a Freetype glyph.
00102          */
00103         FT_GlyphSlot Glyph( unsigned int index, FT_Int load_flags);
00104 
00105         /**
00106          * Gets the number of glyphs in the current face.
00107          */
00108         unsigned int GlyphCount() const { return numGlyphs;}
00109 
00110         /**
00111          * Queries for errors.
00112          *
00113          * @return  The current error code.
00114          */
00115         FT_Error Error() const { return err; }
00116         
00117     private:
00118         /**
00119          * The Freetype face
00120          */
00121         FT_Face* ftFace;
00122 
00123         /**
00124          * The size object associated with this face
00125          */
00126         FTSize  charSize;
00127         
00128         /**
00129          * The number of glyphs in this face
00130          */
00131         int numGlyphs;
00132         
00133         FT_Encoding* fontEncodingList;
00134 
00135         /**
00136          * This face has kerning tables
00137          */
00138          bool hasKerningTable;
00139 
00140         /**
00141          * Current error code. Zero means no error.
00142          */
00143         FT_Error err;
00144 };
00145 
00146 
00147 #endif  //  __FTFace__

Generated on Tue Jul 5 14:16:15 2011 for ROOT_528-00b_version by  doxygen 1.5.1