]> Shamusworld >> Repos - ttedit/blobdiff - src/charwindow.cpp
Fix for missing ampersand in QApplication.
[ttedit] / src / charwindow.cpp
index 769c20fe8ff4c52f28bee76a3d1760cba3b03e49..cea3baad3d74f848d94056f22bde8be0444ef3c3 100755 (executable)
@@ -45,86 +45,42 @@ void CharWindow::MakePathFromPoints(GlyphPoints * gp)
 
        for(int poly=0; poly<gp->GetNumPolys(); poly++)
        {
-               if (gp->GetNumPoints(poly) > 2)
+               if (gp->GetNumPoints(poly) < 3)
+                       continue;
+
+               // Initial move: If our start point is on curve, then go to it. Otherwise,
+               // check previous point. If it's on curve, go to it otherwise go the
+               // midpoint between start point and previous (since it's between two curve
+               // control points).
+               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);
+
+               for(int i=0; i<gp->GetNumPoints(poly); i++)
                {
-                       // Initial move...
-                       // If last point is on curve then move to it, otherwise move to first point...
-
-//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++)
-                       {
-                               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, i) && gp->GetNextOnCurve(poly, i))
-                               {
-                                       // 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;
-
-                       if (gp->GetPrevOnCurve(poly, 0))
-                               pt = gp->GetPrevPoint(poly, 0);
+                       // If this point and then next are both on curve, we have a line...
+                       if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(poly, i))
+                               path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i));
                        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++)
                        {
+                               // Skip point if it's on curve (start of curve--it's already
+                               // been plotted so we don't need to handle it...)
                                if (gp->GetOnCurve(poly, i))
-                                       path->lineTo(gp->GetX(poly, i), gp->GetY(poly, i));
-                               else
-                               {
-                                       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);
-
-                                       // If following point is on curve, move past it
-                                       if (gp->GetNextOnCurve(poly, i))
-                                               i++;
-                               }
-                       }
-#endif
+                                       continue;
+
+                               // We are now guaranteed that we are sitting on a curve control point
+                               // (off curve). Figure the extent of the curve: If the following is a
+                               // curve control point, then use the midpoint to it otherwise go to
+                               // the next point since it's on curve.
+                               IPoint pt = (gp->GetNextOnCurve(poly, i)
+                                       ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
 
-                       path->closeSubpath();
+                               path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
+                       }
                }
+
+               path->closeSubpath();
        }
 }
 
@@ -145,28 +101,18 @@ void CharWindow::paintEvent(QPaintEvent * /*event*/)
 
        QPainter p(this);
 
+//     p.setBrush(QColor(0, 163, 200));        // Nice, aqua color...
        p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
-//     p.setBrush(QColor(122, 163, 39));
        p.setBrush(Qt::black);
 
-/*
-1.0 -> 3.0, height = 400
-r.h / ps.h = 2/400 <-- do it the other way!
-
-height works, width does not
-
-2-step process:
-compare aspect ratios
-
-ps.w - ((r.h / ps.h) * ps.w)
-
-0.5 -> where in the 400? -> 100
-0.5/r.h(2.0) = 0.25 * ps.h(400) = 100
-conv.fac. -> (ps.h / r.h)
-*/
        QRectF rect = path->boundingRect();
        QSize paintSize = size();
 
+       // For some reason, this code cuts off two pixels when rendering the path.
+       // Not sure why, but we compensate for that here.
+       paintSize.rwidth() -= 2;
+       paintSize.rheight() -= 2;
+
        p.translate(0, paintSize.height());
        float extraX = 0.0f, extraY = 0.0f;
        float xConvFac = (float)paintSize.width() / rect.width();
@@ -174,13 +120,13 @@ conv.fac. -> (ps.h / r.h)
 
        if (xConvFac > yConvFac)
        {
-               // height is limiting factor
+               // height is limiting factor (smaller than width)
                p.scale(yConvFac, -yConvFac);
                extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f;
        }
        else
        {
-               // width is limiting factor
+               // width is limiting factor (smaller than height)
                p.scale(xConvFac, -xConvFac);
 //extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();
 //extraY = (extraY - rect.height()) / 2.0f;