[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 448cc83 2/3: [ftinspect] Prepare zoom for drawi
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master 448cc83 2/3: [ftinspect] Prepare zoom for drawing pixel center. |
Date: |
Sun, 29 May 2016 09:02:52 +0000 (UTC) |
branch: master
commit 448cc839c2c186e5009cab8f8186c3af3b27076b
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Prepare zoom for drawing pixel center.
This change makes the zoom use only even values larger than a given
threshold; it also implements (kind of) logarithmic zooming.
* src/ftinspect.h (QSpinBoxx): New class, derived from `QSpinBox'.
(MainGUI): Updated.
* src/ftinspect.cpp (MainGUI::createLayout): Updated.
(QSpinBoxx::valueFromText, QSpinBoxx::stepBy): New methods.
---
ChangeLog | 13 ++++++++
src/ftinspect.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++--
src/ftinspect.h | 14 ++++++++-
3 files changed, 111 insertions(+), 4 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 7d95d02..f109371 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2016-05-29 Werner Lemberg <address@hidden>
+
+ [ftinspect] Prepare zoom for drawing pixel center.
+
+ This change makes the zoom use only even values larger than a given
+ threshold; it also implements (kind of) logarithmic zooming.
+
+ * src/ftinspect.h (QSpinBoxx): New class, derived from `QSpinBox'.
+ (MainGUI): Updated.
+
+ * src/ftinspect.cpp (MainGUI::createLayout): Updated.
+ (QSpinBoxx::valueFromText, QSpinBoxx::stepBy): New methods.
+
2016-05-26 Werner Lemberg <address@hidden>
[ftbench] Add support for third TrueType interpreter version.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index e56785b..edec05c 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -2138,10 +2138,10 @@ MainGUI::createLayout()
zoomLabel = new QLabel(tr("Zoom Factor"));
zoomLabel->setAlignment(Qt::AlignRight);
- zoomSpinBox = new QSpinBox;
+ zoomSpinBox = new QSpinBoxx;
zoomSpinBox->setAlignment(Qt::AlignRight);
- zoomSpinBox->setRange(1, 1000);
- zoomSpinBox->setSingleStep(1);
+ zoomSpinBox->setRange(1, 1000 - 1000 % 64);
+ zoomSpinBox->setKeyboardTracking(false);
zoomLabel->setBuddy(zoomSpinBox);
previousFontButton = new QPushButton(tr("Previous Font"));
@@ -2511,6 +2511,88 @@ QGraphicsViewx::resizeEvent(QResizeEvent* event)
/////////////////////////////////////////////////////////////////////////////
//
+// QSpinBoxx
+//
+/////////////////////////////////////////////////////////////////////////////
+
+// we want to mark the center of a pixel square with a single dot or a small
+// cross; starting with a certain magnification we thus only use even values
+// so that we can do that symmetrically
+
+int
+QSpinBoxx::valueFromText(const QString& text) const
+{
+ int val = QSpinBox::valueFromText(text);
+
+ if (val > 640)
+ val = val - (val % 64);
+ else if (val > 320)
+ val = val - (val % 32);
+ else if (val > 160)
+ val = val - (val % 16);
+ else if (val > 80)
+ val = val - (val % 8);
+ else if (val > 40)
+ val = val - (val % 4);
+ else if (val > 20)
+ val = val - (val % 2);
+
+ return val;
+}
+
+
+void
+QSpinBoxx::stepBy(int steps)
+{
+ int val = value();
+
+ if (steps > 0)
+ {
+ for (int i = 0; i < steps; i++)
+ {
+ if (val >= 640)
+ val = val + 64;
+ else if (val >= 320)
+ val = val + 32;
+ else if (val >= 160)
+ val = val + 16;
+ else if (val >= 80)
+ val = val + 8;
+ else if (val >= 40)
+ val = val + 4;
+ else if (val >= 20)
+ val = val + 2;
+ else
+ val++;
+ }
+ }
+ else if (steps < 0)
+ {
+ for (int i = 0; i < -steps; i++)
+ {
+ if (val > 640)
+ val = val - 64;
+ else if (val > 320)
+ val = val - 32;
+ else if (val > 160)
+ val = val - 16;
+ else if (val > 80)
+ val = val - 8;
+ else if (val > 40)
+ val = val - 4;
+ else if (val > 20)
+ val = val - 2;
+ else
+ val--;
+ }
+ }
+
+ setValue(val);
+}
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
// QComboBoxx
//
/////////////////////////////////////////////////////////////////////////////
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 789f8b3..bf6e9af 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -285,6 +285,18 @@ private:
};
+// we want to have our own `stepBy' function for the zoom spin box
+class QSpinBoxx
+: public QSpinBox
+{
+ Q_OBJECT
+
+public:
+ void stepBy(int);
+ int valueFromText(const QString&) const;
+};
+
+
// 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
@@ -482,7 +494,7 @@ private:
QSlider *gammaSlider;
QSpinBox *dpiSpinBox;
- QSpinBox *zoomSpinBox;
+ QSpinBoxx *zoomSpinBox;
QTabWidget *tabWidget;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 448cc83 2/3: [ftinspect] Prepare zoom for drawing pixel center.,
Werner LEMBERG <=