[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 2590945 4/4: [ftinspect] Really load fonts.
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master 2590945 4/4: [ftinspect] Really load fonts. |
Date: |
Sat, 7 May 2016 15:36:10 +0000 (UTC) |
branch: master
commit 2590945d54dc9f45aa90f83efa8d09c7da85b5d0
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Really load fonts.
* src/ftinspect.cpp (Engine::loadFont, Engine::removeFont): New
methods.
(Engine::update): Set font-independent scaler values.
(MainGUI::closeFont): Remove font ID from hash and font from cache.
(MainGUI::showFOnt): Call `loadFont'.
(MainGUI::setDefaults): Set initial value of `faceCounter' to 1 to
circumvent a FreeType buglet.
* src/ftinspect.h (Engine): New `scaler' and `ftSize' members.
Updated.
(MainGUI): New member `currentNumGlyphs'.
---
ChangeLog | 16 +++++++++++
src/ftinspect.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/ftinspect.h | 8 +++++-
3 files changed, 104 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9556772..737f74c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
2016-05-07 Werner Lemberg <address@hidden>
+ [ftinspect] Really load fonts.
+
+ * src/ftinspect.cpp (Engine::loadFont, Engine::removeFont): New
+ methods.
+ (Engine::update): Set font-independent scaler values.
+ (MainGUI::closeFont): Remove font ID from hash and font from cache.
+ (MainGUI::showFOnt): Call `loadFont'.
+ (MainGUI::setDefaults): Set initial value of `faceCounter' to 1 to
+ circumvent a FreeType buglet.
+
+ * src/ftinspect.h (Engine): New `scaler' and `ftSize' members.
+ Updated.
+ (MainGUI): New member `currentNumGlyphs'.
+
+2016-05-07 Werner Lemberg <address@hidden>
+
* src/ftinspect.cpp (MainGUI::showFont): Another logic fix.
2016-05-07 Werner Lemberg <address@hidden>
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index 25998f7..b615474 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -308,6 +308,40 @@ Engine::numInstances(int fontIndex,
}
+int
+Engine::loadFont(int fontIndex,
+ int faceIndex,
+ int instanceIndex)
+{
+ scaler.face_id = reinterpret_cast<void*>
+ (gui->faceIDHash.value(FaceID(fontIndex,
+ faceIndex,
+ instanceIndex)));
+
+ FT_Error error = FTC_Manager_LookupSize(cacheManager, &scaler, &ftSize);
+ if (error)
+ {
+ // XXX error handling
+ return -1;
+ }
+
+ return ftSize->face->num_glyphs;
+}
+
+
+void
+Engine::removeFont(int fontIndex,
+ int faceIndex,
+ int instanceIndex)
+{
+ FTC_FaceID face_id = reinterpret_cast<void*>
+ (gui->faceIDHash.value(FaceID(fontIndex,
+ faceIndex,
+ instanceIndex)));
+ FTC_Manager_RemoveFaceID(cacheManager, face_id);
+}
+
+
void
Engine::update()
{
@@ -391,6 +425,25 @@ Engine::update()
}
// XXX handle color fonts also
+
+ scaler.pixel = 0; // use 26.6 format
+
+ if (gui->unitsComboBox->currentIndex() == MainGUI::Units_px)
+ {
+ scaler.width = int(pixelSize * 64.0);
+ scaler.height = int(pixelSize * 64.0);
+ scaler.x_res = 0;
+ scaler.y_res = 0;
+ }
+ else
+ {
+ scaler.width = int(pointSize * 64.0);
+ scaler.height = int(pointSize * 64.0);
+ scaler.x_res = dpi;
+ scaler.y_res = dpi;
+ }
+
+
}
@@ -486,7 +539,16 @@ void
MainGUI::closeFont()
{
if (currentFontIndex >= 0)
+ {
+ for (int i = 0; i < fonts[currentFontIndex].numInstancesList.size(); i++)
+ for (int j = 0; j < fonts[currentFontIndex].numInstancesList[i]; j++)
+ {
+ faceIDHash.remove(FaceID(currentFontIndex, i, j));
+ engine->removeFont(currentFontIndex, i, j);
+ }
+
fonts.removeAt(currentFontIndex);
+ }
if (currentFontIndex >= fonts.size())
currentFontIndex--;
@@ -565,6 +627,23 @@ MainGUI::showFont()
// (instead of having indices 0 to `n-1')
currentInstanceIndex = 0;
}
+
+ if (currentFaceIndex >= 0)
+ {
+ // up to now we only called for rudimentary font handling
+ // (via the `engine->numFaces' and `engine->numInstances' methods);
+ // `engine->loadFont', however, really parses a font
+
+ // if the (font,face,instance) triplet is invalid,
+ // remove it from the hash
+ int currentNumGlyphs = engine->loadFont(currentFontIndex,
+ currentFaceIndex,
+ currentInstanceIndex);
+ if (currentNumGlyphs < 0)
+ faceIDHash.remove(FaceID(currentFontIndex,
+ currentFaceIndex,
+ currentInstanceIndex));
+ }
}
checkCurrentFontIndex();
@@ -1264,7 +1343,8 @@ MainGUI::clearStatusBar()
void
MainGUI::setDefaults()
{
- faceCounter = 0;
+ // starting value 0 only works with FreeType 2.6.4 or newer
+ faceCounter = 1;
// set up mappings between property values and combo box indices
hintingModesTrueTypeHash[TT_INTERPRETER_VERSION_35] =
HintingMode_TrueType_v35;
diff --git a/src/ftinspect.h b/src/ftinspect.h
index 133b65c..95d0736 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -96,9 +96,11 @@ public:
Engine(MainGUI*);
~Engine();
- void update();
int numFaces(int);
int numInstances(int, int);
+ int loadFont(int, int, int); // returns number of glyphs
+ void removeFont(int, int, int);
+ void update();
friend class MainGUI;
@@ -110,6 +112,9 @@ private:
FTC_ImageCache imageCache;
FTC_SBitCache sbitsCache;
+ FTC_ScalerRec scaler;
+ FT_Size ftSize;
+
int cffHintingEngineDefault;
int cffHintingEngineOther;
@@ -216,6 +221,7 @@ private:
int currentFontIndex;
int currentFaceIndex;
int currentInstanceIndex;
+ int currentNumGlyphs;
int faceCounter; // a running number used to initialize `faceIDHash'
QHash<FaceID, int> faceIDHash;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 2590945 4/4: [ftinspect] Really load fonts.,
Werner LEMBERG <=