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 <Looper.h> 17 #include <ObjectList.h> 18 19 20 class BEntry; 21 class BPath; 22 struct node_ref; 23 24 25 class FontFamily; 26 class FontStyle; 27 class ServerFont; 28 29 30 /*! 31 \class GlobalFontManager GlobalFontManager.h 32 \brief Manager for system fonts within the font subsystem 33 */ 34 class GlobalFontManager : public FontManager, public BLooper { 35 public: 36 GlobalFontManager(); 37 virtual ~GlobalFontManager(); 38 39 bool Lock() { return BLooper::Lock(); } 40 void Unlock() { BLooper::Unlock(); } 41 bool IsLocked() const { return BLooper::IsLocked(); } 42 43 status_t InitCheck() { return fInitStatus; } 44 45 void SaveRecentFontMappings(); 46 47 virtual void MessageReceived(BMessage* message); 48 49 virtual int32 CountFamilies(); 50 51 virtual int32 CountStyles(const char* family); 52 virtual int32 CountStyles(uint16 familyID); 53 54 const ServerFont* DefaultPlainFont() const; 55 const ServerFont* DefaultBoldFont() const; 56 const ServerFont* DefaultFixedFont() const; 57 58 virtual FontFamily* GetFamily(uint16 familyID) const; 59 virtual FontFamily* GetFamily(const char* name); 60 61 virtual FontStyle* GetStyle(uint16 familyID, uint16 styleID) const; 62 virtual FontStyle* GetStyle(const char* familyName, 63 const char* styleName, 64 uint16 familyID = 0xffff, 65 uint16 styleID = 0xffff, 66 uint16 face = 0); 67 68 virtual uint32 Revision(); 69 70 private: 71 struct font_directory; 72 struct font_mapping; 73 74 void _AddDefaultMapping(const char* family, 75 const char* style, const char* path); 76 bool _LoadRecentFontMappings(); 77 status_t _AddMappedFont(const char* family, 78 const char* style = NULL); 79 void _PrecacheFontFile(const ServerFont* font); 80 void _AddSystemPaths(); 81 void _AddUserPaths(); 82 font_directory* _FindDirectory(node_ref& nodeRef); 83 void _RemoveDirectory(font_directory* directory); 84 status_t _CreateDirectories(const char* path); 85 status_t _AddPath(const char* path); 86 status_t _AddPath(BEntry& entry, 87 font_directory** _newDirectory = NULL); 88 89 void _ScanFontsIfNecessary(); 90 void _ScanFonts(); 91 status_t _ScanFontDirectory(font_directory& directory); 92 status_t _AddFont(font_directory& directory, 93 BEntry& entry); 94 void _RemoveStyle(font_directory& directory, 95 FontStyle* style); 96 void _RemoveStyle(dev_t device, uint64 directory, 97 uint64 node); 98 FontStyle* _GetDefaultStyle(const char* familyName, 99 const char* styleName, 100 const char* fallbackFamily, 101 const char* fallbackStyle, 102 uint16 fallbackFace); 103 status_t _SetDefaultFonts(); 104 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 #endif /* GLOBAL_FONT_MANAGER_H */ 129