xref: /haiku/src/servers/app/font/FontManager.h (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2  * Copyright 2001-2009, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Axel Dörfler, axeld@pinc-software.de
8  */
9 #ifndef FONT_MANAGER_H
10 #define FONT_MANAGER_H
11 
12 
13 #include <HashMap.h>
14 #include <Node.h>
15 #include <ObjectList.h>
16 #include <Referenceable.h>
17 
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 
21 
22 class FontFamily;
23 class FontStyle;
24 
25 
26 /*!
27 	\class FontManager FontManager.h
28 	\brief Base class interface used by GlobalFontManager and AppFontManager
29 */
30 class FontManager {
31 public:
32 								FontManager();
33 	virtual						~FontManager();
34 
35 	virtual	bool				Lock() = 0;
36 	virtual	void				Unlock() = 0;
37 	virtual	bool				IsLocked() const = 0;
38 
39 	virtual	int32				CountFamilies();
40 
41 	virtual	int32				CountStyles(const char* family);
42 	virtual	int32				CountStyles(uint16 familyID);
43 			FontFamily*			FamilyAt(int32 index) const;
44 
45 	virtual	FontFamily*			GetFamily(uint16 familyID) const;
46 	virtual	FontFamily*			GetFamily(const char* name);
47 
48 			FontStyle*			GetStyleByIndex(const char* family,
49 									int32 index);
50 			FontStyle*			GetStyleByIndex(uint16 familyID, int32 index);
51 
52 	virtual	FontStyle*			GetStyle(uint16 familyID,
53 									uint16 styleID) const;
54 	virtual	FontStyle*			GetStyle(const char* familyName,
55 									const char* styleName,
56 									uint16 familyID = 0xffff,
57 									uint16 styleID = 0xffff,
58 									uint16 face = 0);
59 			FontStyle*			FindStyleMatchingFace(uint16 face) const;
60 
61 			void				RemoveStyle(FontStyle* style);
62 				// This call must not be used by anything else than class
63 				// FontStyle.
64 
65 
66 protected:
67 			FT_CharMap			_GetSupportedCharmap(const FT_Face& face);
68 
69 			FontFamily*			_FindFamily(const char* family) const;
70 			FontFamily*			_FindFamily(uint16 familyID) const;
71 
72 			status_t			_AddFont(FT_Face face, node_ref nodeRef,
73 									const char* path,
74 									uint16& familyID, uint16& styleID);
75 			FontStyle*			_RemoveFont(uint16 familyID, uint16 styleID);
76 			void				_RemoveAllFonts();
77 
78 	virtual	uint16				_NextID();
79 
80 private:
81 			struct FontKey {
82 				FontKey()
83 					: familyID(0xffff), styleID(0xffff) {}
84 
85 				FontKey(uint16 family, uint16 style)
86 					: familyID(family), styleID(style) {}
87 
88 				uint32 GetHashCode() const
89 				{
90 					return familyID | (styleID << 16UL);
91 				}
92 
93 				bool operator==(const FontKey& other) const
94 				{
95 					return familyID == other.familyID
96 						&& styleID == other.styleID;
97 				}
98 
99 				uint16 familyID, styleID;
100 			};
101 
102 private:
103 			typedef BObjectList<FontFamily>			FamilyList;
104 			FamilyList			fFamilies;
105 
106 			HashMap<FontKey, BReference<FontStyle> > fStyleHashTable;
107 			HashMap<FontKey, FontStyle*> fDelistedStyleHashTable;
108 
109 			uint16				fNextID;
110 };
111 
112 #endif	/* FONT_MANAGER_H */
113