2 // TTEDIT.CPP - The TrueType Editor
4 // (C) 2004 Underground Software
6 // JLH = James L. Hammons <jlhamm@acm.org>
9 // --- ---------- -------------------------------------------------------------
10 // JLH 08/28/2008 Created this file
11 // JLH 03/19/2009 Converted from wxWidgets to Qt
12 // JLH 03/21/2009 Fixed main screen points rendering
17 // - Render of main window points [DONE]
21 // - Fix "window disappears when tool win comes up" problem
24 #include "charwindow.h"
27 //CharWindow::CharWindow(QWidget * parent/*= NULL*/): QWidget(parent, Qt::Tool), path(NULL)
28 CharWindow::CharWindow(QWidget * parent/*= NULL*/): QWidget(parent, Qt::Window), path(NULL)
30 setWindowTitle("Character: Unknown");
33 void CharWindow::MakePathFromPoints(GlyphPoints * gp)
41 path = new QPainterPath();
42 // path->setFillRule(Qt::OddEvenFill);
43 path->setFillRule(Qt::WindingFill);
45 // Draw curve formed by points
47 for(int poly=0; poly<gp->GetNumPolys(); poly++)
49 if (gp->GetNumPoints(poly) < 3)
52 // Initial move: If our start point is on curve, then go to it. Otherwise,
53 // check previous point. If it's on curve, go to it otherwise go the
54 // midpoint between start point and previous (since it's between two curve
56 IPoint pt = (gp->GetOnCurve(poly, 0)
57 ? gp->GetPoint(poly, 0) : (gp->GetPrevOnCurve(poly, 0)
58 ? gp->GetPrevPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0)));
59 path->moveTo(pt.x, pt.y);
61 for(int i=0; i<gp->GetNumPoints(poly); i++)
63 // If this point and then next are both on curve, we have a line...
64 if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(poly, i))
65 path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i));
68 // Skip point if it's on curve (start of curve--it's already
69 // been plotted so we don't need to handle it...)
70 if (gp->GetOnCurve(poly, i))
73 // We are now guaranteed that we are sitting on a curve control point
74 // (off curve). Figure the extent of the curve: If the following is a
75 // curve control point, then use the midpoint to it otherwise go to
76 // the next point since it's on curve.
77 IPoint pt = (gp->GetNextOnCurve(poly, i)
78 ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
80 path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
88 QSize CharWindow::minimumSizeHint() const
93 QSize CharWindow::sizeHint() const
95 return QSize(200, 200);
98 void CharWindow::paintEvent(QPaintEvent * /*event*/)
105 // p.setBrush(QColor(0, 163, 200)); // Nice, aqua color...
106 p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
107 p.setBrush(Qt::black);
109 QRectF rect = path->boundingRect();
110 QSize paintSize = size();
112 // For some reason, this code cuts off two pixels when rendering the path.
113 // Not sure why, but we compensate for that here.
114 paintSize.rwidth() -= 2;
115 paintSize.rheight() -= 2;
117 p.translate(0, paintSize.height());
118 float extraX = 0.0f, extraY = 0.0f;
119 float xConvFac = (float)paintSize.width() / rect.width();
120 float yConvFac = (float)paintSize.height() / rect.height();
122 if (xConvFac > yConvFac)
124 // height is limiting factor (smaller than width)
125 p.scale(yConvFac, -yConvFac);
126 extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f;
130 // width is limiting factor (smaller than height)
131 p.scale(xConvFac, -xConvFac);
132 //extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();
133 //extraY = (extraY - rect.height()) / 2.0f;
134 extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f;
137 p.translate(-rect.x() + extraX, -rect.y() + extraY);