[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master a5a7922 3/4: [ftinspect] Display glyph points.
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master a5a7922 3/4: [ftinspect] Display glyph points. |
Date: |
Tue, 10 May 2016 03:20:41 +0000 (UTC) |
branch: master
commit a5a79226bcaad246966df889503a693254692ce2
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Display glyph points.
Also fix other minor issues.
* src/ftinspect.cpp (GlyphPoints::GlyphPoints,
GlyphPoints::boundRect, GlyphPoints::paint): New methods for
constructing the set of glyph points.
(MainGUI::checkShowPoints, MainGUI::setGraphicsDefaults): Updated.
(MainGUI::drawGlyph): Honor `glyph outlines' and `glyph points'
check boxes.
(MainGUI::createLayout): Updated.
(MainGUI::createConnections): Handle `showOutlinesCheckBox'.
(GlyphOutline::GlyphOutline): Improve computation of bounding
rectangle.
(Engine::update): Updated.
* src/ftinspect.h (Engine): Remove unused members which are handled
in MainGUI.
(GlyphPoints): New class, derived from `QGraphicsItem'.
(MainGUI): Mew member `currentGlyphPointsItem'.
---
ChangeLog | 24 ++++++++++
src/ftinspect.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++++++++----
src/ftinspect.h | 24 ++++++++--
3 files changed, 173 insertions(+), 13 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 26da596..f413870 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,29 @@
2016-05-09 Werner Lemberg <address@hidden>
+ [ftinspect] Display glyph points.
+
+ Also fix other minor issues.
+
+ * src/ftinspect.cpp (GlyphPoints::GlyphPoints,
+ GlyphPoints::boundRect, GlyphPoints::paint): New methods for
+ constructing the set of glyph points.
+ (MainGUI::checkShowPoints, MainGUI::setGraphicsDefaults): Updated.
+ (MainGUI::drawGlyph): Honor `glyph outlines' and `glyph points'
+ check boxes.
+ (MainGUI::createLayout): Updated.
+ (MainGUI::createConnections): Handle `showOutlinesCheckBox'.
+
+ (GlyphOutline::GlyphOutline): Improve computation of bounding
+ rectangle.
+ (Engine::update): Updated.
+
+ * src/ftinspect.h (Engine): Remove unused members which are handled
+ in MainGUI.
+ (GlyphPoints): New class, derived from `QGraphicsItem'.
+ (MainGUI): Mew member `currentGlyphPointsItem'.
+
+2016-05-09 Werner Lemberg <address@hidden>
+
[ftinspect] Minor.
* src/ftinspect.cpp, src/ftinspect.h: s/loadGlyph/loadOutline/.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index 565a809..b47dd9e 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -405,12 +405,6 @@ Engine::update()
doWarping = gui->warpingCheckBox->isChecked();
showBitmap = gui->showBitmapCheckBox->isChecked();
- showPoints = gui->showPointsCheckBox->isChecked();
- if (showPoints)
- showPointIndices = gui->showPointIndicesCheckBox->isChecked();
- else
- showPointIndices = false;
- showOutlines = gui->showOutlinesCheckBox->isChecked();
gamma = gui->gammaSlider->value();
@@ -621,10 +615,14 @@ GlyphOutline::GlyphOutline(const QPen& outlineP,
{
FT_BBox cbox;
+ qreal halfPenWidth = outlinePen.widthF();
+
FT_Outline_Get_CBox(outline, &cbox);
- bRect.setCoords(qreal(cbox.xMin) / 64, -qreal(cbox.yMax) / 64,
- qreal(cbox.xMax) / 64, -qreal(cbox.yMin) / 64);
+ bRect.setCoords(qreal(cbox.xMin) / 64 - halfPenWidth,
+ -qreal(cbox.yMax) / 64 - halfPenWidth,
+ qreal(cbox.xMax) / 64 + halfPenWidth,
+ -qreal(cbox.yMin) / 64 + halfPenWidth);
}
@@ -649,6 +647,102 @@ GlyphOutline::paint(QPainter* painter,
}
+GlyphPoints::GlyphPoints(const QPen& onP,
+ const QPen& offP,
+ FT_Outline* outln)
+: onPen(onP),
+ offPen(offP),
+ outline(outln)
+{
+ FT_BBox cbox;
+
+ qreal halfPenWidth = qMax(onPen.widthF(), offPen.widthF()) / 2;
+
+ FT_Outline_Get_CBox(outline, &cbox);
+
+ bRect.setCoords(qreal(cbox.xMin) / 64 - halfPenWidth,
+ -qreal(cbox.yMax) / 64 - halfPenWidth,
+ qreal(cbox.xMax) / 64 + halfPenWidth,
+ -qreal(cbox.yMin) / 64 + halfPenWidth);
+}
+
+
+QRectF
+GlyphPoints::boundingRect() const
+{
+ return bRect;
+}
+
+
+void
+GlyphPoints::paint(QPainter* painter,
+ const QStyleOptionGraphicsItem* option,
+ QWidget*)
+{
+ const qreal lod = option->levelOfDetailFromTransform(
+ painter->worldTransform());
+
+ // don't draw points if magnification is too small
+ if (lod >= 5)
+ {
+ // we want the same dot size regardless of the scaling;
+ // for good optical results, the pen widths should be uneven integers
+
+ // interestingly, using `drawPoint' doesn't work as expected:
+ // the larger the zoom, the more horizontally stretched the dot appears
+#if 0
+ qreal origOnPenWidth = onPen.widthF();
+ qreal origOffPenWidth = offPen.widthF();
+
+ onPen.setWidthF(origOnPenWidth / lod);
+ offPen.setWidthF(origOffPenWidth / lod);
+
+ for (int i = 0; i < outline->n_points; i++)
+ {
+ if (outline->tags[i] & FT_CURVE_TAG_ON)
+ painter->setPen(onPen);
+ else
+ painter->setPen(offPen);
+
+ painter->drawPoint(QPointF(qreal(outline->points[i].x) / 64,
+ -qreal(outline->points[i].y) / 64));
+ }
+
+ onPen.setWidthF(origOnPenWidth);
+ offPen.setWidthF(origOffPenWidth);
+#else
+ QBrush onBrush(onPen.color());
+ QBrush offBrush(offPen.color());
+
+ painter->setPen(Qt::NoPen);
+
+ qreal onRadius = onPen.widthF() / lod;
+ qreal offRadius = offPen.widthF() / lod;
+
+ for (int i = 0; i < outline->n_points; i++)
+ {
+ if (outline->tags[i] & FT_CURVE_TAG_ON)
+ {
+ painter->setBrush(onBrush);
+ painter->drawEllipse(QPointF(qreal(outline->points[i].x) / 64,
+ -qreal(outline->points[i].y) / 64),
+ onRadius,
+ onRadius);
+ }
+ else
+ {
+ painter->setBrush(offBrush);
+ painter->drawEllipse(QPointF(qreal(outline->points[i].x) / 64,
+ -qreal(outline->points[i].y) / 64),
+ offRadius,
+ offRadius);
+ }
+ }
+#endif
+ }
+}
+
+
MainGUI::MainGUI()
{
engine = NULL;
@@ -971,6 +1065,8 @@ MainGUI::checkShowPoints()
showPointIndicesCheckBox->setEnabled(true);
else
showPointIndicesCheckBox->setEnabled(false);
+
+ drawGlyph();
}
@@ -1216,7 +1312,9 @@ MainGUI::setGraphicsDefaults()
gridPen.setColor(QColor(192, 192, 192, 255)); // gray
gridPen.setWidth(0);
offPen.setColor(QColor(0, 128, 0, 255)); // dark green
+ offPen.setWidth(3);
onPen.setColor(QColor(255, 0, 0, 255)); // red
+ onPen.setWidth(3);
outlinePen.setColor(QColor(255, 0, 0, 255)); // red
outlinePen.setWidth(0);
segmentPen.setColor(QColor(64, 255, 128, 64)); // light green
@@ -1238,14 +1336,31 @@ MainGUI::drawGlyph()
currentGlyphOutlineItem = NULL;
}
+ if (currentGlyphPointsItem)
+ {
+ glyphScene->removeItem(currentGlyphPointsItem);
+ delete currentGlyphPointsItem;
+
+ currentGlyphPointsItem = NULL;
+ }
+
if (currentFontIndex >= 0
&& currentFaceIndex >= 0)
{
FT_Outline* outline = engine->loadOutline(currentGlyphIndex);
if (outline)
{
- currentGlyphOutlineItem = new GlyphOutline(outlinePen, outline);
- glyphScene->addItem(currentGlyphOutlineItem);
+ if (showOutlinesCheckBox->isChecked())
+ {
+ currentGlyphOutlineItem = new GlyphOutline(outlinePen, outline);
+ glyphScene->addItem(currentGlyphOutlineItem);
+ }
+
+ if (showPointsCheckBox->isChecked())
+ {
+ currentGlyphPointsItem = new GlyphPoints(onPen, offPen, outline);
+ glyphScene->addItem(currentGlyphPointsItem);
+ }
}
}
@@ -1443,6 +1558,7 @@ MainGUI::createLayout()
glyphScene->addItem(new Grid(gridPen, axisPen));
currentGlyphOutlineItem = NULL;
+ currentGlyphPointsItem = NULL;
drawGlyph();
glyphView = new QGraphicsView;
@@ -1580,6 +1696,8 @@ MainGUI::createConnections()
SLOT(checkAutoHinting()));
connect(showPointsCheckBox, SIGNAL(clicked()),
SLOT(checkShowPoints()));
+ connect(showOutlinesCheckBox, SIGNAL(clicked()),
+ SLOT(drawGlyph()));
connect(sizeDoubleSpinBox, SIGNAL(valueChanged(double)),
SLOT(drawGlyph()));
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 24409ea..c0034b6 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -146,9 +146,6 @@ private:
bool doWarping;
bool showBitmap;
- bool showPoints;
- bool showPointIndices;
- bool showOutlines;
double gamma;
@@ -191,6 +188,26 @@ private:
};
+class GlyphPoints
+: public QGraphicsItem
+{
+public:
+ GlyphPoints(const QPen&,
+ const QPen&,
+ FT_Outline*);
+ QRectF boundingRect() const;
+ void paint(QPainter*,
+ const QStyleOptionGraphicsItem*,
+ QWidget*);
+
+private:
+ QPen onPen;
+ QPen offPen;
+ FT_Outline* outline;
+ QRectF bRect;
+};
+
+
// we want to grey out items in a combo box;
// since Qt doesn't provide a function for this we derive a class
class QComboBoxx
@@ -301,6 +318,7 @@ private:
QDoubleSpinBox *sizeDoubleSpinBox;
QGraphicsItem *currentGlyphOutlineItem;
+ QGraphicsItem *currentGlyphPointsItem;
QGraphicsScene *glyphScene;
QGraphicsView *glyphView;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master a5a7922 3/4: [ftinspect] Display glyph points.,
Werner LEMBERG <=