freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master d8fc14b: [ftinspect] Make glyph navigation work


From: Werner LEMBERG
Subject: [freetype2-demos] master d8fc14b: [ftinspect] Make glyph navigation work.
Date: Sat, 7 May 2016 16:44:53 +0000 (UTC)

branch: master
commit d8fc14bac83925b4ff3eac2bbba905f1f9bfc042
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [ftinspect] Make glyph navigation work.
    
    * src/ftinspect.cpp (MainGUI::showFont): Don't use local variable.
    (MainGUI::adjustGlyphIndex): New method.
    (MainGUI::createConnections): Use `QSignalMapper' class to map all
    navigation button signals to a single receiver function (namely
    `adjustGlyphIndex').
    (MainGUI::setDefaults): Updated.
    
    * src/ftinspect.h (MainGUI): New `currentGlyphIndex' member.
    Updated.
---
 ChangeLog         |   14 ++++++++++++
 src/ftinspect.cpp |   63 +++++++++++++++++++++++++++++++++++++++++++++++++----
 src/ftinspect.h   |    6 +++++
 3 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 737f74c..5c662f5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2016-05-07  Werner Lemberg  <address@hidden>
 
+       [ftinspect] Make glyph navigation work.
+
+       * src/ftinspect.cpp (MainGUI::showFont): Don't use local variable.
+       (MainGUI::adjustGlyphIndex): New method.
+       (MainGUI::createConnections): Use `QSignalMapper' class to map all
+       navigation button signals to a single receiver function (namely
+       `adjustGlyphIndex').
+       (MainGUI::setDefaults): Updated.
+
+       * src/ftinspect.h (MainGUI): New `currentGlyphIndex' member.
+       Updated.
+
+2016-05-07  Werner Lemberg  <address@hidden>
+
        [ftinspect] Really load fonts.
 
        * src/ftinspect.cpp (Engine::loadFont, Engine::removeFont): New
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index b615474..312edf6 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -636,9 +636,9 @@ MainGUI::showFont()
 
       // if the (font,face,instance) triplet is invalid,
       // remove it from the hash
-      int currentNumGlyphs = engine->loadFont(currentFontIndex,
-                                              currentFaceIndex,
-                                              currentInstanceIndex);
+      currentNumGlyphs = engine->loadFont(currentFontIndex,
+                                          currentFaceIndex,
+                                          currentInstanceIndex);
       if (currentNumGlyphs < 0)
         faceIDHash.remove(FaceID(currentFontIndex,
                                  currentFaceIndex,
@@ -779,6 +779,21 @@ MainGUI::checkUnits()
 
 
 void
+MainGUI::adjustGlyphIndex(int delta)
+{
+  // don't adjust current glyph index if we have an invalid font
+  if (currentFaceIndex < 0 || currentNumGlyphs < 0)
+    return;
+
+  currentGlyphIndex += delta;
+  if (currentGlyphIndex < 0)
+    currentGlyphIndex = 0;
+  else if (currentGlyphIndex >= currentNumGlyphs)
+    currentGlyphIndex = currentNumGlyphs - 1;
+}
+
+
+void
 MainGUI::checkCurrentFontIndex()
 {
   if (fonts.size() < 2)
@@ -1285,6 +1300,42 @@ MainGUI::createConnections()
           SLOT(previousInstance()));
   connect(nextInstanceButton, SIGNAL(clicked()),
           SLOT(nextInstance()));
+
+  glyphNavigationMapper = new QSignalMapper;
+  connect(glyphNavigationMapper, SIGNAL(mapped(int)),
+          SLOT(adjustGlyphIndex(int)));
+
+  connect(toStartButtonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toM1000Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toM100Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toM10Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toM1Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toP1Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toP10Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toP100Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toP1000Buttonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+  connect(toEndButtonx, SIGNAL(clicked()),
+          glyphNavigationMapper, SLOT(map()));
+
+  glyphNavigationMapper->setMapping(toStartButtonx, -0x10000);
+  glyphNavigationMapper->setMapping(toM1000Buttonx, -1000);
+  glyphNavigationMapper->setMapping(toM100Buttonx, -100);
+  glyphNavigationMapper->setMapping(toM10Buttonx, -10);
+  glyphNavigationMapper->setMapping(toM1Buttonx, -1);
+  glyphNavigationMapper->setMapping(toP1Buttonx, 1);
+  glyphNavigationMapper->setMapping(toP10Buttonx, 10);
+  glyphNavigationMapper->setMapping(toP100Buttonx, 100);
+  glyphNavigationMapper->setMapping(toP1000Buttonx, 1000);
+  glyphNavigationMapper->setMapping(toEndButtonx, 0x10000);
 }
 
 
@@ -1343,7 +1394,8 @@ MainGUI::clearStatusBar()
 void
 MainGUI::setDefaults()
 {
-  // starting value 0 only works with FreeType 2.6.4 or newer
+  // starting value 0 for a cache's face ID
+  // only works with FreeType 2.6.4 or newer
   faceCounter = 1;
 
   // set up mappings between property values and combo box indices
@@ -1387,6 +1439,9 @@ MainGUI::setDefaults()
   currentFaceIndex = -1;
   currentInstanceIndex = -1;
 
+  currentNumGlyphs = -1;
+  currentGlyphIndex = 0;
+
   hintingCheckBox->setChecked(true);
 
   hintingModeComboBoxx->setCurrentIndex(HintingMode_TrueType_v35);
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 95d0736..57a2c0f 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -33,6 +33,7 @@
 #include <QMessageBox>
 #include <QPushButton>
 #include <QSettings>
+#include <QSignalMapper>
 #include <QSizePolicy>
 #include <QSlider>
 #include <QSpinBox>
@@ -195,6 +196,7 @@ protected:
 
 private slots:
   void about();
+  void adjustGlyphIndex(int);
   void checkAntiAliasing();
   void checkAutoHinting();
   void checkCurrentFaceIndex();
@@ -221,7 +223,9 @@ private:
   int currentFontIndex;
   int currentFaceIndex;
   int currentInstanceIndex;
+
   int currentNumGlyphs;
+  int currentGlyphIndex;
 
   int faceCounter; // a running number used to initialize `faceIDHash'
   QHash<FaceID, int> faceIDHash;
@@ -309,6 +313,8 @@ private:
   QPushButtonx *toP1Buttonx;
   QPushButtonx *toStartButtonx;
 
+  QSignalMapper *glyphNavigationMapper;
+
   QSlider *gammaSlider;
 
   QSpinBox *dpiSpinBox;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]