Commit 1fc9d48877666eaa03a50b4a750422682e050e50

henry 2002-12-17T03:53:37

Refactored to get rid of data memory buffers and function name tidy ups

diff --git a/include/FTVectoriser.h b/include/FTVectoriser.h
index 5a5025d..e5ca95c 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -1,9 +1,6 @@
 #ifndef     __FTVectoriser__
 #define     __FTVectoriser__
 
-#include <ft2build.h>
-#include FT_FREETYPE_H
-#include FT_GLYPH_H
 
 #include "FTContour.h"
 #include "FTPoint.h"
@@ -16,7 +13,6 @@
 #endif
 
 
-
 /**
  * FTTesselation captures points that are output by OpenGL's gluTesselator.
  */
@@ -46,21 +42,25 @@ class FTGL_EXPORT FTTesselation
         }
 
 
-        size_t size() const { return pointList.size();}
+        size_t PointCount() const { return pointList.size();}
+        
+        const FTPoint& Point( unsigned int index) const { return pointList[index];}
 
-        /**
-         * OpenGL primitive type from gluTesselator.
-         */
-        GLenum meshType;
+        void PolygonType( GLenum m) { meshType = m;}
         
+        GLenum PolygonType() const { return meshType;}
+        
+    private:
         /**
          * Points generated by gluTesselator.
          */
         typedef FTVector<FTPoint> PointVector;
         PointVector pointList;
-        
-    private:
-        
+
+        /**
+         * OpenGL primitive type from gluTesselator.
+         */
+        GLenum meshType;
 };
 
 
@@ -85,8 +85,10 @@ class FTGL_EXPORT FTMesh
         void End();
         void Error( GLenum e) { err = e;}
         
-        int size() const;
-        
+        unsigned int TesselationCount() const { return tesselationList.size();}
+
+        FTTesselation* Tesselation( unsigned int index) const { return tesselationList[index];}
+
         /**
          * Get the GL ERROR returned by the glu tesselator
          */
@@ -98,12 +100,6 @@ class FTGL_EXPORT FTMesh
         typedef FTVector<FTPoint> PointVector;
         PointVector tempPointList;
         
-        /**
-         * Holds each sub mesh that comprises this glyph.
-         */
-        typedef FTVector<FTTesselation*> TesselationVector;
-        TesselationVector tesselationList;
-        
     protected:
     
     private:
@@ -113,6 +109,12 @@ class FTGL_EXPORT FTMesh
         FTTesselation* currentTesselation;
         
         /**
+         * Holds each sub mesh that comprises this glyph.
+         */
+        typedef FTVector<FTTesselation*> TesselationVector;
+        TesselationVector tesselationList;
+        
+        /**
          * GL ERROR returned by the glu tesselator
          */
         GLenum err;
@@ -156,31 +158,23 @@ class FTGL_EXPORT FTVectoriser
         void MakeMesh( FTGL_DOUBLE zNormal = 1.0);
         
         /**
-         * Copy the tesselation data into a block of <code>FTGL_DOUBLEs</code>
-         *
-         * @param d a pointer to the memory to copy the data into.
+         * Get the current mesh.
          */
-        void GetMesh( FTGL_DOUBLE* d);
-        
-        /** Get the number of points in the tesselation
-         *
-         * @return the number of points.
-         */
-        size_t MeshPoints() const { return mesh->size();}
+        FTMesh* GetMesh() const { return mesh;}
         
         /**
          * Get the total count of points in this outline
          *
          * @return the number of points
          */
-        int points();
+        size_t PointCount();
 
         /**
          * Get the count of contours in this outline
          *
          * @return the number of contours
          */
-        size_t contours() const { return ftContourCount;}
+        size_t ContourCount() const { return ftContourCount;}
 
         /**
          * Get the count of contours in this outline
@@ -195,7 +189,7 @@ class FTGL_EXPORT FTVectoriser
          * @param c     The contour index
          * @return      the number of points in contour[c]
          */
-        size_t contourSize( int c) const { return contourList[c]->Points();}
+        size_t ContourSize( int c) const { return contourList[c]->PointCount();}
 
         /**
          * Get the flag for the tesselation rule for this outline
@@ -221,7 +215,7 @@ class FTGL_EXPORT FTVectoriser
         FTMesh* mesh;
         
         /**
-         *
+         * The number of contours reported by Freetype
          */
         short ftContourCount;
 
@@ -234,17 +228,6 @@ class FTGL_EXPORT FTVectoriser
          * A Freetype outline
          */
         FT_Outline ftOutline;
