X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fglyphpoints.h;h=5602cbe82a87f43b06a468bacd9fa2b8599058f8;hb=1881acb17ed405cdb5aa2cb333a7af77f644a86d;hp=2348d1e48f28f08aa398ba60fa78451de5495de4;hpb=6d13a5166688e470590692eb91c3915ab332fe36;p=ttedit diff --git a/src/glyphpoints.h b/src/glyphpoints.h old mode 100755 new mode 100644 index 2348d1e..5602cbe --- a/src/glyphpoints.h +++ b/src/glyphpoints.h @@ -1,85 +1,123 @@ -// -// glyphpoints.h -// -// by James L. Hammons -// -// This class encapsulates the data associated with a TrueType glyph. -// Data is dynamically allocated. -// - -#ifndef __GLYPHPOINTS_H__ -#define __GLYPHPOINTS_H__ - -#include "types.h" - - -struct IPoint -{ - int32 x, y; - bool onCurve; - - IPoint(int32 xx=0, int32 yy=0, bool oc=true): x(xx), y(yy), onCurve(oc) {} -}; - -// Throws the following exceptions: -#define GP_OUT_OF_RANGE 1 - -class GlyphPoints -{ - public: -//For some reason, gcc barfs here when something tries to use the copy -//constructor because it gets confused between the optional arguments (which -//start with an INT for cryin' out loud) and the GlyphPoints & argument. So, -//Let's try making it a non-optional first param, and go from there... -//Turns out the compiler barfs regardless... -//Turns out the problem was that the copy ctor wasn't declared as CONST... - GlyphPoints(int nPts = 0, int nPlys = 0, int * xa = NULL, int * ya = NULL, - bool * oca = NULL, uint16 * pa = NULL); -// GlyphPoints(void);// And now *this* is needed... Bleah! -// GlyphPoints(int nPts, int nPlys = 0, int * xa = NULL, int * ya = NULL, -// bool * oca = NULL, uint16 * pa = NULL); - GlyphPoints(int xx, int yy, bool oc); -// GlyphPoints(GlyphPoints &); // Copy constructor - GlyphPoints(const GlyphPoints &); // Copy constructor - ~GlyphPoints(); - GlyphPoints& operator=(const GlyphPoints &); - GlyphPoints operator+(const GlyphPoints &); - GlyphPoints operator+(const IPoint &); - GlyphPoints& operator+=(const IPoint &); - void InsertPoint(uint16, int, int, bool); - void InsertPoint(uint16, const IPoint &); - void DeletePoint(uint16); - uint16 GetNumPoints(void); - uint16 GetNumPoints(uint16); - uint16 GetNumPolys(void); - int GetX(uint16); - int GetY(uint16); - bool GetOnCurve(uint16); - int GetX(uint16, uint16); - int GetY(uint16, uint16); - bool GetOnCurve(uint16, uint16); - uint16 GetPolyEnd(uint16); - void OffsetPoints(int, int); - void OffsetPoly(uint16, int32, int32); - void ScalePoints(float); - void SetXY(uint16, int, int); - void SetOnCurve(uint16, bool); - uint16 GetPrev(uint16); - uint16 GetNext(uint16); - uint16 GetPrev(uint16, uint16); - uint16 GetNext(uint16, uint16); - uint16 GetPoly(uint16); - void AddNewPolyAtEnd(void); - - private: - void AllocateAndCopy(int, int, int *, int *, bool *, uint16 *); - - private: - int numPoints, numPolys; - int * x, * y; - bool * onCurve; - uint16 * polyEnd; - uint16 pointsAllocated, polysAllocated; -}; - -#endif // __GLYPHPOINTS_H__ +// +// glyphpoints.h +// +// by James L. Hammons +// +// This class encapsulates the data associated with a TrueType glyph. +// Data is dynamically allocated. +// + +#ifndef __GLYPHPOINTS_H__ +#define __GLYPHPOINTS_H__ + +#include +#include +#include "vector.h" + + +// "IPoint" is an Integer based Point +struct IPoint +{ + int32_t x, y; + bool onCurve; + + IPoint(int32_t xx=0, int32_t yy=0, bool oc=true): x(xx), y(yy), onCurve(oc) {} + bool operator==(const IPoint & p) { return (p.x == x && p.y == y ? true: false); }; +}; + + +struct GuideLine +{ + int32_t x, y; + double angle; +}; + + +// Throws the following exceptions: +#define GP_OUT_OF_RANGE 1 + +class GlyphPoints +{ + public: +//For some reason, gcc barfs here when something tries to use the copy +//constructor because it gets confused between the optional arguments (which +//start with an INT for cryin' out loud) and the GlyphPoints & argument. So, +//Let's try making it a non-optional first param, and go from there... +//Turns out the compiler barfs regardless... +//Turns out the problem was that the copy ctor wasn't declared as CONST... + GlyphPoints(int nPts = 0, int nPlys = 0, int * xa = NULL, int * ya = NULL, + bool * oca = NULL, uint16_t * pa = NULL); +// GlyphPoints(void);// And now *this* is needed... Bleah! +// GlyphPoints(int nPts, int nPlys = 0, int * xa = NULL, int * ya = NULL, +// bool * oca = NULL, uint16_t * pa = NULL); + GlyphPoints(int xx, int yy, bool oc); +// GlyphPoints(GlyphPoints &); // Copy constructor + GlyphPoints(const GlyphPoints &); // Copy constructor + ~GlyphPoints(); + GlyphPoints& operator=(const GlyphPoints &); + GlyphPoints operator+(const GlyphPoints &); + GlyphPoints operator+(const IPoint &); + GlyphPoints& operator+=(const IPoint &); + void Clear(void); + void InsertPoint(uint16_t, int, int, bool); + void InsertPoint(uint16_t, const IPoint &); + void DeletePoint(uint16_t); + uint16_t GetNumPoints(void); + uint16_t GetNumPoints(uint16_t poly); + uint16_t GetNumPolys(void); + int GetX(uint16_t); + int GetY(uint16_t); + Vector GetXY(uint16_t); + bool GetOnCurve(uint16_t); + int GetX(uint16_t, uint16_t); + int GetNextX(uint16_t, uint16_t); + int GetY(uint16_t, uint16_t); + int GetNextY(uint16_t, uint16_t); + IPoint GetPoint(uint16_t, uint16_t); + IPoint GetPoint(uint16_t); + bool GetOnCurve(uint16_t, uint16_t); + bool GetPrevOnCurve(uint16_t, uint16_t); + bool GetNextOnCurve(uint16_t, uint16_t); + uint16_t GetPolyStart(uint16_t); + uint16_t GetPolyEnd(uint16_t); + void OffsetPoints(int, int); + void OffsetPoly(uint16_t, int32_t, int32_t); + void ScalePoints(float); + void SetXY(uint16_t, int, int); + void SetOnCurve(uint16_t, bool); + void SetPoint(const uint16_t pointNum, const IPoint point); + uint16_t GetPrev(uint16_t); + uint16_t GetNext(uint16_t); + uint16_t GetPrev(uint16_t, uint16_t); + uint16_t GetNext(uint16_t, uint16_t); + uint16_t GetPoly(uint16_t); + void AddNewPolyAtEnd(void); + IPoint GetMidpointToPrev(uint16_t, uint16_t); + IPoint GetMidpointToNext(uint16_t, uint16_t); + IPoint GetPrevPoint(uint16_t, uint16_t); + IPoint GetNextPoint(uint16_t, uint16_t); + uint16_t GetPolyForPoint(IPoint point); + uint16_t GetPolyForPointNumber(uint16_t pointNumber); + + IPoint RotatePoint(const double angle, const IPoint point, const IPoint center); + void RotatePoints(const double angle, const IPoint point); + IPoint GetPolyCentroid(const int16_t poly); + void RotatePolyAroundCentroid(const int16_t poly, const double angle); + void InvertPolyDrawSequence(const uint16_t poly); + + bool LoadGlyphFromFile(FILE *); + bool SaveGlyphToFile(FILE *); + + private: + void AllocateAndCopy(int, int, int *, int *, bool *, uint16_t *); + void FreeAllocatedMemory(void); + + private: + int numPoints, numPolys; + int * x, * y; + bool * onCurve; + uint16_t * polyEnd; + uint16_t pointsAllocated, polysAllocated; +}; + +#endif // __GLYPHPOINTS_H__