From: Shamus Hammons Date: Fri, 19 Feb 2016 02:27:54 +0000 (-0600) Subject: Add ability to move points with the arrow keys. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=ttedit;a=commitdiff_plain;h=0c01fa32c7e0629ae61992e0419f03724fc18487 Add ability to move points with the arrow keys. --- diff --git a/src/editwindow.cpp b/src/editwindow.cpp index 429943d..9d0f5d8 100755 --- a/src/editwindow.cpp +++ b/src/editwindow.cpp @@ -212,7 +212,7 @@ void EditWindow::paintEvent(QPaintEvent * /*event*/) rotated.RotatePoints(rotationAngle, IPoint(rotationCenter.x(), rotationCenter.y())); else if (tool == TOOLRotatePoly) { - uint16 poly = rotated.GetPolyForPointNumber(ptHighlight); + uint16_t poly = rotated.GetPolyForPointNumber(ptHighlight); rotated.RotatePolyAroundCentroid(poly, rotationAngle); } @@ -226,6 +226,7 @@ void EditWindow::DrawGlyph(QPainter & p, GlyphPoints & glyph) { for(int poly=0; polykey() == Qt::Key_Up) + { + pts.SetXY(ptHighlight, pts.GetX(ptHighlight), pts.GetY(ptHighlight) + 1); + } + else if (event->key() == Qt::Key_Down) + pts.SetXY(ptHighlight, pts.GetX(ptHighlight), pts.GetY(ptHighlight) - 1); + else if (event->key() == Qt::Key_Right) + pts.SetXY(ptHighlight, pts.GetX(ptHighlight) + 1, pts.GetY(ptHighlight)); + else if (event->key() == Qt::Key_Left) + pts.SetXY(ptHighlight, pts.GetX(ptHighlight) - 1, pts.GetY(ptHighlight)); + else + return; + + event->accept(); + update(); + ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&pts); + ((TTEdit *)qApp)->charWnd->update(); } -void EditWindow::keyReleaseEvent(QKeyEvent * event) +void EditWindow::keyReleaseEvent(QKeyEvent * /*event*/) { } diff --git a/src/editwindow.h b/src/editwindow.h index 8821da4..6525359 100755 --- a/src/editwindow.h +++ b/src/editwindow.h @@ -9,7 +9,7 @@ #define __EDITWINDOW_H__ #include -#include "types.h" +#include #include "toolwindow.h" // For ToolType enum #include "glyphpoints.h" @@ -23,29 +23,29 @@ class EditWindow: public QWidget QSize sizeHint() const; protected: - void paintEvent(QPaintEvent * event); - void mousePressEvent(QMouseEvent * event); - void mouseMoveEvent(QMouseEvent * event); - void mouseReleaseEvent(QMouseEvent * event); + void paintEvent(QPaintEvent *); + void mousePressEvent(QMouseEvent *); + void mouseMoveEvent(QMouseEvent *); + void mouseReleaseEvent(QMouseEvent *); void keyPressEvent(QKeyEvent *); void keyReleaseEvent(QKeyEvent *); private: void CreateCursors(void); - QPoint GetAdjustedMousePosition(QMouseEvent * event); + QPoint GetAdjustedMousePosition(QMouseEvent *); QPoint GetAdjustedClientPosition(int x, int y); void DrawGlyph(QPainter & p, GlyphPoints & glyph); - void DrawGlyphPoly(QPainter & p, GlyphPoints & glyph, uint16 poly); + void DrawGlyphPoly(QPainter & p, GlyphPoints & glyph, uint16_t poly); public: QImage image; QPoint pt, ptOffset, ptPrevious; double scale; // Window scaling factor - int32 offsetX, offsetY; // Window offsets + int32_t offsetX, offsetY; // Window offsets ToolType tool; // Current tool GlyphPoints pts; // Glyph point structure - int32 ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight; - int16 polyHighlight, oldPolyHighlight; + int32_t ptHighlight, oldPtHighlight, ptNextHighlight, oldPtNextHighlight; + int16_t polyHighlight, oldPolyHighlight; bool polyFirstPoint; bool showRotationCenter, haveZeroPoint; QPoint rotationCenter, rotationZeroPoint, rotationCurrentPoint; diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index 2e80e38..0b05752 100755 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -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 @@ -90,7 +90,7 @@ GlyphPoints::~GlyphPoints() } -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 +115,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; @@ -280,7 +280,7 @@ void GlyphPoints::InsertPoint(uint16 pt, int xx, int yy, bool oc) } -void GlyphPoints::InsertPoint(uint16 pt, const IPoint &p) +void GlyphPoints::InsertPoint(uint16_t pt, const IPoint &p) { InsertPoint(pt, p.x, p.y, p.onCurve); } @@ -292,10 +292,10 @@ void GlyphPoints::InsertPoint(uint16 pt, const IPoint &p) // size counters down as needed. In the future, we'll keep track so we // don't have to reallocate *every* damn time a point is added... // -void GlyphPoints::DeletePoint(uint16 pt) +void GlyphPoints::DeletePoint(uint16_t pt) { // Adjust polygon ends appropriately - uint16 poly = GetPoly(pt); + uint16_t poly = GetPoly(pt); for(int i=poly; 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 @@ -341,18 +341,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 @@ -363,12 +363,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 @@ -379,12 +379,12 @@ WriteLogMsg("Exception: GetY(uint16). pt=%u, numPoints=%u\xD\xA", pt, numPoints) } -bool GlyphPoints::GetOnCurve(uint16 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 @@ -395,12 +395,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 @@ -411,18 +411,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 @@ -433,19 +433,19 @@ 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), GetOnCurve(poly, pt)); } -IPoint GlyphPoints::GetPoint(uint16 pointNumber) +IPoint GlyphPoints::GetPoint(uint16_t pointNumber) { if (pointNumber > numPoints) throw GP_OUT_OF_RANGE; @@ -454,12 +454,12 @@ IPoint GlyphPoints::GetPoint(uint16 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 @@ -470,24 +470,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 @@ -499,12 +499,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 @@ -525,19 +525,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 @@ -568,12 +568,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 @@ -584,12 +584,12 @@ WriteLogMsg("Exception: SetOnCurve(uint16, bool). pt=%u, numPoints=%u\xD\xA", pt } -void GlyphPoints::SetPoint(const uint16 pointNum, const IPoint point) +void GlyphPoints::SetPoint(const uint16_t pointNum, const IPoint point) { if (pointNum >= numPoints) #ifdef DEBUG { -WriteLogMsg("Exception: SetPoint(uint16, IPoint). pt=%u, numPoints=%u\xD\xA", pointNum, numPoints); +WriteLogMsg("Exception: SetPoint(uint16_t, IPoint). pt=%u, numPoints=%u\xD\xA", pointNum, numPoints); #endif throw GP_OUT_OF_RANGE; #ifdef DEBUG @@ -600,10 +600,10 @@ WriteLogMsg("Exception: SetPoint(uint16, IPoint). pt=%u, numPoints=%u\xD\xA", po } -uint16 GlyphPoints::GetPrev(uint16 pt) +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 @@ -688,7 +688,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; } @@ -697,9 +697,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++; @@ -764,14 +764,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; @@ -824,7 +824,7 @@ 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) @@ -836,7 +836,7 @@ IPoint GlyphPoints::GetPolyCentroid(const int16 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 @@ -844,9 +844,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]; @@ -859,14 +859,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; @@ -875,18 +875,18 @@ void GlyphPoints::RotatePolyAroundCentroid(const int16 poly, const double angle) } -void GlyphPoints::InvertPolyDrawSequence(const uint16 poly) +void GlyphPoints::InvertPolyDrawSequence(const uint16_t poly) { if (poly >= numPolys) throw GP_OUT_OF_RANGE; - uint16 pointNum1 = GetPolyStart(poly); - uint16 pointNum2 = GetPolyEnd(poly); + 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 i=0; i #include // "IPoint" is an Integer based Point struct IPoint { - int32 x, y; + int32_t x, y; bool onCurve; - IPoint(int32 xx=0, int32 yy=0, bool oc=true): x(xx), y(yy), onCurve(oc) {} + 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 x, y; + int32_t x, y; double angle; }; @@ -45,10 +45,10 @@ class GlyphPoints //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); + 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 * pa = NULL); +// bool * oca = NULL, uint16_t * pa = NULL); GlyphPoints(int xx, int yy, bool oc); // GlyphPoints(GlyphPoints &); // Copy constructor GlyphPoints(const GlyphPoints &); // Copy constructor @@ -58,64 +58,64 @@ class GlyphPoints GlyphPoints operator+(const IPoint &); GlyphPoints& operator+=(const IPoint &); void Clear(void); - void InsertPoint(uint16, int, int, bool); - void InsertPoint(uint16, const IPoint &); - void DeletePoint(uint16); - uint16 GetNumPoints(void); - uint16 GetNumPoints(uint16 poly); - uint16 GetNumPolys(void); - int GetX(uint16); - int GetY(uint16); - bool GetOnCurve(uint16); - int GetX(uint16, uint16); - int GetNextX(uint16, uint16); - int GetY(uint16, uint16); - int GetNextY(uint16, uint16); - IPoint GetPoint(uint16, uint16); - IPoint GetPoint(uint16); - bool GetOnCurve(uint16, uint16); - bool GetPrevOnCurve(uint16, uint16); - bool GetNextOnCurve(uint16, uint16); - uint16 GetPolyStart(uint16); - uint16 GetPolyEnd(uint16); + 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); + 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, int32, int32); + void OffsetPoly(uint16_t, int32_t, int32_t); void ScalePoints(float); - void SetXY(uint16, int, int); - void SetOnCurve(uint16, bool); - void SetPoint(const uint16 pointNum, const IPoint point); - uint16 GetPrev(uint16); - uint16 GetNext(uint16); - uint16 GetPrev(uint16, uint16); - uint16 GetNext(uint16, uint16); - uint16 GetPoly(uint16); + 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, uint16); - IPoint GetMidpointToNext(uint16, uint16); - IPoint GetPrevPoint(uint16, uint16); - IPoint GetNextPoint(uint16, uint16); - uint16 GetPolyForPoint(IPoint point); - uint16 GetPolyForPointNumber(uint16 pointNumber); + 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 poly); - void RotatePolyAroundCentroid(const int16 poly, const double angle); - void InvertPolyDrawSequence(const uint16 poly); + 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 *); + void AllocateAndCopy(int, int, int *, int *, bool *, uint16_t *); void FreeAllocatedMemory(void); private: int numPoints, numPolys; int * x, * y; bool * onCurve; - uint16 * polyEnd; - uint16 pointsAllocated, polysAllocated; + uint16_t * polyEnd; + uint16_t pointsAllocated, polysAllocated; }; #endif // __GLYPHPOINTS_H__ diff --git a/src/graphicprimitives.cpp b/src/graphicprimitives.cpp index dd9b480..9dec215 100755 --- a/src/graphicprimitives.cpp +++ b/src/graphicprimitives.cpp @@ -63,7 +63,7 @@ void Bezier(QPainter &p, IPoint p1, IPoint p2, IPoint p3) // // Draw a round dot (5x5, centered on [x, y]) // -void DrawRoundDot(QPainter &p, int32 x, int32 y) +void DrawRoundDot(QPainter &p, int32_t x, int32_t y) { QPoint pt[8]; @@ -83,7 +83,7 @@ void DrawRoundDot(QPainter &p, int32 x, int32 y) // // Draw a sqaure dot (5x5, centered on [x, y]) // -void DrawSquareDot(QPainter &p, int32 x, int32 y) +void DrawSquareDot(QPainter &p, int32_t x, int32_t y) { QPoint pt[4]; @@ -99,10 +99,10 @@ void DrawSquareDot(QPainter &p, int32 x, int32 y) // // Draw a sqaure dot (nxn, centered on [x, y]) // -void DrawSquareDotN(QPainter &p, int32 x, int32 y, uint32 n) +void DrawSquareDotN(QPainter &p, int32_t x, int32_t y, uint32_t n) { QPoint pt[4]; - uint32 offset = (n - 1) / 2; + uint32_t offset = (n - 1) / 2; pt[0] = QPoint(x - offset, y - offset); pt[1] = QPoint(x + offset, y - offset); @@ -116,7 +116,7 @@ void DrawSquareDotN(QPainter &p, int32 x, int32 y, uint32 n) // // Draw a round dot (nxn, centered on [x, y]) // -void DrawRoundDotN(QPainter &p, int32 x, int32 y, uint32 n) +void DrawRoundDotN(QPainter &p, int32_t x, int32_t y, uint32_t n) { int radius = (n / 2) + 1; p.drawEllipse(x - radius, y - radius, n, n); diff --git a/src/graphicprimitives.h b/src/graphicprimitives.h index 9b2de44..6d5b27b 100755 --- a/src/graphicprimitives.h +++ b/src/graphicprimitives.h @@ -8,8 +8,8 @@ #ifndef __GRAPHICPRIMITIVES_H__ #define __GRAPHICPRIMITIVES_H__ +#include #include // For QPainter -#include "types.h" // For int32 #include "glyphpoints.h" // For IPoint struct point @@ -21,9 +21,9 @@ struct point void Bezier(QPainter &, point, point, point); void Bezier(QPainter &, IPoint, IPoint, IPoint); -void DrawRoundDot(QPainter &, int32, int32); -void DrawSquareDot(QPainter &, int32, int32); -void DrawRoundDotN(QPainter &, int32, int32, uint32); -void DrawSquareDotN(QPainter &, int32, int32, uint32); +void DrawRoundDot(QPainter &, int32_t, int32_t); +void DrawSquareDot(QPainter &, int32_t, int32_t); +void DrawRoundDotN(QPainter &, int32_t, int32_t, uint32_t); +void DrawSquareDotN(QPainter &, int32_t, int32_t, uint32_t); #endif // __GRAPHICPRIMITIVES_H__ diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 25b63d1..dea9087 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -45,6 +45,7 @@ MainWindow::MainWindow() ((TTEdit *)qApp)->charWnd = new CharWindow(this); editWnd = new EditWindow(this); setCentralWidget(editWnd); + editWnd->setFocus(); setWindowIcon(QIcon(":/res/ttedit.png")); setWindowTitle("TTEdit!"); diff --git a/src/mainwindow.h b/src/mainwindow.h index 80df508..7038b1e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -73,3 +73,4 @@ class MainWindow: public QMainWindow }; #endif // __MAINWINDOW_H__ + diff --git a/src/toolwindow.cpp b/src/toolwindow.cpp index 5fd774c..13d3754 100755 --- a/src/toolwindow.cpp +++ b/src/toolwindow.cpp @@ -23,7 +23,6 @@ #define DEBUGTP // Toolpalette debugging... #include "toolwindow.h" -#include "types.h" ToolWindow::ToolWindow(void): QWidget(NULL, Qt::Window | Qt::FramelessWindowHint), @@ -72,7 +71,7 @@ ToolType ToolWindow::FindSelectedTool(void) //printf("pt = %u, %u\n", pt.x(), pt.y()); // Divide mouse coords by the bitmap stamp size to find which one is pointed to - uint32 x = (uint32)pt.x() / sizeStamp.x(), y = (uint32)pt.y() / sizeStamp.y(); + uint32_t x = (uint32_t)pt.x() / sizeStamp.x(), y = (uint32_t)pt.y() / sizeStamp.y(); // Preset failure into newTool, in case no new tool is selected ToolType newTool = TOOLNone; diff --git a/src/toolwindow.h b/src/toolwindow.h index 1077d67..47125c2 100755 --- a/src/toolwindow.h +++ b/src/toolwindow.h @@ -48,3 +48,4 @@ class ToolWindow: public QWidget }; #endif // __TOOLWINDOW_H__ + diff --git a/src/ttf.cpp b/src/ttf.cpp index ce312a8..799f032 100755 --- a/src/ttf.cpp +++ b/src/ttf.cpp @@ -20,7 +20,7 @@ // - Eliminate ALL references to BYTE, WORD, SBYTE, SWORD, etc. // -#include // For file handling, etc. // +#include // For file handling, etc. #include #include #include "charnames.h" @@ -35,7 +35,7 @@ #define NUMTABS 24 // Number of distinct tables -/*void fskip(HANDLE file, uint32 bytesToSkip) +/*void fskip(HANDLE file, uint32_t bytesToSkip) { SetFilePointer(file, (LONG)bytesToSkip, NULL, FILE_CURRENT); }*/ @@ -43,9 +43,9 @@ // // Get a BYTE from the current file... // -uint8 ReadByte(FILE * file) +uint8_t ReadByte(FILE * file) { - return (uint8)fgetc(file); + return (uint8_t)fgetc(file); } // The following routines get and put WORDs and DWORDs in little endian @@ -55,10 +55,10 @@ uint8 ReadByte(FILE * file) // // Get a WORD from the current file... // -uint16 ReadWord(FILE * file) +uint16_t ReadWord(FILE * file) { - uint16 word = (uint16)fgetc(file) << 8; - word |= (uint16)fgetc(file); + uint16_t word = (uint16_t)fgetc(file) << 8; + word |= (uint16_t)fgetc(file); return word; } @@ -66,14 +66,14 @@ uint16 ReadWord(FILE * file) // // Get a double WORD from the current file... // -uint32 ReadDWord(FILE * file) +uint32_t ReadDWord(FILE * file) { - uint32 dword = 0; + uint32_t dword = 0; for(int i=0; i<4; i++) { dword <<= 8; - dword |= (uint8)fgetc(file); + dword |= (uint8_t)fgetc(file); } return dword; @@ -82,7 +82,7 @@ uint32 ReadDWord(FILE * file) // // Write a WORD to the current file... // -void WriteWord(FILE * file, uint16 word) +void WriteWord(FILE * file, uint16_t word) { fputc(word >> 8, file); // Hi byte fputc(word & 0xFF, file); // Lo byte @@ -91,7 +91,7 @@ void WriteWord(FILE * file, uint16 word) // // Write a double WORD to the current file... // -void WriteDWord(FILE * file, uint32 dword) +void WriteDWord(FILE * file, uint32_t dword) { for(int i=0; i<4; i++) { @@ -107,7 +107,7 @@ void WriteDWord(FILE * file, uint32 dword) // // Return a BYTE from a BYTE based table // -uint8 GetByte(uint8 * table, uint32 &ptr) +uint8_t GetByte(uint8_t * table, uint32_t &ptr) { return table[ptr++]; } @@ -115,25 +115,25 @@ uint8 GetByte(uint8 * table, uint32 &ptr) // // Return a WORD from a BYTE based table // -uint16 GetWord(uint8 * table, uint32 &ptr) +uint16_t GetWord(uint8_t * table, uint32_t &ptr) { - uint16 hi = table[ptr++]; - uint16 lo = table[ptr++]; + uint16_t hi = table[ptr++]; + uint16_t lo = table[ptr++]; - return (uint16)((hi<<8) | lo); + return (uint16_t)((hi<<8) | lo); } // // Return a double WORD from a BYTE based table // -uint32 GetDWord(uint8 * table, uint32 &ptr) +uint32_t GetDWord(uint8_t * table, uint32_t &ptr) { - uint32 hi1 = table[ptr++]; - uint32 lo1 = table[ptr++]; - uint32 hi2 = table[ptr++]; - uint32 lo2 = table[ptr++]; + uint32_t hi1 = table[ptr++]; + uint32_t lo1 = table[ptr++]; + uint32_t hi2 = table[ptr++]; + uint32_t lo2 = table[ptr++]; - return (uint32)((hi1 << 24) | (lo1 << 16) | (hi2 << 8) | lo2); + return (uint32_t)((hi1 << 24) | (lo1 << 16) | (hi2 << 8) | lo2); } ///////////////////////////////////////////////////////////////////////////// @@ -143,7 +143,7 @@ uint32 GetDWord(uint8 * table, uint32 &ptr) // // Store a BYTE in a BYTE based table // -void SetByte(uint8 * table, uint32 &ptr, uint8 data) +void SetByte(uint8_t * table, uint32_t &ptr, uint8_t data) { table[ptr++] = data; } @@ -151,7 +151,7 @@ void SetByte(uint8 * table, uint32 &ptr, uint8 data) // // Store a WORD in a BYTE based table // -void SetWord(uint8 * table, uint32 &ptr, uint16 data) +void SetWord(uint8_t * table, uint32_t &ptr, uint16_t data) { table[ptr++] = data>>8; table[ptr++] = data&0xFF; } @@ -159,16 +159,16 @@ void SetWord(uint8 * table, uint32 &ptr, uint16 data) // // Store a DWORD in a BYTE based table // -void SetDWord(uint8 * table, uint32 &ptr, uint32 data) +void SetDWord(uint8_t * table, uint32_t &ptr, uint32_t data) { - table[ptr++] = (uint8)(data >> 24); table[ptr++] = (uint8)(data >> 16); - table[ptr++] = (uint8)(data >> 8); table[ptr++] = (uint8)(data & 0xFF); + table[ptr++] = (uint8_t)(data >> 24); table[ptr++] = (uint8_t)(data >> 16); + table[ptr++] = (uint8_t)(data >> 8); table[ptr++] = (uint8_t)(data & 0xFF); } ///////////////////////////////////////////////////////////////////////////// // Fixed point to float (& vice versa) conversions ///////////////////////////////////////////////////////////////////////////// -float FixedToFloat(int16 fixed) +float FixedToFloat(int16_t fixed) { return (float)fixed / 16384.0f; } @@ -201,10 +201,10 @@ TTF::TTF(void) larray[18] = &maxp_len; larray[19] = &name_len; larray[20] = &post_len; larray[21] = &prep_len; larray[22] = &vhea_len; larray[23] = &vmtx_len; - for(uint32 i=0; i 255) || (curx < -255)) // I.e., it's 2 uint8 value + if ((curx > 255) || (curx < -255)) // I.e., it's 2 uint8_t value SetWord(xbuf, xp, curx); else { @@ -473,7 +473,7 @@ bool TTF::EncodeGlyph(uint16 glyphnum) if (cury) { - if ((cury > 255) || (cury < -255)) // I.e., it's 2 uint8 value + if ((cury > 255) || (cury < -255)) // I.e., it's 2 uint8_t value SetWord(ybuf, yp, cury); else { @@ -502,7 +502,7 @@ bool TTF::EncodeGlyph(uint16 glyphnum) { if (fbuf[i] == fbuf[i+1]) // { - uint8 count = 0; // Sentinel takes care of check for end of flags... + uint8_t count = 0; // Sentinel takes care of check for end of flags... while (fbuf[i] == fbuf[++i]) count++; // Count number of repeats i--; fbuf[fp++] = fbuf[i] | 0x08; // Set repeat flag @@ -514,35 +514,35 @@ bool TTF::EncodeGlyph(uint16 glyphnum) fp = numberOfPoints; // Find length of glyph and reallocate space if necessary - uint32 newLength = 12 + numberOfPolys*2 + numberOfHints + fp + xp + yp; + uint32_t newLength = 12 + numberOfPolys*2 + numberOfHints + fp + xp + yp; if (newLength & 0x03) newLength += (4 - newLength & 0x03); if (glyphLen[glyphnum] != newLength) { - glyph[glyphnum] = (uint8 *)realloc(glyph[glyphnum], newLength); + glyph[glyphnum] = (uint8_t *)realloc(glyph[glyphnum], newLength); glyphLen[glyphnum] = newLength; } // And finally, store it! - uint32 gp = 0; // Glyph pointer... + uint32_t gp = 0; // Glyph pointer... SetWord(glyph[glyphnum], gp, numberOfPolys); SetWord(glyph[glyphnum], gp, llx); SetWord(glyph[glyphnum], gp, lly); SetWord(glyph[glyphnum], gp, urx); SetWord(glyph[glyphnum], gp, ury); - for(uint32 i=0; i= myMaxp.numGlyphs) @@ -578,10 +578,10 @@ bool TTF::DecodeGlyph(uint16 glyphnum) isCompositeGlyph = false; // Default is no numberOfPolys = GetWord(glyph[glyphnum], dp); // # of polygons - llx = (int16)GetWord(glyph[glyphnum], dp); // Lower left X - lly = (int16)GetWord(glyph[glyphnum], dp); // Lower left Y - urx = (int16)GetWord(glyph[glyphnum], dp); // Upper right X - ury = (int16)GetWord(glyph[glyphnum], dp); // Upper right Y + llx = (int16_t)GetWord(glyph[glyphnum], dp); // Lower left X + lly = (int16_t)GetWord(glyph[glyphnum], dp); // Lower left Y + urx = (int16_t)GetWord(glyph[glyphnum], dp); // Upper right X + ury = (int16_t)GetWord(glyph[glyphnum], dp); // Upper right Y // Need to handle composite glyphs better here. The ways things // are set now is a recipe for disaster... @@ -600,19 +600,19 @@ bool TTF::DecodeGlyph(uint16 glyphnum) { cmpst.flags = GetWord(glyph[glyphnum], dp); cmpst.glyphIndex = GetWord(glyph[glyphnum], dp); - cmpst.arg1 = (cmpst.flags & 0x01 ? (int16)GetWord(glyph[glyphnum], dp) : (int8)GetByte(glyph[glyphnum], dp)); - cmpst.arg2 = (cmpst.flags & 0x01 ? (int16)GetWord(glyph[glyphnum], dp) : (int8)GetByte(glyph[glyphnum], dp)); + cmpst.arg1 = (cmpst.flags & 0x01 ? (int16_t)GetWord(glyph[glyphnum], dp) : (int8_t)GetByte(glyph[glyphnum], dp)); + cmpst.arg2 = (cmpst.flags & 0x01 ? (int16_t)GetWord(glyph[glyphnum], dp) : (int8_t)GetByte(glyph[glyphnum], dp)); if (cmpst.flags & 0x08) - cmpst.xScale = cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); else if (cmpst.flags & 0x40) - cmpst.xScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); else if (cmpst.flags & 0x80) - cmpst.xScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.scale01 = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.scale10 = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)), - cmpst.yScale = FixedToFloat((int16)GetWord(glyph[glyphnum], dp)); + cmpst.xScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.scale01 = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.scale10 = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)), + cmpst.yScale = FixedToFloat((int16_t)GetWord(glyph[glyphnum], dp)); compositeList.AddAtRear(cmpst); } @@ -624,9 +624,9 @@ bool TTF::DecodeGlyph(uint16 glyphnum) //do { // USHORT flags; // USHORT glyphIndex; -// if ( flags & ARG_1_AND_2_ARE_uint16S) { -// (SHORT or Fuint16) argument1; -// (SHORT or Fuint16) argument2; +// if ( flags & ARG_1_AND_2_ARE_uint16_tS) { +// (SHORT or Fuint16_t) argument1; +// (SHORT or Fuint16_t) argument2; // } else { // USHORT arg1and2; /* (arg1 << 8) | arg2 */ // } @@ -644,11 +644,11 @@ bool TTF::DecodeGlyph(uint16 glyphnum) //} while ( flags & MORE_COMPONENTS ) //if (flags & WE_HAVE_INSTR){ // USHORT numInstr -// uint8 instr[numInstr] +// uint8_t instr[numInstr] // //Flags Bit Description -//ARG_1_AND_2_ARE_uint16S 0 If this is set, the arguments are uint16s; -// otherwise, they are uint8s. +//ARG_1_AND_2_ARE_uint16_tS 0 If this is set, the arguments are uint16_ts; +// otherwise, they are uint8_ts. //ARGS_ARE_XY_VALUES 1 If this is set, the arguments are xy values; // otherwise, they are points. //ROUND_XY_TO_GRID 2 For the xy values if the preceding is true. @@ -678,20 +678,20 @@ bool TTF::DecodeGlyph(uint16 glyphnum) // Decode the dots... - uint32 num_pts = poly[numberOfPolys-1] + 1; + uint32_t num_pts = poly[numberOfPolys-1] + 1; numberOfPoints = num_pts; // necessary?? - uint32 xptr, yptr; // pointers to beginning of coord data - uint32 numXs = 0; + uint32_t xptr, yptr; // pointers to beginning of coord data + uint32_t numXs = 0; int xx = 0, yy = 0, repeat; - uint32 numTokens = num_pts, k, numRep; + uint32_t numTokens = num_pts, k, numRep; // We make an educated guess that num_pts = num_tokens; but if there // is repeated data in the tokens, then we need to adjust the # of // tokens down appropriately. - for(uint32 i=0; i 257) { @@ -866,13 +866,13 @@ void TTF::GetCharName(int cNum, uint8 * buf) pTab = macStdNames; } - for(uint32 i=0; i= numberOfPolys) return 0; @@ -1148,7 +1148,7 @@ uint16 TTF::GetPolyEnd(uint16 polynum) return poly[polynum]; } -int TTF::GetPointX(uint16 pointno) +int TTF::GetPointX(uint16_t pointno) { if (pointno >= MAXPOINTS) return 0; @@ -1156,7 +1156,7 @@ int TTF::GetPointX(uint16 pointno) return gx[pointno]; } -int TTF::GetPointY(uint16 pointno) +int TTF::GetPointY(uint16_t pointno) { if (pointno >= MAXPOINTS) return 0; @@ -1164,7 +1164,7 @@ int TTF::GetPointY(uint16 pointno) return gy[pointno]; } -bool TTF::GetOnCurve(uint16 pointno) +bool TTF::GetOnCurve(uint16_t pointno) { if (pointno >= MAXPOINTS) return true; @@ -1172,7 +1172,7 @@ bool TTF::GetOnCurve(uint16 pointno) return onCurve[pointno]; } -bool TTF::SetOnCurve(uint16 pointno, bool state) +bool TTF::SetOnCurve(uint16_t pointno, bool state) { if (pointno >= numberOfPoints) return false; @@ -1183,7 +1183,7 @@ bool TTF::SetOnCurve(uint16 pointno, bool state) return true; } -bool TTF::MovePoint(uint16 pointno, int x, int y) +bool TTF::MovePoint(uint16_t pointno, int x, int y) { if (pointno >= numberOfPoints) return false; @@ -1194,7 +1194,7 @@ bool TTF::MovePoint(uint16 pointno, int x, int y) return true; } -bool TTF::MovePoint(uint16 pointno, GlyphPt p) +bool TTF::MovePoint(uint16_t pointno, GlyphPt p) { if (pointno >= numberOfPoints) return false; diff --git a/src/ttf.h b/src/ttf.h index 2ea45be..49a3869 100755 --- a/src/ttf.h +++ b/src/ttf.h @@ -8,35 +8,28 @@ // TTF database. // -// These really shouldn't be included here, but are for now... -//#include -////#include // This is needed only for things like BOOL, etc. -//#include -//#include -//#include // Both for malloc, free, _msize, realloc - #ifndef __TTF_H__ #define __TTF_H__ +#include #include "list.h" -#include "types.h" #include "glyphpoints.h" #define MAXGLYPHS 4096 // Number of glyphs in object #define MAXPOINTS 2000 // Number of points in a glyph -#define MAXHINTS 2000 // Number of hint uint8s in glyph +#define MAXHINTS 2000 // Number of hint uint8_ts in glyph // // "head" struct // struct Head { - uint32 version; // Fixed - Table version number (0x00010000 for version 1.0.) - uint32 fontRevision; // Fixed - fontRevision (Set by font manufacturer.) - uint32 checkSumAdjustment; // To compute: Set it to 0, sum the entire font + uint32_t version; // Fixed - Table version number (0x00010000 for version 1.0.) + uint32_t fontRevision; // Fixed - fontRevision (Set by font manufacturer.) + uint32_t checkSumAdjustment; // To compute: Set it to 0, sum the entire font // as ULONG, then store 0xB1B0AFBA - sum. - uint32 magicNumber; // Set to 0x5F0F3CF5. - uint16 flags; /* Bit 0 - baseline for font at y=0; + uint32_t magicNumber; // Set to 0x5F0F3CF5. + uint16_t flags; /* Bit 0 - baseline for font at y=0; Bit 1 - left sidebearing at x=0; Bit 2 - instructions may depend on point size; Bit 3 - force ppem to integer values for all @@ -45,23 +38,23 @@ struct Head Bit 4 - instructions may alter advance width (the advance widths might not scale linearly); Note: All other bits must be zero.*/ - uint16 unitsPerEm; // Valid range is from 16 to 16384 - uint32 /*longDateTime*/ createdh, createdl; // International date (8-uint8 field). - uint32 /*longDateTime*/ modifiedh, modifiedl; // International date (8-uint8 field). - uint16 xMin; // For all glyph bounding boxes. - uint16 yMin; // For all glyph bounding boxes. - uint16 xMax; // For all glyph bounding boxes. - uint16 yMax; // For all glyph bounding boxes. - uint16 macStyle; /* Bit 0 bold (if set to 1); Bit 1 italic (if set to 1) + uint16_t unitsPerEm; // Valid range is from 16 to 16384 + uint32_t /*longDateTime*/ createdh, createdl; // International date (8-uint8_t field). + uint32_t /*longDateTime*/ modifiedh, modifiedl; // International date (8-uint8_t field). + uint16_t xMin; // For all glyph bounding boxes. + uint16_t yMin; // For all glyph bounding boxes. + uint16_t xMax; // For all glyph bounding boxes. + uint16_t yMax; // For all glyph bounding boxes. + uint16_t macStyle; /* Bit 0 bold (if set to 1); Bit 1 italic (if set to 1) Bits 2-15 reserved (set to 0).*/ - uint16 lowestRecPPEM; // Smallest readable size in pixels. - int16 fontDirectionHint; /* 0 Fully mixed directional glyphs; + uint16_t lowestRecPPEM; // Smallest readable size in pixels. + int16_t fontDirectionHint; /* 0 Fully mixed directional glyphs; 1 Only strongly left to right; 2 Like 1 but also contains neutrals; -1 Only strongly right to left; -2 Like -1 but also contains neutrals.*/ - int16 indexToLocFormat; // 0 for short offsets, 1 for long. - int16 glyphDataFormat; // 0 for current format. + int16_t indexToLocFormat; // 0 for short offsets, 1 for long. + int16_t glyphDataFormat; // 0 for current format. }; // @@ -69,24 +62,24 @@ struct Head // struct Maxp { - uint32 version; // Table version number 0x00010000 for version 1.0. - uint16 numGlyphs; // The number of glyphs in the font. - uint16 maxPoints; // Maximum points in a non-composite glyph. - uint16 maxContours; // Maximum contours in a non-composite glyph. - uint16 maxCompositePoints; // Maximum points in a composite glyph. - uint16 maxCompositeContours; // Maximum contours in a composite glyph. - uint16 maxZones; // 1 if instructions do not use the twilight + uint32_t version; // Table version number 0x00010000 for version 1.0. + uint16_t numGlyphs; // The number of glyphs in the font. + uint16_t maxPoints; // Maximum points in a non-composite glyph. + uint16_t maxContours; // Maximum contours in a non-composite glyph. + uint16_t maxCompositePoints; // Maximum points in a composite glyph. + uint16_t maxCompositeContours; // Maximum contours in a composite glyph. + uint16_t maxZones; // 1 if instructions do not use the twilight // zone (Z0), or 2 if instructions do use Z0; // should be set to 2 in most cases. - uint16 maxTwilightPoints; // Maximum points used in Z0. - uint16 maxStorage; // Number of Storage Area locations. - uint16 maxFunctionDefs; // Number of FDEFs. - uint16 maxInstructionDefs; // Number of IDEFs. - uint16 maxStackElements; // Maximum stack depth. - uint16 maxSizeOfInstructions; // Maximum uint8 count for glyph instructions. - uint16 maxComponentElements; // Maximum number of components referenced at + uint16_t maxTwilightPoints; // Maximum points used in Z0. + uint16_t maxStorage; // Number of Storage Area locations. + uint16_t maxFunctionDefs; // Number of FDEFs. + uint16_t maxInstructionDefs; // Number of IDEFs. + uint16_t maxStackElements; // Maximum stack depth. + uint16_t maxSizeOfInstructions; // Maximum uint8_t count for glyph instructions. + uint16_t maxComponentElements; // Maximum number of components referenced at // "top level" for any composite glyph. - uint16 maxComponentDepth; // Maximum levels of recursion; 1 for simple components. + uint16_t maxComponentDepth; // Maximum levels of recursion; 1 for simple components. }; // @@ -102,10 +95,10 @@ particular encoding, and the offset to the actual subtable: Type Description USHORT Platform ID. USHORT Platform-specific encoding ID. -ULONG uint8 offset from beginning of table to the subtable for this encoding. +ULONG uint8_t offset from beginning of table to the subtable for this encoding. USHORT format Format number is set to 4. -USHORT length Length in uint8s. +USHORT length Length in uint8_ts. USHORT version Version number (starts at 0). USHORT segCountX2 2 x segCount. USHORT searchRange 2 x (2**floor(log2(segCount))) @@ -141,17 +134,17 @@ struct GlyphPt struct Box { - int16 llx, lly, urx, ury; + int16_t llx, lly, urx, ury; // Default constructor - Box(int16 lx = 0, int16 ly = 0, int16 rx = 0, int16 ry = 0): + Box(int16_t lx = 0, int16_t ly = 0, int16_t rx = 0, int16_t ry = 0): llx(lx), lly(ly), urx(rx), ury(ry) {} }; struct NameRec { - uint16 platformID, platformSpecID, languageID, nameID, length; - uint8 * str; + uint16_t platformID, platformSpecID, languageID, nameID, length; + uint8_t * str; NameRec(): str(NULL) {} @@ -179,17 +172,17 @@ struct NameRec languageID = c.languageID; nameID = c.nameID; length = c.length; -//Fix this str = (uint8 *)strdup((char *)c.str); +//Fix this str = (uint8_t *)strdup((char *)c.str); } }; struct Composite { - uint16 flags, glyphIndex; - int16 arg1, arg2; + uint16_t flags, glyphIndex; + int16_t arg1, arg2; float xScale, yScale, scale01, scale10; - Composite(uint16 fl = 0, uint16 gl = 0, int16 a1 = 0, int16 a2 = 0, + Composite(uint16_t fl = 0, uint16_t gl = 0, int16_t a1 = 0, int16_t a2 = 0, float xs = 1.0f, float ys = 1.0f, float s01 = 1.0f, float s10 = 1.0f): flags(fl), glyphIndex(gl), arg1(a1), arg2(a2), xScale(xs), yScale(ys), scale01(s01), scale10(s10) {} @@ -229,8 +222,8 @@ struct Composite class TTF { private: - bool EncodeGlyph(uint16); - bool DecodeGlyph(uint16); + bool EncodeGlyph(uint16_t); + bool DecodeGlyph(uint16_t); bool ExtractTables(void); bool BuildTables(void); @@ -241,54 +234,54 @@ class TTF bool Load(const char *); // Load font database bool Save(const char *); // Save font database void ClearTables(void); // Deallocate memory... - bool SetGlyph(uint16 glyphnum); // Set internal pointer/encode/decode - bool AddGlyph(uint16 glyphnum); - bool DeleteGlyph(uint16 glyphnum); + bool SetGlyph(uint16_t glyphnum); // Set internal pointer/encode/decode + bool AddGlyph(uint16_t glyphnum); + bool DeleteGlyph(uint16_t glyphnum); Box GetBoundingBox(void); - GlyphPt GetPoint(uint16 pointno); - uint16 GetNumberOfPolys(void); - uint16 GetPolyEnd(uint16 polynum); - int GetPointX(uint16 pointno); - int GetPointY(uint16 pointno); - bool GetOnCurve(uint16 pointno); - bool SetOnCurve(uint16 pointno, bool state); - bool MovePoint(uint16 pointno, int x, int y); - bool MovePoint(uint16 pointno, GlyphPt p); - bool AddPoint(uint16 pointno, int x, int y, bool state); - bool DeletePoint(uint16 pointno); + GlyphPt GetPoint(uint16_t pointno); + uint16_t GetNumberOfPolys(void); + uint16_t GetPolyEnd(uint16_t polynum); + int GetPointX(uint16_t pointno); + int GetPointY(uint16_t pointno); + bool GetOnCurve(uint16_t pointno); + bool SetOnCurve(uint16_t pointno, bool state); + bool MovePoint(uint16_t pointno, int x, int y); + bool MovePoint(uint16_t pointno, GlyphPt p); + bool AddPoint(uint16_t pointno, int x, int y, bool state); + bool DeletePoint(uint16_t pointno); bool IsCompositeGlyph(void); - GlyphPoints GetGlyphPoints(uint16); - GlyphPoints GetAllCompositePoints(uint16); - void GetCharName(int, uint8 *); + GlyphPoints GetGlyphPoints(uint16_t); + GlyphPoints GetAllCompositePoints(uint16_t); + void GetCharName(int, uint8_t *); private: bool isDirty; // Has glyph been modified? bool isCompositeGlyph; // Is it a composite? (need structs to store composite info...) - uint16 currentGlyph; // The glyph currently decoded - uint16 numberOfPoints; + uint16_t currentGlyph; // The glyph currently decoded + uint16_t numberOfPoints; int gx[MAXPOINTS]; // Internal point arrays... int gy[MAXPOINTS]; // These could be dynamically allocated in the bool onCurve[MAXPOINTS]; // constructor, with default values being set - uint16 numberOfHints; - uint8 hint[MAXHINTS]; // Hints storage - uint16 numberOfPolys; // Number of polygons in glyph - uint16 poly[200]; // End points of polygons - int16 llx, lly, urx, ury; // Lower left/Upper right X/Y + uint16_t numberOfHints; + uint8_t hint[MAXHINTS]; // Hints storage + uint16_t numberOfPolys; // Number of polygons in glyph + uint16_t poly[200]; // End points of polygons + int16_t llx, lly, urx, ury; // Lower left/Upper right X/Y // public://remove after debugging... - uint8 * glyph[MAXGLYPHS]; // Placeholders for glyphs - uint32 glyphLen[MAXGLYPHS]; // Glyph lengths are stored since malloc() is sloppy + uint8_t * glyph[MAXGLYPHS]; // Placeholders for glyphs + uint32_t glyphLen[MAXGLYPHS]; // Glyph lengths are stored since malloc() is sloppy Maxp myMaxp; // Internal placeholders for this shiat Head myHead; // public: //private: later... List compositeList; // Composite glyph list - uint8 * EBDT, * EBLC, * EBSC, * LTSH, * OS_2, * PCLT, * VDMX, * cmap, * cvt, * fpgm, + uint8_t * EBDT, * EBLC, * EBSC, * LTSH, * OS_2, * PCLT, * VDMX, * cmap, * cvt, * fpgm, * gasp, * glyf, * hdmx, * head, * hhea, * hmtx, * kern, * loca, * maxp, * name, * post, * prep, * vhea, * vmtx; - uint32 EBDT_len, EBLC_len, EBSC_len, LTSH_len, OS_2_len, PCLT_len, VDMX_len, cmap_len, + uint32_t EBDT_len, EBLC_len, EBSC_len, LTSH_len, OS_2_len, PCLT_len, VDMX_len, cmap_len, cvt_len, fpgm_len, gasp_len, glyf_len, hdmx_len, head_len, hhea_len, hmtx_len, kern_len, loca_len, maxp_len, name_len, post_len, prep_len, vhea_len, vmtx_len; - uint8 * * parray[24]; // Pointer array - uint32 * larray[24]; // Length array + uint8_t * * parray[24]; // Pointer array + uint32_t * larray[24]; // Length array bool loaded; // Font loaded/init'ed? }; diff --git a/src/types.h b/src/types.h deleted file mode 100755 index 0fc13b5..0000000 --- a/src/types.h +++ /dev/null @@ -1,30 +0,0 @@ -// -// Basic types for platform independent code -// - -#ifndef __TYPES_H__ -#define __TYPES_H__ - -// This should be portable, since it's part of the C99 standard...! - -#include - -typedef uint8_t uint8; -typedef int8_t int8; -typedef uint16_t uint16; -typedef int16_t int16; -typedef uint32_t uint32; -typedef int32_t int32; -typedef uint64_t uint64; -typedef int64_t int64; - -/*#ifndef _WINDOWS_ -#define NULL 0 -// This is for non-compliant compilers that don't follow proper scoping rules (and suck). ;-) -#define for if(false);else for -#endif*/ -#ifndef NULL -#define NULL 0 -#endif - -#endif // __TYPES_H__ diff --git a/src/vector.cpp b/src/vector.cpp index 1f4c29c..1ba2064 100755 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -323,14 +323,14 @@ Vector& Vector::operator-=(double const v) // Check for equality bool Vector::operator==(Vector const v) { - return (x == v.x && y == v.y && z == v.z ? true : false); + return ((x == v.x) && (y == v.y) && (z == v.z) ? true : false); } // Check for inequality bool Vector::operator!=(Vector const v) { - return (x != v.x || y != v.y || z != v.z ? true : false); + return ((x != v.x) || (y != v.y) || (z != v.z) ? true : false); } @@ -348,7 +348,7 @@ Vector Vector::Unit(void) double Vector::Magnitude(void) { - return sqrt(x * x + y * y + z * z); + return sqrt((x * x) + (y * y) + (z * z)); } @@ -365,17 +365,26 @@ double Vector::Angle(void) // -// Angle between these two vectors +// Returns the smallest angle between these two vectors // double Vector::Angle(Vector v) { +// seems that something relies on this bad behavior... :-P +#if 0 + // Discard the sign from the subtraction + double angle = fabs(Angle() - v.Angle()); + + // Return the complementary angle if greater than 180⁰ + return (angle <= 180.0 ? angle : 360.0 - angle); +#else return Angle() - v.Angle(); +#endif } bool Vector::isZero(double epsilon/*= 1e-6*/) { - return (fabs(x) < epsilon && fabs(y) < epsilon && fabs(z) < epsilon ? true : false); + return ((fabs(x) < epsilon) && (fabs(y) < epsilon) && (fabs(z) < epsilon) ? true : false); } @@ -392,7 +401,7 @@ double Vector::Magnitude(Vector v1, Vector v2) double xx = v1.x - v2.x; double yy = v1.y - v2.y; double zz = v1.z - v2.z; - return sqrt(xx * xx + yy * yy + zz * zz); + return sqrt((xx * xx) + (yy * yy) + (zz * zz)); } #endif diff --git a/src/vector.h b/src/vector.h index 6c46dff..4504fe4 100755 --- a/src/vector.h +++ b/src/vector.h @@ -98,4 +98,5 @@ typedef Vector Point; #endif // __VECTOR_H__ -#endif \ No newline at end of file +#endif + diff --git a/ttedit.pro b/ttedit.pro index 996c9a4..1e86018 100644 --- a/ttedit.pro +++ b/ttedit.pro @@ -9,7 +9,6 @@ HEADERS += src/ttedit.h HEADERS += src/mainwindow.h HEADERS += src/editwindow.h HEADERS += src/glyphpoints.h -HEADERS += src/types.h HEADERS += src/debug.h HEADERS += src/toolwindow.h HEADERS += src/charwindow.h