]> Shamusworld >> Repos - ttedit/blob - src/glyphpoints.h
fc0dd2b40fd17d1d56909c8c39bff35c79aba19e
[ttedit] / src / glyphpoints.h
1 //
2 // glyphpoints.h
3 //
4 // by James L. Hammons
5 //
6 // This class encapsulates the data associated with a TrueType glyph.
7 // Data is dynamically allocated.
8 //
9
10 #ifndef __GLYPHPOINTS_H__
11 #define __GLYPHPOINTS_H__
12
13 #include "types.h"
14 #include <stdio.h>
15
16
17 // "IPoint" is an Integer based Point
18 struct IPoint
19 {
20         int32 x, y;
21         bool onCurve;
22
23         IPoint(int32 xx=0, int32 yy=0, bool oc=true): x(xx), y(yy), onCurve(oc) {}
24         bool operator==(const IPoint & p) { return (p.x == x && p.y == y ? true: false); };
25 };
26
27 // Throws the following exceptions:
28 #define GP_OUT_OF_RANGE  1
29
30 class GlyphPoints
31 {
32         public:
33 //For some reason, gcc barfs here when something tries to use the copy
34 //constructor because it gets confused between the optional arguments (which
35 //start with an INT for cryin' out loud) and the GlyphPoints & argument. So,
36 //Let's try making it a non-optional first param, and go from there...
37 //Turns out the compiler barfs regardless...
38 //Turns out the problem was that the copy ctor wasn't declared as CONST...
39                 GlyphPoints(int nPts = 0, int nPlys = 0, int * xa = NULL, int * ya = NULL,
40                         bool * oca = NULL, uint16 * pa = NULL);
41 //              GlyphPoints(void);// And now *this* is needed... Bleah!
42 //              GlyphPoints(int nPts, int nPlys = 0, int * xa = NULL, int * ya = NULL,
43 //                      bool * oca = NULL, uint16 * pa = NULL);
44                 GlyphPoints(int xx, int yy, bool oc);
45 //              GlyphPoints(GlyphPoints &);                             // Copy constructor
46                 GlyphPoints(const GlyphPoints &);                               // Copy constructor
47                 ~GlyphPoints();
48                 GlyphPoints& operator=(const GlyphPoints &);
49                 GlyphPoints operator+(const GlyphPoints &);
50                 GlyphPoints operator+(const IPoint &);
51                 GlyphPoints& operator+=(const IPoint &);
52                 void Clear(void);
53                 void InsertPoint(uint16, int, int, bool);
54                 void InsertPoint(uint16, const IPoint &);
55                 void DeletePoint(uint16);
56                 uint16 GetNumPoints(void);
57                 uint16 GetNumPoints(uint16 poly);
58                 uint16 GetNumPolys(void);
59                 int GetX(uint16);
60                 int GetY(uint16);
61                 bool GetOnCurve(uint16);
62                 int GetX(uint16, uint16);
63                 int GetNextX(uint16, uint16);
64                 int GetY(uint16, uint16);
65                 int GetNextY(uint16, uint16);
66                 IPoint GetPoint(uint16, uint16);
67                 IPoint GetPoint(uint16);
68                 bool GetOnCurve(uint16, uint16);
69                 bool GetPrevOnCurve(uint16, uint16);
70                 bool GetNextOnCurve(uint16, uint16);
71                 uint16 GetPolyStart(uint16);
72                 uint16 GetPolyEnd(uint16);
73                 void OffsetPoints(int, int);
74                 void OffsetPoly(uint16, int32, int32);
75                 void ScalePoints(float);
76                 void SetXY(uint16, int, int);
77                 void SetOnCurve(uint16, bool);
78                 uint16 GetPrev(uint16);
79                 uint16 GetNext(uint16);
80                 uint16 GetPrev(uint16, uint16);
81                 uint16 GetNext(uint16, uint16);
82                 uint16 GetPoly(uint16);
83                 void AddNewPolyAtEnd(void);
84                 IPoint GetMidpointToPrev(uint16, uint16);
85                 IPoint GetMidpointToNext(uint16, uint16);
86                 IPoint GetPrevPoint(uint16, uint16);
87                 IPoint GetNextPoint(uint16, uint16);
88                 uint16 GetPolyForPoint(IPoint point);
89                 uint16 GetPolyForPointNumber(uint16 pointNumber);
90
91                 IPoint RotatePoint(const double angle, const IPoint point, const IPoint center);
92                 void RotatePoints(const double angle, const IPoint point);
93                 IPoint GetPolyCentroid(const int16 poly);
94                 void RotatePolyAroundCentroid(const int16 poly, const double angle);
95
96                 bool LoadGlyphFromFile(FILE *);
97                 bool SaveGlyphToFile(FILE *);
98
99         private:
100                 void AllocateAndCopy(int, int, int *, int *, bool *, uint16 *);
101                 void FreeAllocatedMemory(void);
102
103         private:
104                 int numPoints, numPolys;
105                 int * x, * y;
106                 bool * onCurve;
107                 uint16 * polyEnd;
108                 uint16 pointsAllocated, polysAllocated;
109 };
110
111 #endif  // __GLYPHPOINTS_H__