xref: /haiku/src/servers/app/font/FontManager.h (revision 909af08f4328301fbdef1ffb41f566c3b5bec0c7)
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 	virtual	uint32				Revision();
66 
67 
68 protected:
69 			FT_CharMap			_GetSupportedCharmap(const FT_Face& face);
70 
71 			FontFamily*			_FindFamily(const char* family) const;
72 			FontFamily*			_FindFamily(uint16 familyID) const;
73 
74 			status_t			_AddFont(FT_Face face, node_ref nodeRef,
75 									const char* path,
76 									uint16& familyID, uint16& styleID);
77 			FontStyle*			_RemoveFont(uint16 familyID, uint16 styleID);
78 			void				_RemoveAllFonts();
79 
80 	virtual	uint16				_NextID();
81 
82 private:
83 			struct FontKey {
84 				FontKey()
85 					: familyID(0xffff), styleID(0xffff) {}
86 
87 				FontKey(uint16 family, uint16 style)
88 					: familyID(family), styleID(style) {}
89 
90 				uint32 GetHashCode() const
91 				{
92 					return familyID | (styleID << 16UL);
93 				}
94 
95 				bool operator==(const FontKey& other) const
96 				{
97 					return familyID == other.familyID
98 						&& styleID == other.styleID;
99 				}
100 
101 				uint16 familyID, styleID;
102 			};
103 
104 private:
105 			typedef BObjectList<FontFamily>			FamilyList;
106 			FamilyList			fFamilies;
107 
108 			HashMap<FontKey, BReference<FontStyle> > fStyleHashTable;
109 			HashMap<FontKey, FontStyle*> fDelistedStyleHashTable;
110 
111 			uint32				fRevision;
112 			uint16				fNextID;
113 };
114 
115 #endif	/* FONT_MANAGER_H */
116