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...
55 if (gp->GetOnCurve(poly, gp->GetPrev(poly, 0)))
56 x = gp->GetX(poly, gp->GetPrev(poly, 0)),
57 y = gp->GetY(poly, gp->GetPrev(poly, 0));
60 x = (int)gp->GetX(poly, 0), y = (int)gp->GetY(poly, 0);
62 if (!gp->GetOnCurve(poly, 0))
64 IPoint pt = gp->GetMidpointToPrev(poly, 0);
71 for(int i=0; i<gp->GetNumPoints(poly); i++)
73 if (gp->GetOnCurve(poly, i))
75 // p.drawLine(x, y, gp->GetX(poly, i), gp->GetY(poly, i));
76 x = (int)gp->GetX(poly, i), y = (int)gp->GetY(poly, i);
81 IPoint pt = (gp->GetOnCurve(poly, gp->GetNext(poly, i)) ? gp->GetNextPoint(poly, i) : gp->GetMidpointToNext(poly, i));
83 path->quadTo(gp->GetX(poly, i), gp->GetY(poly, i), pt.x, pt.y);
86 // If following point is on curve, move past it
87 if (gp->GetOnCurve(poly, gp->GetNext(poly, i)))
97 QSize CharWindow::minimumSizeHint() const
102 QSize CharWindow::sizeHint() const
104 return QSize(200, 200);
107 void CharWindow::paintEvent(QPaintEvent * /*event*/)
114 p.setBrush(QColor(122, 163, 39));
115 // Need to translate as well...
116 // p.scale(2.0, 2.0);
119 1.0 -> 3.0, height = 400
120 r.h / ps.h = 2/400 <-- do it the other way!
122 height works, width does not
125 compare aspect ratios
127 ps.w - ((r.h / ps.h) * ps.w)
129 0.5 -> where in the 400? -> 100
130 0.5/r.h(2.0) = 0.25 * ps.h(400) = 100
131 conv.fac. -> (ps.h / r.h)
133 QRectF rect = path->boundingRect();
134 QSize paintSize = size();
136 p.translate(0, paintSize.height());
137 float extraX = 0.0f, extraY = 0.0f;
138 float xConvFac = (float)paintSize.width() / rect.width();
139 float yConvFac = (float)paintSize.height() / rect.height();
141 // if (((float)paintSize.width() / rect.width()) > ((float)paintSize.height() / rect.height()))
142 if (xConvFac > yConvFac)
144 // height is limiting factor
145 p.scale(yConvFac, -yConvFac);
146 //extraX = (rect.height() / (float)paintSize.height()) * (float)paintSize.width();
147 //extraX = (extraX - rect.width()) / 2.0f;
148 extraX = (((float)paintSize.width() / yConvFac) - rect.width()) / 2.0f;
152 // width is limiting factor
153 // p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.height());
154 p.scale((float)paintSize.width() / rect.width(), -(float)paintSize.width() / rect.width());
155 extraY = (rect.width() / (float)paintSize.width()) * (float)paintSize.height();// / 2.0f;
156 extraY = extraY - rect.height();
160 p.translate(-rect.x() + extraX, -rect.y() + extraY);