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