[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 3d7b276 5/7: [ftinspect] Replace face ID hash w
From: |
Werner LEMBERG |
Subject: |
[freetype2-demos] master 3d7b276 5/7: [ftinspect] Replace face ID hash with a map. |
Date: |
Mon, 16 May 2016 05:56:44 +0000 (UTC) |
branch: master
commit 3d7b276e5be585a74d954d3e5d8942213bc02eb6
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>
[ftinspect] Replace face ID hash with a map.
We need this for later changes that will rely on ordered data.
* src/ftinspect.cpp (FaceID::operator==): Replace with...
(FaceID::operator<): ... this method.
(qHash): Removed.
(faceRequester, Engine::loadFont, Engine::removeFont,
MainGUI::closeFont, MainGUI::showFont): Updated.
* src/ftinspect.h (FaceID): Updated.
(Main): Rename member `faceIDHash' to `faceIDMap'.
---
ChangeLog | 15 +++++++++++++
src/ftinspect.cpp | 63 +++++++++++++++++++++++++++++------------------------
src/ftinspect.h | 16 ++++++--------
3 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 80e6a63..dbbb1ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
2016-05-15 Werner Lemberg <address@hidden>
+ [ftinspect] Replace face ID hash with a map.
+
+ We need this for later changes that will rely on ordered data.
+
+ * src/ftinspect.cpp (FaceID::operator==): Replace with...
+ (FaceID::operator<): ... this method.
+ (qHash): Removed.
+ (faceRequester, Engine::loadFont, Engine::removeFont,
+ MainGUI::closeFont, MainGUI::showFont): Updated.
+
+ * src/ftinspect.h (FaceID): Updated.
+ (Main): Rename member `faceIDHash' to `faceIDMap'.
+
+2016-05-15 Werner Lemberg <address@hidden>
+
[ftinspect] More variable and function renamings.
Mainly for consistency.
diff --git a/src/ftinspect.cpp b/src/ftinspect.cpp
index c1ba7dd..97b87bf 100644
--- a/src/ftinspect.cpp
+++ b/src/ftinspect.cpp
@@ -29,20 +29,24 @@ FaceID::FaceID(int fontIdx,
bool
-FaceID::operator==(const FaceID& other) const
+FaceID::operator<(const FaceID& other) const
{
- return (fontIndex == other.fontIndex
- && faceIndex == other.faceIndex
- && namedInstanceIndex == other.namedInstanceIndex);
-}
+ bool ret = false;
+ if (fontIndex < other.fontIndex)
+ ret = true;
+ else if (fontIndex == other.fontIndex)
+ {
+ if (faceIndex < other.faceIndex)
+ ret = true;
+ else if (faceIndex == other.faceIndex)
+ {
+ if (namedInstanceIndex < other.namedInstanceIndex)
+ ret = true;
+ }
+ }
-uint
-qHash(FaceID key)
-{
- return ((uint)key.fontIndex << 20)
- | ((uint)key.faceIndex << 10)
- | (uint)key.namedInstanceIndex;
+ return ret;
}
@@ -50,9 +54,10 @@ qHash(FaceID key)
// the cache manager to translate an `abstract' face ID into a real
// `FT_Face' object.
//
-// We use a hash: `faceID' is the value, and its associated key gives the
-// font, face, and instance indices. Getting a key from a value is slow,
-// but this must be done only once.
+// We use a map: `faceID' is the value, and its associated key gives the
+// font, face, and named instance indices. Getting a key from a value is
+// slow, but this must be done only once, since `faceRequester' is only
+// called if the font is not yet in the cache.
FT_Error
faceRequester(FTC_FaceID ftcFaceID,
@@ -64,7 +69,7 @@ faceRequester(FTC_FaceID ftcFaceID,
// in C++ it's tricky to convert a void pointer back to an integer
// without warnings related to 32bit vs. 64bit pointer size
int val = static_cast<int>((char*)ftcFaceID - (char*)0);
- const FaceID& faceID = gui->faceIDHash.key(val);
+ const FaceID& faceID = gui->faceIDMap.key(val);
Font& font = gui->fontList[faceID.fontIndex];
int faceIndex = faceID.faceIndex;
@@ -317,12 +322,12 @@ Engine::loadFont(int fontIndex,
fontType = FontType_Other;
scaler.face_id = reinterpret_cast<void*>
- (gui->faceIDHash.value(FaceID(fontIndex,
- faceIndex,
- namedInstanceIndex)));
+ (gui->faceIDMap.value(FaceID(fontIndex,
+ faceIndex,
+ namedInstanceIndex)));
if (scaler.face_id == 0)
{
- // an invalid font, missing in the hash
+ // an invalid font, missing in the map
ftSize = NULL;
curFamilyName = QString();
curStyleName = QString();
@@ -362,9 +367,9 @@ Engine::removeFont(int fontIndex,
int namedInstanceIndex)
{
FTC_FaceID ftcFaceID = reinterpret_cast<void*>
- (gui->faceIDHash.value(FaceID(fontIndex,
- faceIndex,
- namedInstanceIndex)));
+ (gui->faceIDMap.value(FaceID(fontIndex,
+ faceIndex,
+ namedInstanceIndex)));
if (ftcFaceID)
FTC_Manager_RemoveFaceID(cacheManager, ftcFaceID);
}
@@ -1217,7 +1222,7 @@ MainGUI::closeFont()
for (int j = 0; j < list[i]; j++)
{
engine->removeFont(currentFontIndex, i, j);
- faceIDHash.remove(FaceID(currentFontIndex, i, j));
+ faceIDMap.remove(FaceID(currentFontIndex, i, j));
}
fontList.removeAt(currentFontIndex);
@@ -1306,8 +1311,8 @@ MainGUI::showFont(bool preserveIndices)
// assign the (font,face,instance) triplet to a running ID;
// we need this for the `faceRequester' function
for (int i = 0; i < currentNumberOfNamedInstances; i++)
- faceIDHash.insert(FaceID(currentFontIndex, currentFaceIndex, i),
- faceCounter++);
+ faceIDMap.insert(FaceID(currentFontIndex, currentFaceIndex, i),
+ faceCounter++);
// instance index 0 represents a face without an instance;
// consequently, `n' instances are enumerated from 1 to `n'
@@ -1324,15 +1329,15 @@ MainGUI::showFont(bool preserveIndices)
// methods); `engine->loadFont', however, really parses a font
// if the (font,face,instance) triplet is invalid,
- // remove it from the hash
+ // remove it from the map
currentNumberOfGlyphs = engine->loadFont(currentFontIndex,
currentFaceIndex,
currentNamedInstanceIndex);
if (currentNumberOfGlyphs < 0)
{
- faceIDHash.remove(FaceID(currentFontIndex,
- currentFaceIndex,
- currentNamedInstanceIndex));
+ faceIDMap.remove(FaceID(currentFontIndex,
+ currentFaceIndex,
+ currentNamedInstanceIndex));
// XXX improve navigation for fonts with named instances
currentFaceIndex = -1;
diff --git a/src/ftinspect.h b/src/ftinspect.h
index fed0b5d..b591a89 100644
--- a/src/ftinspect.h
+++ b/src/ftinspect.h
@@ -38,6 +38,7 @@
#include <QLabel>
#include <QList>
#include <QMainWindow>
+#include <QMap>
#include <QMenu>
#include <QMenuBar>
#include <QMessageBox>
@@ -67,7 +68,7 @@ class MainGUI;
//
// A valid font contains one or more multiple faces.
// A valid face contains one or more instances.
-// A valid instance gets assigned an entry in MainGUI's `faceIDHash'.
+// A valid instance gets assigned an entry in MainGUI's `faceIDMap'.
//
// An invalid font is marked as having one face but zero instances.
// An invalid face is marked as having -1 instances.
@@ -82,12 +83,11 @@ struct Font
};
-// This structure is used to map the (font,face,instance) index triplet to
+// This structure is used to map the (font, face, instance) index triplet to
// abstract IDs (generated by a running number stored in MainGUI's
// `faceCounter' member).
//
-// Qt's `QHash' class needs an implementation of `==' and a global,
-// overloaded `qHash' function.
+// Qt's `QMap' class needs an implementation of the `<' operator.
struct FaceID
{
@@ -97,11 +97,9 @@ struct FaceID
FaceID();
FaceID(int, int, int);
- bool operator==(const FaceID& other) const;
+ bool operator<(const FaceID& other) const;
};
-uint qHash(FaceID key);
-
// FreeType specific data.
@@ -357,8 +355,8 @@ private:
int currentNumberOfGlyphs;
int currentGlyphIndex;
- int faceCounter; // a running number used to initialize `faceIDHash'
- QHash<FaceID, int> faceIDHash;
+ int faceCounter; // a running number used to initialize `faceIDMap'
+ QMap<FaceID, int> faceIDMap;
int currentCFFHintingMode;
int currentTTInterpreterVersion;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 3d7b276 5/7: [ftinspect] Replace face ID hash with a map.,
Werner LEMBERG <=