From: Shamus Hammons Date: Fri, 27 Mar 2009 02:28:49 +0000 (+0000) Subject: Added some functions to GlyphPoints to reduce redundancy in glyph X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=ttedit;a=commitdiff_plain;h=32b6adaf700132ab0910d841b43a0ad343029ce0 Added some functions to GlyphPoints to reduce redundancy in glyph rendering code. Prolly have to do more. :-P --- diff --git a/src/charwindow.cpp b/src/charwindow.cpp index a6da0f9..95965d4 100755 --- a/src/charwindow.cpp +++ b/src/charwindow.cpp @@ -50,44 +50,78 @@ void CharWindow::MakePathFromPoints(GlyphPoints * gp) // Initial move... // If last point is on curve then move to it, otherwise move to first point... - int x, y; - - if (gp->GetOnCurve(poly, gp->GetPrev(poly, 0))) - x = gp->GetX(poly, gp->GetPrev(poly, 0)), - y = gp->GetY(poly, gp->GetPrev(poly, 0)); - else +//NOTE: This is basically doing the below for i=-1. +// Find some way to integrate this crap. +/* +Could do in pairs: get i and i+1, connect them depending on whether the pair +is a line or a curve. +4 cases: on to on (line), + on to off (begin curve), + off to on (end curve), + off to off (begin curve) +*/ +#if 1 + for(int i=0; iGetNumPoints(poly); i++) { - x = (int)gp->GetX(poly, 0), y = (int)gp->GetY(poly, 0); + if (i == 0) + { + IPoint pt = (gp->GetOnCurve(poly, 0) + ? gp->GetPoint(poly, 0) : (gp->GetPrevOnCurve(poly, 0) + ? gp->GetPrevPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0))); + path->moveTo(pt.x, pt.y); + } - if (!gp->GetOnCurve(poly, 0)) + if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(poly, i)) { - IPoint pt = gp->GetMidpointToPrev(poly, 0); - x = pt.x, y = pt.y; + // Handle lines... + path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i)); + } + else + { + // Skip point if it's on curve (start of curve--it's already + // been plotted so we don't care about it... + if (gp->GetOnCurve(poly, i)) + i++; + + // We may have moved past the end; if not, handle curve + if (i < gp->GetNumPoints(poly)) + { + // Handle curves... + IPoint pt = (gp->GetNextOnCurve(poly, i) + ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); + + path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y); + } } } +#else + IPoint pt; - path->moveTo(x, y); + if (gp->GetPrevOnCurve(poly, 0)) + pt = gp->GetPrevPoint(poly, 0); + else + pt = (gp->GetOnCurve(poly, 0) + ? gp->GetPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0)); + + path->moveTo(pt.x, pt.y); for(int i=0; iGetNumPoints(poly); i++) { if (gp->GetOnCurve(poly, i)) - { -// p.drawLine(x, y, gp->GetX(poly, i), gp->GetY(poly, i)); - x = (int)gp->GetX(poly, i), y = (int)gp->GetY(poly, i); - path->lineTo(x, y); - } + path->lineTo(gp->GetX(poly, i), gp->GetY(poly, i)); else { - IPoint pt = (gp->GetOnCurve(poly, gp->GetNext(poly, i)) ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); + pt = (gp->GetNextOnCurve(poly, i) + ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i)); path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y); - x = pt.x, y = pt.y; // If following point is on curve, move past it - if (gp->GetOnCurve(poly, gp->GetNext(poly, i))) + if (gp->GetNextOnCurve(poly, i)) i++; } } +#endif path->closeSubpath(); } @@ -134,11 +168,10 @@ conv.fac. -> (ps.h / r.h) QSize paintSize = size(); p.translate(0, paintSize.height()); -float extraX = 0.0f, extraY = 0.0f; -float xConvFac = (float)paintSize.width() / rect.width(); -float yConvFac = (float)paintSize.height() / rect.height(); + float extraX = 0.0f, extraY = 0.0f; + float xConvFac = (float)paintSize.width() / rect.width(); + float yConvFac = (float)paintSize.height() / rect.height(); -// if (((float)paintSize.width() / rect.width()) > ((float)paintSize.height() / rect.height())) if (xConvFac > yConvFac) { // height is limiting factor @@ -150,11 +183,10 @@ float yConvFac = (float)paintSize.height() / rect.height(); else { // width is limiting factor -// p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.height()); - p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.width()); -extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();// / 2.0f; -extraY = extraY - rect.height(); -extraY /= 2.0f; + p.scale(xConvFac, -xConvFac); +//extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height(); +//extraY = (extraY - rect.height()) / 2.0f; + extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f; } p.translate(-rect.x() + extraX, -rect.y() + extraY); diff --git a/src/glyphpoints.cpp b/src/glyphpoints.cpp index d7ce0d5..0fc62f3 100755 --- a/src/glyphpoints.cpp +++ b/src/glyphpoints.cpp @@ -368,6 +368,11 @@ WriteLogMsg("Exception: GetX(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\x return x[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; } +int GlyphPoints::GetNextX(uint16 poly, uint16 pt) +{ + return GetX(poly, GetNext(poly, pt)); +} + int GlyphPoints::GetY(uint16 poly, uint16 pt) { if (pt >= GetNumPoints(poly)) @@ -383,6 +388,16 @@ WriteLogMsg("Exception: GetY(uint16, uint16). poly= %u, pt=%u, numPoints=%u\xD\x return y[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; } +int GlyphPoints::GetNextY(uint16 poly, uint16 pt) +{ + return GetY(poly, GetNext(poly, pt)); +} + +IPoint GlyphPoints::GetPoint(uint16 poly, uint16 pt) +{ + return IPoint(GetX(poly, pt), GetY(poly, pt)); +} + bool GlyphPoints::GetOnCurve(uint16 poly, uint16 pt) { if (pt >= GetNumPoints(poly)) @@ -398,6 +413,16 @@ WriteLogMsg("Exception: GetOnCurve(uint16, uint16). poly= %u, pt=%u, numPoints=% return onCurve[pt + (poly == 0 ? 0 : polyEnd[poly - 1] + 1)]; } +bool GlyphPoints::GetPrevOnCurve(uint16 poly, uint16 pt) +{ + return GetOnCurve(poly, GetPrev(poly, pt)); +} + +bool GlyphPoints::GetNextOnCurve(uint16 poly, uint16 pt) +{ + return GetOnCurve(poly, GetNext(poly, pt)); +} + uint16 GlyphPoints::GetPolyEnd(uint16 poly) { if (poly >= numPolys) diff --git a/src/glyphpoints.h b/src/glyphpoints.h index 73195e4..fbcf0a8 100755 --- a/src/glyphpoints.h +++ b/src/glyphpoints.h @@ -56,8 +56,13 @@ class GlyphPoints 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); bool GetOnCurve(uint16, uint16); + bool GetPrevOnCurve(uint16, uint16); + bool GetNextOnCurve(uint16, uint16); uint16 GetPolyEnd(uint16); void OffsetPoints(int, int); void OffsetPoly(uint16, int32, int32);