]> Shamusworld >> Repos - ttedit/commitdiff
Added some functions to GlyphPoints to reduce redundancy in glyph
authorShamus Hammons <jlhamm@acm.org>
Fri, 27 Mar 2009 02:28:49 +0000 (02:28 +0000)
committerShamus Hammons <jlhamm@acm.org>
Fri, 27 Mar 2009 02:28:49 +0000 (02:28 +0000)
rendering code. Prolly have to do more. :-P

src/charwindow.cpp
src/glyphpoints.cpp
src/glyphpoints.h

index a6da0f9ca83f8e2312f5028261068dd7d5895421..95965d4d60f2f5810d5974c8b6e37fcdde7fd155 100755 (executable)
@@ -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; i<gp->GetNumPoints(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; i<gp->GetNumPoints(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);
index d7ce0d5b19d082d629c28aa9f8458142830402e2..0fc62f3cd40af42b8bf2603bc8d5aad7330e2bb2 100755 (executable)
@@ -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)
index 73195e42d4240c3f048fd9428a4bb27388f1e5a4..fbcf0a80008110ea9036378b3321c9111e7b0ae8 100755 (executable)
@@ -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);