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 Base class interface used by GlobalFontManager and AppFontManager 35 */ 36 class FontManagerBase : public BLooper { 37 public: 38 FontManagerBase(bool init_freetype, 39 const char* className = "FontManagerBase"); 40 virtual ~FontManagerBase(); 41 42 status_t InitCheck() { return fInitStatus; } 43 void SetInitStatus(status_t new_status) 44 { fInitStatus = new_status; } 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 FontFamily* FamilyAt(int32 index) const; 53 54 virtual FontFamily* GetFamily(uint16 familyID) const; 55 virtual FontFamily* GetFamily(const char* name); 56 57 FontStyle* GetStyleByIndex(const char* family, 58 int32 index); 59 FontStyle* GetStyleByIndex(uint16 familyID, int32 index); 60 61 virtual FontStyle* GetStyle(uint16 familyID, 62 uint16 styleID) const; 63 virtual FontStyle* GetStyle(const char* familyName, 64 const char* styleName, 65 uint16 familyID = 0xffff, 66 uint16 styleID = 0xffff, 67 uint16 face = 0); 68 FontStyle* FindStyleMatchingFace(uint16 face) const; 69 70 void RemoveStyle(FontStyle* style); 71 // This call must not be used by anything else than class 72 // FontStyle. 73 74 75 FT_CharMap _GetSupportedCharmap(const FT_Face& face); 76 77 protected: 78 FontFamily* _FindFamily(const char* family) const; 79 80 static int compare_font_families(const FontFamily* a, 81 const FontFamily* b); 82 83 struct FontKey { 84 FontKey(uint16 family, uint16 style) 85 : familyID(family), styleID(style) {} 86 87 uint32 GetHashCode() const 88 { 89 return familyID | (styleID << 16UL); 90 } 91 92 bool operator==(const FontKey& other) const 93 { 94 return familyID == other.familyID 95 && styleID == other.styleID; 96 } 97 98 uint16 familyID, styleID; 99 }; 100 101 status_t fInitStatus; 102 103 typedef BObjectList<FontFamily> FamilyList; 104 FamilyList fFamilies; 105 106 HashMap<FontKey, BReference<FontStyle> > fStyleHashTable; 107 108 uint16 fNextID; 109 bool fHasFreetypeLibrary; 110 }; 111 112 extern FT_Library gFreeTypeLibrary; 113 114 #endif /* FONT_MANAGER_H */ 115