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