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
#ifndef __FTVectoriser__
#define __FTVectoriser__
#include <vector>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
#include "FTGlyph.h"
using namespace std;
// 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( const float X, const float Y, const 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:
// methods
FTContour();
~FTContour();
void AddPoint( const int x, const int y);
int size() const { return pointList.size();}
// attributes
vector< ftPoint> pointList;
float ctrlPtArray[4][2];
private:
// methods
// attributes
};
class FTVectoriser
{
public:
// methods
FTVectoriser( FT_Glyph glyph);
virtual ~FTVectoriser();
bool Ingest();
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
int Conic( const int index, const int first, const int last);
int Cubic( const int index, const int first, const int last);
void deCasteljau( const float t, const int n);
void evaluateCurve( const int n);
// attributes
vector< const FTContour*> contourList;
FTContour* contour;
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
};
#endif // __FTVectoriser__