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