The font manager now utilizes a hash table to look up fonts by ID.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14777 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-11-08 16:49:33 +00:00
parent 5f5dfa87e1
commit ec9b3f7ca1
7 changed files with 301 additions and 12 deletions
+22 -1
View File
@@ -19,6 +19,7 @@
#include <ft2build.h>
#include FT_FREETYPE_H
#include "SharedObject.h"
#include "HashTable.h"
class FontFamily;
@@ -39,6 +40,23 @@ enum font_format {
};
class FontKey : public Hashable {
public:
FontKey(uint16 familyID, uint16 styleID)
: fHash(familyID | (styleID << 16UL))
{
}
virtual uint32 Hash() const
{ return fHash; }
virtual bool CompareTo(Hashable& other) const
{ return fHash == other.Hash(); }
private:
uint32 fHash;
};
/*!
\class FontStyle FontFamily.h
\brief Object used to represent a font style
@@ -46,11 +64,14 @@ enum font_format {
FontStyle objects help abstract a lot of the font engine details while
still offering plenty of information the style in question.
*/
class FontStyle : public SharedObject, public BLocker {
class FontStyle : public SharedObject, public Hashable, public BLocker {
public:
FontStyle(const char* path, FT_Face face);
virtual ~FontStyle();
virtual uint32 Hash() const;
virtual bool CompareTo(Hashable& other) const;
/*!
\fn bool FontStyle::IsFixedWidth(void)
\brief Determines whether the font's character width is fixed
+3 -1
View File
@@ -10,9 +10,10 @@
#define FONT_MANAGER_H
#include "HashTable.h"
#include <Looper.h>
#include <ObjectList.h>
#include <SupportDefs.h>
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -85,6 +86,7 @@ class FontManager : public BLooper {
BObjectList<font_directory> fDirectories;
BObjectList<font_mapping> fMappings;
BObjectList<FontFamily> fFamilies;
HashTable fStyleHashTable;
ServerFont *fDefaultFont;
bool fScanned;
int32 fNextID;
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2005, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, [email protected]
*/
#ifndef _HASH_TABLE_H_
#define _HASH_TABLE_H_
#include <SupportDefs.h>
class Hashable {
public:
virtual uint32 Hash() const = 0;
virtual bool CompareTo(Hashable& hashable) const = 0;
};
class HashTable {
public:
HashTable(int32 capacity = 100, float loadFactor = 0.75);
~HashTable();
void MakeEmpty();
bool IsEmpty() const { return fCount == 0; }
bool ContainsKey(Hashable& key) const { return _GetHashEntry(key) != NULL; }
int32 CountItems() const { return fCount; }
Hashable *GetValue(Hashable& key) const;
bool AddItem(Hashable* value);
Hashable *RemoveItem(Hashable& key);
protected:
struct entry;
bool _Rehash();
entry *_GetHashEntry(Hashable& key) const;
entry** fTable;
int32 fCapacity, fCount, fThreshold;
float fLoadFactor;
};
#endif /* HASHTABLE_H */