X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fglyphpoints.cpp;h=025f0e1ef3fde7be1c709ee943ada7084d23e7d9;hb=c7d608c4fcdd370274964cc861b674c2fae69468;hp=05edc828d791d44bba987e683b0ed935f1c1b858;hpb=360d040a4727383cc8e78d0b8a3c8151c27d26fc;p=ttedit diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp old mode 100755 new mode 100644 index 05edc82..025f0e1 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -10,7 +10,7 @@ // JLH = James L. Hammons // // Who When What -// --- ---------- ------------------------------------------------------------ +// --- ---------- ----------------------------------------------------------- // JLH ??/??/200? Created this file // JLH 05/18/2004 Added pure point adding, inserting, better polygon handling // @@ -31,16 +31,16 @@ }*/ GlyphPoints::GlyphPoints(int nPts/*=0*/, int nPlys/*=0*/, int * xa/*=null*/, int * ya/*=null*/, - bool * oca/*=null*/, uint16 * pa/*=null*/): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) + bool * oca/*=null*/, uint16_t * pa/*=null*/): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) //GlyphPoints::GlyphPoints(int nPts, int nPlys/*=0*/, int * xa/*=null*/, int * ya/*=null*/, -// bool * oca/*=null*/, uint16 * pa/*=null*/): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) +// bool * oca/*=null*/, uint16_t * pa/*=null*/): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) { AllocateAndCopy(nPts, nPlys, xa, ya, oca, pa); if (nPlys == 0) { numPolys = 1; - polyEnd = new uint16[numPolys]; + polyEnd = new uint16_t[numPolys]; polyEnd[0] = numPoints - 1; } #ifdef DEBUG @@ -74,23 +74,10 @@ WriteLogMsg("GlyphPoints: Copy constructor. %u points, %u polys.\n", numPoints, GlyphPoints::~GlyphPoints() { FreeAllocatedMemory(); -#if 0 - if (x) - delete[] x; - - if (y) - delete[] y; - - if (onCurve) - delete[] onCurve; - - if (polyEnd) - delete[] polyEnd; -#endif } -void GlyphPoints::AllocateAndCopy(int nPts, int nPlys, int * xa, int * ya, bool * oca, uint16 * pa) +void GlyphPoints::AllocateAndCopy(int nPts, int nPlys, int * xa, int * ya, bool * oca, uint16_t * pa) { numPoints = nPts, numPolys = nPlys; @@ -115,7 +102,7 @@ void GlyphPoints::AllocateAndCopy(int nPts, int nPlys, int * xa, int * ya, bool if (numPolys) { - polyEnd = new uint16[numPolys]; + polyEnd = new uint16_t[numPolys]; if (pa) // Copy poly ends in if they're passed in... for(int i=0; i numPoints) // > because we can insert at end...! throw GP_OUT_OF_RANGE; @@ -263,7 +255,6 @@ void GlyphPoints::InsertPoint(uint16 pt, int xx, int yy, bool oc) //we're adding to the end of the structure: [DONE, below] int polyInsert = (pt == numPoints ? numPolys - 1 : GetPoly(pt)); for(int i=polyInsert; i= numPolys) #ifdef DEBUG { -WriteLogMsg("Exception: GetNumPoints(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +WriteLogMsg("Exception: GetNumPoints(uint16_t). poly=%u, numPolys=%u\xD\xA", poly, numPolys); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -337,18 +328,18 @@ WriteLogMsg("Exception: GetNumPoints(uint16). poly=%u, numPolys=%u\xD\xA", poly, } -uint16 GlyphPoints::GetNumPolys(void) +uint16_t GlyphPoints::GetNumPolys(void) { return numPolys; } -int GlyphPoints::GetX(uint16 pt) +int GlyphPoints::GetX(uint16_t pt) { if (pt >= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: GetX(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: GetX(uint16_t). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -359,12 +350,12 @@ WriteLogMsg("Exception: GetX(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints) } -int GlyphPoints::GetY(uint16 pt) +int GlyphPoints::GetY(uint16_t pt) { if (pt >= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: GetY(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: GetY(uint16_t). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -375,12 +366,28 @@ WriteLogMsg("Exception: GetY(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints) } -bool GlyphPoints::GetOnCurve(uint16 pt) +Vector GlyphPoints::GetXY(uint16_t pt) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetXY(uint16_t). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return Vector(x[pt], y[pt]); +} + + +bool GlyphPoints::GetOnCurve(uint16_t pt) { if (pt >= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: GetOnCurve(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: GetOnCurve(uint16_t). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -391,12 +398,12 @@ WriteLogMsg("Exception: GetOnCurve(uint16). pt=%u, numPoints=%u\xD\xA", pt, numP } -int GlyphPoints::GetX(uint16 poly, uint16 pt) +int GlyphPoints::GetX(uint16_t poly, uint16_t pt) { if (pt >= GetNumPoints(poly)) #ifdef DEBUG { -WriteLogMsg("Exception: GetX(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +WriteLogMsg("Exception: GetX(uint16_t, uint16_t). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -407,18 +414,18 @@ WriteLogMsg("Exception: GetX(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\x } -int GlyphPoints::GetNextX(uint16 poly, uint16 pt) +int GlyphPoints::GetNextX(uint16_t poly, uint16_t pt) { return GetX(poly, GetNext(poly, pt)); } -int GlyphPoints::GetY(uint16 poly, uint16 pt) +int GlyphPoints::GetY(uint16_t poly, uint16_t pt) { if (pt >= GetNumPoints(poly)) #ifdef DEBUG { -WriteLogMsg("Exception: GetY(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +WriteLogMsg("Exception: GetY(uint16_t, uint16_t). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -429,33 +436,33 @@ WriteLogMsg("Exception: GetY(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\x } -int GlyphPoints::GetNextY(uint16 poly, uint16 pt) +int GlyphPoints::GetNextY(uint16_t poly, uint16_t pt) { return GetY(poly, GetNext(poly, pt)); } -IPoint GlyphPoints::GetPoint(uint16 poly, uint16 pt) +IPoint GlyphPoints::GetPoint(uint16_t poly, uint16_t pt) { - return IPoint(GetX(poly, pt), GetY(poly, pt)); + return IPoint(GetX(poly, pt), GetY(poly, pt), GetOnCurve(poly, pt)); } -IPoint GlyphPoints::GetPoint(uint16 pointNumber) +IPoint GlyphPoints::GetPoint(uint16_t pointNumber) { if (pointNumber > numPoints) throw GP_OUT_OF_RANGE; - return IPoint(x[pointNumber], y[pointNumber]); + return IPoint(x[pointNumber], y[pointNumber], onCurve[pointNumber]); } -bool GlyphPoints::GetOnCurve(uint16 poly, uint16 pt) +bool GlyphPoints::GetOnCurve(uint16_t poly, uint16_t pt) { if (pt >= GetNumPoints(poly)) #ifdef DEBUG { -WriteLogMsg("Exception: GetOnCurve(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +WriteLogMsg("Exception: GetOnCurve(uint16_t, uint16_t). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -466,24 +473,24 @@ WriteLogMsg("Exception: GetOnCurve(uint16, uint16). poly= %u, pt=%u, numPoints=% } -bool GlyphPoints::GetPrevOnCurve(uint16 poly, uint16 pt) +bool GlyphPoints::GetPrevOnCurve(uint16_t poly, uint16_t pt) { return GetOnCurve(poly, GetPrev(poly, pt)); } -bool GlyphPoints::GetNextOnCurve(uint16 poly, uint16 pt) +bool GlyphPoints::GetNextOnCurve(uint16_t poly, uint16_t pt) { return GetOnCurve(poly, GetNext(poly, pt)); } -uint16 GlyphPoints::GetPolyStart(uint16 poly) +uint16_t GlyphPoints::GetPolyStart(uint16_t poly) { if (poly >= numPolys) #ifdef DEBUG { -WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +WriteLogMsg("Exception: GetPolyEnd(uint16_t). poly=%u, numPolys=%u\xD\xA", poly, numPolys); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -495,12 +502,12 @@ WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, n } -uint16 GlyphPoints::GetPolyEnd(uint16 poly) +uint16_t GlyphPoints::GetPolyEnd(uint16_t poly) { if (poly >= numPolys) #ifdef DEBUG { -WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +WriteLogMsg("Exception: GetPolyEnd(uint16_t). poly=%u, numPolys=%u\xD\xA", poly, numPolys); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -521,19 +528,19 @@ void GlyphPoints::OffsetPoints(int xOff, int yOff) // // Offset only a specific polygon in the glyph // -void GlyphPoints::OffsetPoly(uint16 poly, int32 xOff, int32 yOff) +void GlyphPoints::OffsetPoly(uint16_t poly, int32_t xOff, int32_t yOff) { if (poly >= numPolys) #ifdef DEBUG { -WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +WriteLogMsg("Exception: GetPolyEnd(uint16_t). poly=%u, numPolys=%u\xD\xA", poly, numPolys); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG } #endif - uint16 polyStart = (poly == 0 ? 0 : polyEnd[poly - 1] + 1); + uint16_t polyStart = (poly == 0 ? 0 : polyEnd[poly - 1] + 1); for(int i=0; i= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: SetXY(uint16, int, int). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: SetXY(uint16_t, int, int). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -564,12 +571,12 @@ WriteLogMsg("Exception: SetXY(uint16, int, int). pt=%u, numPoints=%u\xD\xA", pt, } -void GlyphPoints::SetOnCurve(uint16 pt, bool oc) +void GlyphPoints::SetOnCurve(uint16_t pt, bool oc) { if (pt >= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: SetOnCurve(uint16_t, bool). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -580,10 +587,26 @@ WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt } -uint16 GlyphPoints::GetPrev(uint16 pt) +void GlyphPoints::SetPoint(const uint16_t pointNum, const IPoint point) +{ + if (pointNum >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: SetPoint(uint16_t, IPoint). pt=%u, numPoints=%u\xD\xA", pointNum, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + x[pointNum] = point.x, y[pointNum] = point.y, onCurve[pointNum] = point.onCurve; +} + + +uint16_t GlyphPoints::GetPrev(uint16_t pt) { // pt = 7, polyEnd = 4, 9, 15 - uint16 min = 0, max = numPoints - 1; + uint16_t min = 0, max = numPoints - 1; for(int i=0; i= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: GetPoly(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +WriteLogMsg("Exception: GetPoly(uint16_t). pt=%u, numPoints=%u\xD\xA", pt, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -668,7 +691,7 @@ WriteLogMsg("Exception: GetPoly(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoin if (pt <= polyEnd[i]) return i; - return (uint16)-1; + return (uint16_t)-1; } @@ -677,9 +700,9 @@ void GlyphPoints::AddNewPolyAtEnd(void) if (numPoints == 0) // By default, we already *have* a poly return; - uint16 * newPolyEnd = new uint16[numPolys + 1]; + uint16_t * newPolyEnd = new uint16_t[numPolys + 1]; - for(uint16 i=0; i polyEnd[poly]) poly++; @@ -744,14 +767,14 @@ uint16 GlyphPoints::GetPolyForPoint(IPoint point) } -uint16 GlyphPoints::GetPolyForPointNumber(uint16 pointNumber) +uint16_t GlyphPoints::GetPolyForPointNumber(uint16_t pointNumber) { // If there's only one poly, we know where the point is... if (numPolys <= 1) return 0; // Otherwise, do a linear search through the polys to find the right one - for(uint16 i=0; i= GetPolyStart(i) && pointNumber <= polyEnd[i]) return i; @@ -804,17 +827,19 @@ void GlyphPoints::RotatePoints(const double angle, const IPoint pt) } -IPoint GlyphPoints::GetPolyCentroid(const int16 poly) +IPoint GlyphPoints::GetPolyCentroid(const int16_t poly) { // We should throw an exception here, but meh // (this actually short circuits the exception handling in all the GetPolyXXX() functions) + // [now we do!] if (poly >= numPolys) - return IPoint(0, 0); + throw GP_OUT_OF_RANGE; +// return IPoint(0, 0); // if (poly >= numPolys) //#ifdef DEBUG //{ -//WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +//WriteLogMsg("Exception: GetPolyEnd(uint16_t). poly=%u, numPolys=%u\xD\xA", poly, numPolys); //#endif // throw GP_OUT_OF_RANGE; //#ifdef DEBUG @@ -822,9 +847,9 @@ IPoint GlyphPoints::GetPolyCentroid(const int16 poly) //#endif IPoint centroid; // Initializes to (0, 0) - uint16 numPointsInPoly = GetNumPoints(poly); + uint16_t numPointsInPoly = GetNumPoints(poly); - for(uint16 i=GetPolyStart(poly); i<=GetPolyEnd(poly); i++) + for(uint16_t i=GetPolyStart(poly); i<=GetPolyEnd(poly); i++) { centroid.x += x[i]; centroid.y += y[i]; @@ -837,14 +862,14 @@ IPoint GlyphPoints::GetPolyCentroid(const int16 poly) } -void GlyphPoints::RotatePolyAroundCentroid(const int16 poly, const double angle) +void GlyphPoints::RotatePolyAroundCentroid(const int16_t poly, const double angle) { if (poly >= numPolys) return; IPoint centroid = GetPolyCentroid(poly); - for(uint16 i=GetPolyStart(poly); i<=GetPolyEnd(poly); i++) + for(uint16_t i=GetPolyStart(poly); i<=GetPolyEnd(poly); i++) { IPoint rotated = RotatePoint(angle, IPoint(x[i], y[i]), centroid); x[i] = rotated.x; @@ -853,6 +878,27 @@ void GlyphPoints::RotatePolyAroundCentroid(const int16 poly, const double angle) } +void GlyphPoints::InvertPolyDrawSequence(const uint16_t poly) +{ + if (poly >= numPolys) + throw GP_OUT_OF_RANGE; + + uint16_t pointNum1 = GetPolyStart(poly); + uint16_t pointNum2 = GetPolyEnd(poly); + + // Algorithm: Step through points in the polygon, swapping 1st and last, then + // 2nd and (last - 1), 3rd and (last - 2), etc. We only do this for half the + // points, as doing it for all would undo the swapping we did in the 1st half. + for(uint16_t i=0; i