[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 38db2c5 4/4: [ftinspect] Start implementation o
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master 38db2c5 4/4: [ftinspect] Start implementation of `showFont'. |
Date: |
Thu, 05 May 2016 08:29:35 +0000 |
branch: master
commit 38db2c5bd02611a7df7d38745345c0a4dc824c86
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Start implementation of `showFont'.
* src/ftinspect.cpp (MainGUI::loadFonts): Call `showFont'.
(MainGUI:closeFont): Fix logic and call `showFont'.
(MainGUI::showFont): New method. Doesn't display something yet, but
font navigation buttons are fully functional now.
(MainGUI::previousFont, MainGUI::nextFont, MainGUI::previousFace,
MainGUI::nextFace, MainGUI::previousInstance,
MainGUI::nextInstance): Call `showFont'.
* src/ftinspect.h (MainGUI): Updated.
---
ChangeLog | 14 ++++++++
src/ftinspect.cpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++------
src/ftinspect.h | 1 +
3 files changed, 100 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index efb8238..add3ea7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2016-05-05 Werner Lemberg <address@hidden>
+ [ftinspect] Start implementation of `showFont'.
+
+ * src/ftinspect.cpp (MainGUI::loadFonts): Call `showFont'.
+ (MainGUI:closeFont): Fix logic and call `showFont'.
+ (MainGUI::showFont): New method. Doesn't display something yet, but
+ font navigation buttons are fully functional now.
+ (MainGUI::previousFont, MainGUI::nextFont, MainGUI::previousFace,
+ MainGUI::nextFace, MainGUI::previousInstance,
+ MainGUI::nextInstance): Call `showFont'.
+
+ * src/ftinspect.h (MainGUI): Updated.
+
+2016-05-05 Werner Lemberg <address@hidden>
+
[ftinspect] Add methods to get number of faces and instances.
* src/ftinspect.cpp (Engine::numFaces, Engine::numInstances): New
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index ec2b157..2170b21 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -270,9 +270,7 @@ MainGUI::loadFonts()
if (oldSize < fonts.size())
currentFontIndex = oldSize;
- checkCurrentFontIndex();
-
- // XXX trigger redisplay
+ showFont();
}
@@ -284,9 +282,79 @@ MainGUI::closeFont()
if (currentFontIndex >= fonts.size())
currentFontIndex--;
- checkCurrentFontIndex();
+ if (currentFontIndex < 0
+ || fonts[currentFontIndex].numInstancesList.isEmpty())
+ {
+ currentFaceIndex = -1;
+ currentInstanceIndex = -1;
+ }
+ else
+ {
+ currentFaceIndex = 0;
+ currentInstanceIndex = 0;
+ }
+
+ showFont();
+}
+
+
+void
+MainGUI::showFont()
+{
+ if (currentFontIndex < 0)
+ return;
+
+ // we do lazy evaluation as much as possible
+
+ Font& font = fonts[currentFontIndex];
- // XXX trigger redisplay
+ // if not yet available, extract the number of faces and indices
+ // for the current font
+
+ if (font.numInstancesList.isEmpty())
+ {
+ int numFaces = engine->numFaces(currentFontIndex);
+
+ if (numFaces > 0)
+ {
+ for (int i = 0; i < numFaces; i++)
+ font.numInstancesList.append(-1);
+
+ currentFaceIndex = 0;
+ currentInstanceIndex = 0;
+ }
+ else
+ {
+ // we use `numInstancesList' with a single element set to zero
+ // to indicate either a non-font or a font FreeType couldn't load;
+ font.numInstancesList.append(0);
+
+ currentFaceIndex = -1;
+ currentInstanceIndex = -1;
+ }
+ }
+
+ // value -1 in `numInstancesList' means `not yet initialized'
+ else if (font.numInstancesList[currentFaceIndex] < 0)
+ {
+ int numInstances = engine->numInstances(currentFontIndex,
+ currentFaceIndex);
+
+ // XXX? we ignore errors
+ if (numInstances < 0)
+ numInstances = 1;
+
+ font.numInstancesList[currentFaceIndex] = numInstances;
+
+ // instance index 0 represents a face without an instance;
+ // consequently, `n' instances are enumerated from 1 to `n'
+ // (instead of having indices 0 to `n-1')
+ currentInstanceIndex = 0;
+ }
+
+ checkCurrentFontIndex();
+ checkCurrentFaceIndex();
+ checkCurrentInstanceIndex();
}
@@ -474,7 +542,9 @@ MainGUI::previousFont()
if (currentFontIndex > 0)
{
currentFontIndex--;
- checkCurrentFontIndex();
+ currentFaceIndex = 0;
+ currentInstanceIndex = 0;
+ showFont();
}
}
@@ -485,7 +555,9 @@ MainGUI::nextFont()
if (currentFontIndex < fonts.size() - 1)
{
currentFontIndex++;
- checkCurrentFontIndex();
+ currentFaceIndex = 0;
+ currentInstanceIndex = 0;
+ showFont();
}
}
@@ -496,7 +568,8 @@ MainGUI::previousFace()
if (currentFaceIndex > 0)
{
currentFaceIndex--;
- checkCurrentFaceIndex();
+ currentInstanceIndex = 0;
+ showFont();
}
}
@@ -509,7 +582,8 @@ MainGUI::nextFace()
if (currentFaceIndex < numFaces - 1)
{
currentFaceIndex++;
- checkCurrentFaceIndex();
+ currentInstanceIndex = 0;
+ showFont();
}
}
@@ -520,7 +594,7 @@ MainGUI::previousInstance()
if (currentInstanceIndex > 0)
{
currentInstanceIndex--;
- checkCurrentInstanceIndex();
+ showFont();
}
}
@@ -534,7 +608,7 @@ MainGUI::nextInstance()
if (currentInstanceIndex < numInstances - 1)
{
currentInstanceIndex++;
- checkCurrentInstanceIndex();
+ showFont();
}
}
diff --git a/src/ftinspect.h b/src/ftinspect.h
index eacc196..61dde19 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -294,6 +294,7 @@ private:
void createStatusBar();
void readSettings();
void setDefaults();
+ void showFont();
void writeSettings();
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 38db2c5 4/4: [ftinspect] Start implementation of `showFont'.,
Werner LEMBERG <=