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)
29 setWindowTitle("Character: Unknown");
32 void CharWindow::MakePathFromPoints(GlyphPoints * gp)
40 path = new QPainterPath();
41 // path->setFillRule(Qt::OddEvenFill);
42 path->setFillRule(Qt::WindingFill);
44 // Draw curve formed by points
46 for(int poly=0; poly<gp->GetNumPolys(); poly++)
48 if (gp->GetNumPoints(poly) > 2)
51 // If last point is on curve then move to it, otherwise move to first point...
53 //NOTE: This is basically doing the below for i=-1.
54 // Find some way to integrate this crap.
56 Could do in pairs: get i and i+1, connect them depending on whether the pair
58 4 cases: on to on (line),
59 on to off (begin curve),
60 off to on (end curve),
61 off to off (begin curve)
64 for(int i=0; i<gp->GetNumPoints(poly); i++)
68 IPoint pt = (gp->GetOnCurve(poly, 0)
69 ? gp->GetPoint(poly, 0) : (gp->GetPrevOnCurve(poly, 0)
70 ? gp->GetPrevPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0)));
71 path->moveTo(pt.x, pt.y);
74 if (gp->GetOnCurve(poly, i) && gp->GetNextOnCurve(poly, i))
77 path->lineTo(gp->GetNextX(poly, i), gp->GetNextY(poly, i));
81 // Skip point if it's on curve (start of curve--it's already
82 // been plotted so we don't care about it...
83 if (gp->GetOnCurve(poly, i))
86 // We may have moved past the end; if not, handle curve
87 if (i < gp->GetNumPoints(poly))
90 IPoint pt = (gp->GetNextOnCurve(poly, i)
91 ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
93 path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
100 if (gp->GetPrevOnCurve(poly, 0))
101 pt = gp->GetPrevPoint(poly, 0);
103 pt = (gp->GetOnCurve(poly, 0)
104 ? gp->GetPoint(poly, 0) : gp->GetMidpointToPrev(poly, 0));
106 path->moveTo(pt.x, pt.y);
108 for(int i=0; i<gp->GetNumPoints(poly); i++)
110 if (gp->GetOnCurve(poly, i))
111 path->lineTo(gp->GetX(poly, i), gp->GetY(poly, i));
114 pt = (gp->GetNextOnCurve(poly, i)
115 ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
117 path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
119 // If following point is on curve, move past it
120 if (gp->GetNextOnCurve(poly, i))
126 path->closeSubpath();
131 QSize CharWindow::minimumSizeHint() const
133 return QSize(50, 50);
136 QSize CharWindow::sizeHint() const
138 return QSize(200, 200);
141 void CharWindow::paintEvent(QPaintEvent * /*event*/)
148 p.setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
149 // p.setBrush(QColor(122, 163, 39));
150 p.setBrush(Qt::black);
153 1.0 -> 3.0, height = 400
154 r.h / ps.h = 2/400 <-- do it the other way!
156 height works, width does not
159 compare aspect ratios
161 ps.w - ((r.h / ps.h) * ps.w)
163 0.5 -> where in the 400? -> 100
164 0.5/r.h(2.0) = 0.25 * ps.h(400) = 100
165 conv.fac. -> (ps.h / r.h)
167 QRectF rect = path->boundingRect();
168 QSize paintSize = size();
170 p.translate(0, paintSize.height());
171 float extraX = 0.0f, extraY = 0.0f;
172 float xConvFac = (float)paintSize.width() / rect.width();
173 float yConvFac = (float)paintSize.height() / rect.height();
175 if (xConvFac > yConvFac)
177 // height is limiting factor
178 p.scale(yConvFac, -yConvFac);
179 extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f;
183 // width is limiting factor
184 p.scale(xConvFac, -xConvFac);
185 //extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();
186 //extraY = (extraY - rect.height()) / 2.0f;
187 extraY = (((float)paintSize.height() / xConvFac) - rect.height()) / 2.0f;
190 p.translate(-rect.x() + extraX, -rect.y() + extraY);