X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fglyphpoints.cpp;h=d0402f6fe041ddc800a29b03db00a24c53d9439f;hb=29b571499a38273c6c693334512e44f4162171a5;hp=a2b80aa499fa4098cedcaa7f2add13d378ee7a00;hpb=6d13a5166688e470590692eb91c3915ab332fe36;p=ttedit diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index a2b80aa..d0402f6 100755 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -1,581 +1,581 @@ -// -// GLYPHPOINTS.CPP -// -// Class implementation. Nothing too inexplicable going on here. Fairly -// straightforward stuff. -// -// by James L. Hammons -// (C) 2004 Underground Software -// -// JLH = James L. Hammons -// -// Who When What -// --- ---------- ------------------------------------------------------------ -// JLH ??/??/200? Created this file -// JLH 05/18/2004 Added pure point adding, inserting, better polygon handling -// - -// Uncomment this for debugging... -#define DEBUG - -#include "glyphpoints.h" -#ifdef DEBUG -#include "debug.h" -#endif - -/*GlyphPoints::GlyphPoints(void) -{ - GlyphPoints(0, 0, NULL, NULL, NULL, NULL); -}*/ - -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) -//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) -{ - AllocateAndCopy(nPts, nPlys, xa, ya, oca, pa); - - if (nPlys == 0) - { - numPolys = 1; - polyEnd = new uint16[numPolys]; - polyEnd[0] = numPoints - 1; - } -#ifdef DEBUG -WriteLogMsg("GlyphPoints: Default constructor. %u points, %u polys.\n", numPoints, numPolys); -#endif -} - -GlyphPoints::GlyphPoints(int xx, int yy, bool oc) -{ -//Hmm. What to do with this...? - AllocateAndCopy(1, 0, &xx, &yy, &oc, NULL); -#ifdef DEBUG -WriteLogMsg("GlyphPoints: Single point constructor. %u points, %u polys.\n", numPoints, numPolys); -#endif -} - -// Copy constructor (needed for deep copying) - -//GlyphPoints::GlyphPoints(GlyphPoints &c): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) -GlyphPoints::GlyphPoints(const GlyphPoints &c): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) -{ - *this = c; // Use overloaded operator= -#ifdef DEBUG -WriteLogMsg("GlyphPoints: Copy constructor. %u points, %u polys.\n", numPoints, numPolys); -#endif -} - -GlyphPoints::~GlyphPoints() -{ - if (x) - delete[] x; - - if (y) - delete[] y; - - if (onCurve) - delete[] onCurve; - - if (polyEnd) - delete[] polyEnd; -} - -void GlyphPoints::AllocateAndCopy(int nPts, int nPlys, int * xa, int * ya, bool * oca, uint16 * pa) -{ - numPoints = nPts, numPolys = nPlys; - - if (nPts) - { - x = new int[numPoints]; - y = new int[numPoints]; - onCurve = new bool[numPoints]; - - if (xa) // Copy points in if they're passed in... - for(int i=0; i numPoints) // > because we can insert at end...! - throw GP_OUT_OF_RANGE; - -//This is kinda silly. We can do better than this! !!! FIX !!! - int * totX = new int[numPoints + 1]; - int * totY = new int[numPoints + 1]; - bool * totOnCurve = new bool[numPoints + 1]; - - for(int i=0; i 0) - { - numPolys--; - - for(int i=poly; i= numPolys) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetNumPoints(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return polyEnd[poly] - (poly == 0 ? -1 : polyEnd[poly - 1]); -} - -uint16 GlyphPoints::GetNumPolys(void) -{ - return numPolys; -} - -int GlyphPoints::GetX(uint16 pt) -{ - if (pt >= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetX(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return x[pt]; -} - -int GlyphPoints::GetY(uint16 pt) -{ - if (pt >= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetY(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return y[pt]; -} - -bool GlyphPoints::GetOnCurve(uint16 pt) -{ - if (pt >= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetOnCurve(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return onCurve[pt]; -} - -int GlyphPoints::GetX(uint16 poly, uint16 pt) -{ - if (pt >= GetNumPoints(poly)) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetX(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return x[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; -} - -int GlyphPoints::GetY(uint16 poly, uint16 pt) -{ - if (pt >= GetNumPoints(poly)) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetY(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return y[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; -} - -bool GlyphPoints::GetOnCurve(uint16 poly, uint16 pt) -{ - if (pt >= GetNumPoints(poly)) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetOnCurve(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return onCurve[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; -} - -uint16 GlyphPoints::GetPolyEnd(uint16 poly) -{ - if (poly >= numPolys) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - return polyEnd[poly]; -} - -void GlyphPoints::OffsetPoints(int xOff, int yOff) -{ - for(int i=0; i= numPolys) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetPolyEnd(uint16). 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); - - for(int i=0; i= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: SetXY(uint16, int, int). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - x[pt] = xx, y[pt] = yy; -} - -void GlyphPoints::SetOnCurve(uint16 pt, bool oc) -{ - if (pt >= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - onCurve[pt] = oc; -} - -uint16 GlyphPoints::GetPrev(uint16 pt) -{ -// pt = 7, polyEnd = 4, 9, 15 - uint16 min = 0, max = numPoints - 1; - - for(int i=0; i 0) - min = polyEnd[i - 1] + 1; - - max = polyEnd[i]; - break; - } - } - - uint16 retVal = pt - 1; - - if (pt == min) - retVal = max; - - return retVal; -} - -uint16 GlyphPoints::GetNext(uint16 pt) -{ - uint16 min = 0, max = numPoints - 1; - - for(int i=0; i 0) - min = polyEnd[i - 1] + 1; - - max = polyEnd[i]; - break; - } - } - - uint16 retVal = pt + 1; - - if (pt == max) - retVal = min; - - return retVal; -} - -// -// Get previous point for this polygon using wraparound. -// Note that pt is a zero-based index! -// -uint16 GlyphPoints::GetPrev(uint16 poly, uint16 pt) -{ - return (pt == 0 ? GetNumPoints(poly) - 1 : pt - 1); -} - -// -// Get next point for this polygon using wraparound. -// Note that pt is a zero-based index! -// -uint16 GlyphPoints::GetNext(uint16 poly, uint16 pt) -{ - return (pt == GetNumPoints(poly) - 1 ? 0 : pt + 1); -} - -uint16 GlyphPoints::GetPoly(uint16 pt) -{ - if (pt >= numPoints) -#ifdef DEBUG -{ -WriteLogMsg("Exception: GetPoly(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); -#endif - throw GP_OUT_OF_RANGE; -#ifdef DEBUG -} -#endif - - for(int i=0; i +// +// Who When What +// --- ---------- ------------------------------------------------------------ +// JLH ??/??/200? Created this file +// JLH 05/18/2004 Added pure point adding, inserting, better polygon handling +// + +// Uncomment this for debugging... +#define DEBUG + +#include "glyphpoints.h" +#ifdef DEBUG +#include "debug.h" +#endif + +/*GlyphPoints::GlyphPoints(void) +{ + GlyphPoints(0, 0, NULL, NULL, NULL, NULL); +}*/ + +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) +//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) +{ + AllocateAndCopy(nPts, nPlys, xa, ya, oca, pa); + + if (nPlys == 0) + { + numPolys = 1; + polyEnd = new uint16[numPolys]; + polyEnd[0] = numPoints - 1; + } +#ifdef DEBUG +WriteLogMsg("GlyphPoints: Default constructor. %u points, %u polys.\n", numPoints, numPolys); +#endif +} + +GlyphPoints::GlyphPoints(int xx, int yy, bool oc) +{ +//Hmm. What to do with this...? + AllocateAndCopy(1, 0, &xx, &yy, &oc, NULL); +#ifdef DEBUG +WriteLogMsg("GlyphPoints: Single point constructor. %u points, %u polys.\n", numPoints, numPolys); +#endif +} + +// Copy constructor (needed for deep copying) + +//GlyphPoints::GlyphPoints(GlyphPoints &c): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) +GlyphPoints::GlyphPoints(const GlyphPoints &c): x(NULL), y(NULL), onCurve(NULL), polyEnd(NULL) +{ + *this = c; // Use overloaded operator= +#ifdef DEBUG +WriteLogMsg("GlyphPoints: Copy constructor. %u points, %u polys.\n", numPoints, numPolys); +#endif +} + +GlyphPoints::~GlyphPoints() +{ + if (x) + delete[] x; + + if (y) + delete[] y; + + if (onCurve) + delete[] onCurve; + + if (polyEnd) + delete[] polyEnd; +} + +void GlyphPoints::AllocateAndCopy(int nPts, int nPlys, int * xa, int * ya, bool * oca, uint16 * pa) +{ + numPoints = nPts, numPolys = nPlys; + + if (nPts) + { + x = new int[numPoints]; + y = new int[numPoints]; + onCurve = new bool[numPoints]; + + if (xa) // Copy points in if they're passed in... + for(int i=0; i numPoints) // > because we can insert at end...! + throw GP_OUT_OF_RANGE; + +//This is kinda silly. We can do better than this! !!! FIX !!! + int * totX = new int[numPoints + 1]; + int * totY = new int[numPoints + 1]; + bool * totOnCurve = new bool[numPoints + 1]; + + for(int i=0; i 0) + { + numPolys--; + + for(int i=poly; i= numPolys) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetNumPoints(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return polyEnd[poly] - (poly == 0 ? -1 : polyEnd[poly - 1]); +} + +uint16 GlyphPoints::GetNumPolys(void) +{ + return numPolys; +} + +int GlyphPoints::GetX(uint16 pt) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetX(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return x[pt]; +} + +int GlyphPoints::GetY(uint16 pt) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetY(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return y[pt]; +} + +bool GlyphPoints::GetOnCurve(uint16 pt) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetOnCurve(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return onCurve[pt]; +} + +int GlyphPoints::GetX(uint16 poly, uint16 pt) +{ + if (pt >= GetNumPoints(poly)) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetX(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return x[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; +} + +int GlyphPoints::GetY(uint16 poly, uint16 pt) +{ + if (pt >= GetNumPoints(poly)) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetY(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return y[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; +} + +bool GlyphPoints::GetOnCurve(uint16 poly, uint16 pt) +{ + if (pt >= GetNumPoints(poly)) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetOnCurve(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\xA", poly, pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return onCurve[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; +} + +uint16 GlyphPoints::GetPolyEnd(uint16 poly) +{ + if (poly >= numPolys) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetPolyEnd(uint16). poly=%u, numPolys=%u\xD\xA", poly, numPolys); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + return polyEnd[poly]; +} + +void GlyphPoints::OffsetPoints(int xOff, int yOff) +{ + for(int i=0; i= numPolys) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetPolyEnd(uint16). 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); + + for(int i=0; i= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: SetXY(uint16, int, int). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + x[pt] = xx, y[pt] = yy; +} + +void GlyphPoints::SetOnCurve(uint16 pt, bool oc) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + onCurve[pt] = oc; +} + +uint16 GlyphPoints::GetPrev(uint16 pt) +{ +// pt = 7, polyEnd = 4, 9, 15 + uint16 min = 0, max = numPoints - 1; + + for(int i=0; i 0) + min = polyEnd[i - 1] + 1; + + max = polyEnd[i]; + break; + } + } + + uint16 retVal = pt - 1; + + if (pt == min) + retVal = max; + + return retVal; +} + +uint16 GlyphPoints::GetNext(uint16 pt) +{ + uint16 min = 0, max = numPoints - 1; + + for(int i=0; i 0) + min = polyEnd[i - 1] + 1; + + max = polyEnd[i]; + break; + } + } + + uint16 retVal = pt + 1; + + if (pt == max) + retVal = min; + + return retVal; +} + +// +// Get previous point for this polygon using wraparound. +// Note that pt is a zero-based index! +// +uint16 GlyphPoints::GetPrev(uint16 poly, uint16 pt) +{ + return (pt == 0 ? GetNumPoints(poly) - 1 : pt - 1); +} + +// +// Get next point for this polygon using wraparound. +// Note that pt is a zero-based index! +// +uint16 GlyphPoints::GetNext(uint16 poly, uint16 pt) +{ + return (pt == GetNumPoints(poly) - 1 ? 0 : pt + 1); +} + +uint16 GlyphPoints::GetPoly(uint16 pt) +{ + if (pt >= numPoints) +#ifdef DEBUG +{ +WriteLogMsg("Exception: GetPoly(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints); +#endif + throw GP_OUT_OF_RANGE; +#ifdef DEBUG +} +#endif + + for(int i=0; i