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