-        
-        /**
-         */
-         // Magic numbers -- #define MAX_DEG 4
-        float bValues[4][4][2];  //3D array storing values of de Casteljau algorithm.
-        float ctrlPtArray[4][2]; // Magic numbers
-        
-        /**
-         */
-        const float kBSTEPSIZE;
-
 };
 
 
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 48a6234..e7ce135 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -46,6 +46,7 @@ void CALLBACK ftglCombine( FTGL_DOUBLE coords[3], void* vertex_data[4], GLfloat 
     FTGL_DOUBLE* vertex = (FTGL_DOUBLE*)coords;
     mesh->tempPointList.push_back( FTPoint( vertex[0], vertex[1], vertex[2]));
     
+    // FIXME if tempPointList reallocs we'll loose these. replace it with a list.
     *outData = &mesh->tempPointList[ mesh->tempPointList.size() - 1].x;
 }
         
@@ -78,7 +79,7 @@ void FTMesh::AddPoint( const FTGL_DOUBLE x, const FTGL_DOUBLE y, const FTGL_DOUB
 void FTMesh::Begin( GLenum m)
 {
     currentTesselation = new FTTesselation;
-    currentTesselation->meshType = m;
+    currentTesselation->PolygonType( m);
 }
 
 
@@ -88,25 +89,11 @@ void FTMesh::End()
 }
 
 
-int FTMesh::size() const
-{
-    int s = 0;
-    for( size_t t = 0; t < tesselationList.size(); ++t)
-    {
-        s += tesselationList[t]->size();
-// FIXME What the hell is this for? Data in FTPolyglyph
-        ++s;
-    }
-    return s;
-}
-
-
 FTVectoriser::FTVectoriser( const FT_Glyph glyph)
 :   contourList(0),
     mesh(0),
     ftContourCount(0),
-    contourFlag(0),
-    kBSTEPSIZE( 0.2f)
+    contourFlag(0)
 {
     if( glyph)
     {
@@ -124,7 +111,7 @@ FTVectoriser::FTVectoriser( const FT_Glyph glyph)
 
 FTVectoriser::~FTVectoriser()
 {
-    for( size_t c = 0; c < contours(); ++c)
+    for( size_t c = 0; c < ContourCount(); ++c)
     {
         delete contourList[c];
     }
@@ -160,12 +147,12 @@ void FTVectoriser::ProcessContours()
 }
 
 
-int FTVectoriser::points()
+size_t FTVectoriser::PointCount()
 {
     int s = 0;
-    for( size_t c = 0; c < contours(); ++c)
+    for( size_t c = 0; c < ContourCount(); ++c)
     {
-        s += contourList[c]->Points();
+        s += contourList[c]->PointCount();
     }
     
     return s;
@@ -203,13 +190,13 @@ void FTVectoriser::MakeMesh( FTGL_DOUBLE zNormal)
     gluTessNormal( tobj, 0.0f, 0.0f, zNormal);
     gluTessBeginPolygon( tobj, mesh);
     
-        for( size_t c = 0; c < contours(); ++c)
+        for( size_t c = 0; c < ContourCount(); ++c)
         {
             const FTContour* contour = contourList[c];
 
             gluTessBeginContour( tobj);
             
-                for( size_t p = 0; p < contour->Points(); ++p)
+                for( size_t p = 0; p < contour->PointCount(); ++p)
                 {
                     FTGL_DOUBLE* d = const_cast<FTGL_DOUBLE*>(&contour->Point(p).x);
                     gluTessVertex( tobj, d, d);
@@ -223,31 +210,3 @@ void FTVectoriser::MakeMesh( FTGL_DOUBLE zNormal)
     gluDeleteTess( tobj);
 }
 
-
-void FTVectoriser::GetMesh( FTGL_DOUBLE* data)
-{
-    // fill out the header
-    size_t msize = mesh->tesselationList.size();
-    data[0] = msize;
-    
-    int i = 0;
-    for( int p = 0; p < data[0]; ++p)
-    {
-        FTTesselation* tesselation = mesh->tesselationList[p];
-        size_t tesselationSize =  tesselation->pointList.size();
-        int tesselationType =  tesselation->meshType;
-        
-        data[i+1] = tesselationType;
-        data[i+2] = tesselationSize;
-
-        i += 3;
-        for( size_t q = 0; q < ( tesselation->pointList.size()); ++q)
-        {
-            data[i] = tesselation->pointList[q].x / 64.0f;
-            data[i + 1] = tesselation->pointList[q].y / 64.0f;
-            data[i + 2] = 0.0f;
-            i += 3;
-        }
-    }
-}
-