FTVectoriser.h

Go to the documentation of this file.
00001 #ifndef     __FTVectoriser__
00002 #define     __FTVectoriser__
00003 
00004 
00005 #include "FTContour.h"
00006 #include "FTList.h"
00007 #include "FTPoint.h"
00008 #include "FTVector.h"
00009 #include "FTGL.h"
00010 
00011 
00012 #ifndef CALLBACK
00013 #define CALLBACK
00014 #endif
00015 
00016 
00017 /**
00018  * FTTesselation captures points that are output by OpenGL's gluTesselator.
00019  */
00020 class FTGL_EXPORT FTTesselation
00021 {
00022     public:
00023         /**
00024          * Default constructor
00025          */
00026         FTTesselation( GLenum m)
00027         :       meshType(m)
00028         {
00029             pointList.reserve( 128);
00030         }
00031 
00032         /**
00033          *  Destructor
00034          */
00035         ~FTTesselation()
00036         {
00037             pointList.clear();
00038         }
00039 
00040         /**
00041          * Add a point to the mesh.
00042          */
00043         void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z)
00044         {   
00045             pointList.push_back( FTPoint( x, y, z));
00046         }
00047 
00048         /**
00049          * The number of points in this mesh
00050          */
00051         size_t PointCount() const { return pointList.size();}
00052         
00053         /**
00054          *
00055          */
00056         const FTPoint& Point( unsigned int index) const { return pointList[index];}
00057         
00058         /**
00059          * Return the OpenGL polygon type.
00060          */
00061         GLenum PolygonType() const { return meshType;}
00062         
00063     private:
00064         /**
00065          * Points generated by gluTesselator.
00066          */
00067         typedef FTVector<FTPoint> PointVector;
00068         PointVector pointList;
00069 
00070         /**
00071          * OpenGL primitive type from gluTesselator.
00072          */
00073         GLenum meshType;
00074 };
00075 
00076 
00077 /**
00078  * FTMesh is a container of FTTesselation's that make up a polygon glyph
00079  */
00080 class FTGL_EXPORT FTMesh
00081 {
00082         typedef FTVector<FTTesselation*> TesselationVector;
00083         typedef FTList<FTPoint> PointList;
00084 
00085     public:
00086         /**
00087          * Default constructor
00088          */
00089         FTMesh();
00090 
00091         /**
00092          *  Destructor
00093          */
00094         ~FTMesh();
00095         
00096         /**
00097          * Add a point to the mesh
00098          */
00099         void AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
00100         
00101         /**
00102          *  Create a combine point for the gluTesselator
00103          */
00104         const FTGL_DOUBLE* Combine( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUBLE z);
00105         
00106         /**
00107          * Begin a new polygon
00108          */
00109         void Begin( GLenum meshType);
00110         
00111         /**
00112          * End a polygon
00113          */
00114         void End();
00115         
00116         /**
00117          * Record a gluTesselation error
00118          */
00119         void Error( GLenum e) { err = e;}
00120         
00121         /**
00122          * The number of tesselations in the mesh
00123          */
00124         unsigned int TesselationCount() const { return tesselationList.size();}
00125 
00126         /**
00127          * Get a tesselation by index
00128          */
00129         const FTTesselation* Tesselation( unsigned int index) const;
00130         
00131         /**
00132          * Return the temporary point list. For testing only.
00133          */
00134         const PointList& TempPointList() const { return tempPointList;}
00135 
00136         /**
00137          * Get the GL ERROR returned by the glu tesselator
00138          */
00139         GLenum Error() const { return err;}
00140 
00141     private:
00142         /**
00143          * The current sub mesh that we are constructing.
00144          */
00145         FTTesselation* currentTesselation;
00146         
00147         /**
00148          * Holds each sub mesh that comprises this glyph.
00149          */
00150         TesselationVector tesselationList;
00151         
00152         /**
00153          * Holds extra points created by gluTesselator. See ftglCombine.
00154          */
00155         PointList tempPointList;
00156         
00157         /**
00158          * GL ERROR returned by the glu tesselator
00159          */
00160         GLenum err;
00161 
00162 };
00163 
00164 const FTGL_DOUBLE FTGL_FRONT_FACING = 1.0;
00165 const FTGL_DOUBLE FTGL_BACK_FACING = -1.0;
00166 
00167 /**
00168  * FTVectoriser class is a helper class that converts font outlines into
00169  * point data.
00170  *
00171  * @see FTExtrdGlyph
00172  * @see FTOutlineGlyph
00173  * @see FTPolyGlyph
00174  * @see FTContour
00175  * @see FTPoint
00176  *
00177  */
00178 class FTGL_EXPORT FTVectoriser
00179 {
00180     public:
00181         /**
00182          * Constructor
00183          *
00184          * @param glyph The freetype glyph to be processed
00185          */
00186         FTVectoriser( const FT_GlyphSlot glyph);
00187 
00188         /**
00189          *  Destructor
00190          */
00191         virtual ~FTVectoriser();
00192 
00193         /**
00194          * Build an FTMesh from the vector outline data. 
00195          *
00196          * @param zNormal   The direction of the z axis of the normal
00197          *                  for this mesh
00198          */
00199         void MakeMesh( FTGL_DOUBLE zNormal = FTGL_FRONT_FACING);
00200         
00201         /**
00202          * Get the current mesh.
00203          */
00204         const FTMesh* GetMesh() const { return mesh;}
00205         
00206         /**
00207          * Get the total count of points in this outline
00208          *
00209          * @return the number of points
00210          */
00211         size_t PointCount();
00212 
00213         /**
00214          * Get the count of contours in this outline
00215          *
00216          * @return the number of contours
00217          */
00218         size_t ContourCount() const { return ftContourCount;}
00219 
00220         /**
00221          * Return a contour at index
00222          *
00223          * @return the number of contours
00224          */
00225          const FTContour* Contour( unsigned int index) const;
00226 
00227         /**
00228          * Get the number of points in a specific contour in this outline
00229          *
00230          * @param c     The contour index
00231          * @return      the number of points in contour[c]
00232          */
00233         size_t ContourSize( int c) const { return contourList[c]->PointCount();}
00234 
00235         /**
00236          * Get the flag for the tesselation rule for this outline
00237          *
00238          * @return The contour flag
00239          */
00240         int ContourFlag() const { return contourFlag;}
00241         
00242     private:
00243         /**
00244          * Process the freetype outline data into contours of points
00245          */
00246         void ProcessContours();
00247 
00248         /**
00249          * The list of contours in the glyph
00250          */
00251         FTContour** contourList;
00252 
00253         /**
00254          * A Mesh for tesselations
00255          */
00256         FTMesh* mesh;
00257         
00258         /**
00259          * The number of contours reported by Freetype
00260          */
00261         short ftContourCount;
00262 
00263         /**
00264          * A flag indicating the tesselation rule for the glyph
00265          */
00266         int contourFlag;
00267 
00268         /**
00269          * A Freetype outline
00270          */
00271         FT_Outline outline;
00272 };
00273 
00274 
00275 #endif  //  __FTVectoriser__

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