xref: /haiku/src/servers/app/font/FontManager.h (revision 1e60bdeab63fa7a57bc9a55b032052e95a18bd2c)
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 "HashTable.h"
14 
15 #include <Looper.h>
16 #include <ObjectList.h>
17 
18 #include <ft2build.h>
19 #include FT_FREETYPE_H
20 
21 class BEntry;
22 class BPath;
23 struct node_ref;
24 
25 class FontFamily;
26 class FontStyle;
27 class ServerFont;
28 
29 
30 /*!
31 	\class FontManager FontManager.h
32 	\brief Manager for the largest part of the font subsystem
33 */
34 class FontManager : public BLooper {
35 public:
36 								FontManager();
37 	virtual						~FontManager();
38 
39 			status_t			InitCheck() { return fInitStatus; }
40 			void				SaveRecentFontMappings();
41 
42 	virtual	void				MessageReceived(BMessage* message);
43 
44 			int32				CheckRevision(uid_t user);
45 			int32				CountFamilies();
46 
47 			int32				CountStyles(const char* family);
48 			int32				CountStyles(uint16 familyID);
49 			FontFamily*			FamilyAt(int32 index) const;
50 
51 			FontFamily*			GetFamily(uint16 familyID) const;
52 			FontFamily*			GetFamily(const char* name);
53 
54 			FontStyle*			GetStyleByIndex(const char* family,
55 									int32 index);
56 			FontStyle*			GetStyleByIndex(uint16 familyID, int32 index);
57 			FontStyle*			GetStyle(const char* family, const char* style,
58 									uint16 familyID = 0xffff,
59 									uint16 styleID = 0xffff, uint16 face = 0);
60 			FontStyle*			GetStyle(const char *family, uint16 styleID);
61 			FontStyle*			GetStyle(uint16 familyID,
62 									uint16 styleID) const;
63 			FontStyle*			FindStyleMatchingFace(uint16 face) const;
64 
65 			void				RemoveStyle(FontStyle* style);
66 				// This call must not be used by anything else than class
67 				// FontStyle.
68 
69 			const ServerFont*	DefaultPlainFont() const;
70 			const ServerFont*	DefaultBoldFont() const;
71 			const ServerFont*	DefaultFixedFont() const;
72 
73 			void				AttachUser(uid_t userID);
74 			void				DetachUser(uid_t userID);
75 
76 private:
77 			struct font_directory;
78 			struct font_mapping;
79 
80 			void				_AddDefaultMapping(const char* family,
81 									const char* style, const char* path);
82 			bool				_LoadRecentFontMappings();
83 			status_t			_AddMappedFont(const char* family,
84 									const char* style = NULL);
85 			FontStyle*			_GetDefaultStyle(const char* familyName,
86 									const char* styleName,
87 									const char* fallbackFamily,
88 									const char* fallbackStyle,
89 									uint16 fallbackFace);
90 			status_t			_SetDefaultFonts();
91 			void				_PrecacheFontFile(const ServerFont* font);
92 			void				_AddSystemPaths();
93 			font_directory*		_FindDirectory(node_ref& nodeRef);
94 			void				_RemoveDirectory(font_directory* directory);
95 			status_t			_CreateDirectories(const char* path);
96 			status_t			_AddPath(const char* path);
97 			status_t			_AddPath(BEntry& entry,
98 									font_directory** _newDirectory = NULL);
99 
100 			void				_RemoveStyle(font_directory& directory,
101 									FontStyle* style);
102 			void				_RemoveStyle(dev_t device, uint64 directory,
103 									uint64 node);
104 			FontFamily*			_FindFamily(const char* family) const;
105 
106 			void				_ScanFontsIfNecessary();
107 			void				_ScanFonts();
108 			status_t			_ScanFontDirectory(font_directory& directory);
109 			status_t			_AddFont(font_directory& directory,
110 									BEntry& entry);
111 
112 			FT_CharMap			_GetSupportedCharmap(const FT_Face& face);
113 
114 private:
115 			status_t			fInitStatus;
116 
117 			typedef BObjectList<font_directory>		DirectoryList;
118 			typedef BObjectList<font_mapping>		MappingList;
119 			typedef BObjectList<FontFamily>			FamilyList;
120 
121 			DirectoryList		fDirectories;
122 			MappingList			fMappings;
123 			FamilyList			fFamilies;
124 
125 			HashTable			fStyleHashTable;
126 
127 			ServerFont*			fDefaultPlainFont;
128 			ServerFont*			fDefaultBoldFont;
129 			ServerFont*			fDefaultFixedFont;
130 
131 			bool				fScanned;
132 			int32				fNextID;
133 };
134 
135 extern FT_Library gFreeTypeLibrary;
136 extern FontManager* gFontManager;
137 
138 #endif	/* FONT_MANAGER_H */
139