Made the ftPoint struct an external class and added some helper functions eg operator != Got rid of ftLoop, it's not needed now that I've tidied up the curve parsing code (which fixed the Vivaldi Q bug) Minor code 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 0d41d9a..e80ada5 100644
--- a/include/FTVectoriser.h
+++ b/include/FTVectoriser.h
@@ -9,6 +9,64 @@
#include "FTGlyph.h"
+
+// template < typename T>
+// class ftLoop
+// {
+// public:
+// ftLoop();
+// ~ftLoop()
+// {
+// list.clear();
+// }
+//
+// T& operator [] (unsigned int i)
+// {
+// int x = i;
+// if( i < 0)
+// x = i + list.size();
+//
+// if( i > list.size())
+// x = i % list.size();
+//
+// return list[x];
+// }
+//
+// void push_back( T t)
+// {
+// list.push_back(t);
+// }
+//
+// private:
+// vector<T> list;
+// };
+
+
+class ftPoint
+{
+ public:
+ ftPoint()
+ : x(0), y(0), z(0){}
+
+ ftPoint( float X, float Y, float Z)
+ : x(X), y(Y), z(Z){}
+
+ friend bool operator == (const ftPoint &a, const ftPoint &b)
+ {
+ return((a.x == b.x) && (a.y == b.y) && (a.z == b.z));
+ }
+
+ friend bool operator != (const ftPoint &a, const ftPoint &b)
+ {
+ return((a.x != b.x) || (a.y != b.y) || (a.z != b.z));
+ }
+
+ float x, y, z;
+
+ private:
+};
+
+
class FTContour
{
public:
@@ -21,28 +79,15 @@ class FTContour
int size() const { return pointList.size();}
// attributes
-
-// typedef pair<int, int> ftPoint;
- struct ftPoint
- {
- float x, y, z;
- ftPoint()
- : x(0), y(0), z(0){}
-
- ftPoint( float X, float Y, float Z)
- : x(X), y(Y), z(Z){}
- };
-
vector< ftPoint> pointList;
float ctrlPtArray[4][2];
+
private:
// methods
// attributes
};
-//FIXME get rid of this
-#define MAX_DEG 4
class FTVectoriser
{
@@ -52,12 +97,13 @@ class FTVectoriser
virtual ~FTVectoriser();
bool Ingest();
- void Output( float* d);
+ void Output( double* d);
int points();
int contours() const { return contourList.size();}
int contourSize( int c) const { return contourList[c]->size();}
// attributes
+ int contourFlag;
private:
// methods
@@ -68,13 +114,14 @@ class FTVectoriser
// attributes
vector< FTContour*> contourList;
- float ctrlPtArray[4][2];
+ float ctrlPtArray[4][2]; // Magic numbers
FTContour* contour;
FT_Outline ftOutline;
- float bValues[MAX_DEG][MAX_DEG][2]; //3D array storing values
+ // Magic numbers -- #define MAX_DEG 4
+ float bValues[4][4][2]; //3D array storing values
//of de Casteljau algorithm.
diff --git a/src/FTVectoriser.cpp b/src/FTVectoriser.cpp
index 2e7e21a..6f20f1a 100644
--- a/src/FTVectoriser.cpp
+++ b/src/FTVectoriser.cpp
@@ -18,14 +18,13 @@ FTContour::~FTContour()
void FTContour::AddPoint( int x, int y)
{
- float fx, fy, fz;
+ ftPoint point( static_cast<float>( x), static_cast<float>( y), 0.0);
- fx = static_cast<float>( x);
- fy = static_cast<float>( y);
- fy = 0;
-
- pointList.push_back( ftPoint( fx, fy, fz));
-
+ // Eliminate duplicate points.
+ if( ( pointList[pointList.size() - 1] != point) || pointList[0] != point)
+ {
+ pointList.push_back( point);
+ }
}
@@ -112,7 +111,9 @@ bool FTVectoriser::Ingest()
{
contour = new FTContour;
- short last = ftOutline.contours[c];
+ contourFlag = ftOutline.flags;
+
+ short last = ftOutline.contours[c];
for( short p = first; p <= last; ++p)
{
@@ -142,53 +143,40 @@ bool FTVectoriser::Ingest()
int FTVectoriser::Conic( int index, int first, int last)
{
- if( ftOutline.tags[index + 1] != FT_Curve_Tag_Conic)
- {
- if( index != first)
- {
- ctrlPtArray[0][0] = ftOutline.points[index-1].x; ctrlPtArray[0][1] = ftOutline.points[index-1].y;
- }
- else
- {
- ctrlPtArray[0][0] = ftOutline.points[last].x; ctrlPtArray[0][1] = ftOutline.points[last].y;
- }
+ int next = index + 1;
+ int prev = index - 1;
+ if( index == last)
+ next = first;
+
+ if( index == first)
+ prev = last;
+
+ if( ftOutline.tags[next] != FT_Curve_Tag_Conic)
+ {
+ ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
+ ctrlPtArray[2][0] = ftOutline.points[next].x; ctrlPtArray[2][1] = ftOutline.points[next].y;
-// if( index != last)
-// {
-// ctrlPtArray[2][0] = ftOutline.points[index+1].x; ctrlPtArray[2][1] = ftOutline.points[index+1].y;
-// }
-// else
-// {
-// ctrlPtArray[2][0] = ftOutline.points[first].x; ctrlPtArray[2][1] = ftOutline.points[first].y;
-// }
evaluateCurve( 2);
return 1;
}
else
{
//create a phantom point
- float x = ( ftOutline.points[index].x + ftOutline.points[index+1].x) / 2;
- float y = ( ftOutline.points[index].y + ftOutline.points[index+1].y) / 2;
+ float x = ( ftOutline.points[index].x + ftOutline.points[next].x) / 2;
+ float y = ( ftOutline.points[index].y + ftOutline.points[next].y) / 2;
// process first curve
- if( index != first)
- {
- ctrlPtArray[0][0] = ftOutline.points[index-1].x; ctrlPtArray[0][1] = ftOutline.points[index-1].y;
- }
- else
- {
- ctrlPtArray[0][0] = ftOutline.points[last].x; ctrlPtArray[0][1] = ftOutline.points[last].y;
- }
-
+ ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
ctrlPtArray[2][0] = x; ctrlPtArray[2][1] = y;
+
evaluateCurve( 2);
// process second curve
ctrlPtArray[0][0] = x; ctrlPtArray[0][1] = y;
- ctrlPtArray[1][0] = ftOutline.points[index + 1].x; ctrlPtArray[1][1] = ftOutline.points[index + 1].y;
+ ctrlPtArray[1][0] = ftOutline.points[next].x; ctrlPtArray[1][1] = ftOutline.points[next].y;
if( index != last -1)
{
@@ -207,17 +195,18 @@ int FTVectoriser::Conic( int index, int first, int last)
int FTVectoriser::Cubic( int index, int first, int last)
{
- if( index != first)
- {
- ctrlPtArray[0][0] = ftOutline.points[index-1].x; ctrlPtArray[0][1] = ftOutline.points[index-1].y;
- }
- else
- {
- ctrlPtArray[0][0] = ftOutline.points[last].x; ctrlPtArray[0][1] = ftOutline.points[last].y;
- }
+ int next = index + 1;
+ int prev = index - 1;
+
+ if( index == last)
+ next = first;
+ if( index == first)
+ prev = last;
+
+ ctrlPtArray[0][0] = ftOutline.points[prev].x; ctrlPtArray[0][1] = ftOutline.points[prev].y;
ctrlPtArray[1][0] = ftOutline.points[index].x; ctrlPtArray[1][1] = ftOutline.points[index].y;
- ctrlPtArray[2][0] = ftOutline.points[index + 1].x; ctrlPtArray[2][1] = ftOutline.points[index + 1].y;
+ ctrlPtArray[2][0] = ftOutline.points[next].x; ctrlPtArray[2][1] = ftOutline.points[next].y;
if( index != last -1)
{
ctrlPtArray[3][0] = ftOutline.points[index+2].x; ctrlPtArray[3][1] = ftOutline.points[index+2].y;
@@ -231,7 +220,7 @@ int FTVectoriser::Cubic( int index, int first, int last)
}
-void FTVectoriser::Output( float* data)
+void FTVectoriser::Output( double* data)
{
int i = 0;
@@ -241,9 +230,9 @@ void FTVectoriser::Output( float* data)
for( int p = 0; p < contour->size(); ++p)
{
- data[i] = contour->pointList[p].x / 64.0f; // is 64 correct?
- data[i + 1] = contour->pointList[p].y / 64.0f;
- data[i + 2] = contour->pointList[p].z / 64.0f;
+ data[i] = static_cast<double>(contour->pointList[p].x / 64.0f); // is 64 correct?
+ data[i + 1] = static_cast<double>(contour->pointList[p].y / 64.0f);
+ data[i + 2] = static_cast<double>(contour->pointList[p].z / 64.0f);
i += 3;
}
}