Refactored to get rid of data memory buffers and function name tidy ups
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
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;
- }
- }
-}
-