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 <HashMap.h>
14#include <Node.h>
15#include <ObjectList.h>
16#include <Referenceable.h>
17
18#include <ft2build.h>
19#include FT_FREETYPE_H
20
21
22class FontFamily;
23class FontStyle;
24
25
26/*!
27	\class FontManager FontManager.h
28	\brief Base class interface used by GlobalFontManager and AppFontManager
29*/
30class FontManager {
31public:
32								FontManager();
33	virtual						~FontManager();
34
35	virtual	bool				Lock() = 0;
36	virtual	void				Unlock() = 0;
37	virtual	bool				IsLocked() const = 0;
38
39	virtual	int32				CountFamilies();
40
41	virtual	int32				CountStyles(const char* family);
42	virtual	int32				CountStyles(uint16 familyID);
43			FontFamily*			FamilyAt(int32 index) const;
44
45	virtual	FontFamily*			GetFamily(uint16 familyID) const;
46	virtual	FontFamily*			GetFamily(const char* name);
47
48			FontStyle*			GetStyleByIndex(const char* family,
49									int32 index);
50			FontStyle*			GetStyleByIndex(uint16 familyID, int32 index);
51
52	virtual	FontStyle*			GetStyle(uint16 familyID,
53									uint16 styleID) const;
54	virtual	FontStyle*			GetStyle(const char* familyName,
55									const char* styleName,
56									uint16 familyID = 0xffff,
57									uint16 styleID = 0xffff,
58									uint16 face = 0);
59			FontStyle*			FindStyleMatchingFace(uint16 face) const;
60
61			void				RemoveStyle(FontStyle* style);
62				// This call must not be used by anything else than class
63				// FontStyle.
64
65
66protected:
67			FT_CharMap			_GetSupportedCharmap(const FT_Face& face);
68
69			FontFamily*			_FindFamily(const char* family) const;
70
71			status_t			_AddFont(FT_Face face, node_ref nodeRef,
72									const char* path,
73									uint16& familyID, uint16& styleID);
74			FontStyle*			_RemoveFont(uint16 familyID, uint16 styleID);
75			void				_RemoveAllFonts();
76
77	virtual	uint16				_NextID();
78
79private:
80			struct FontKey {
81				FontKey(uint16 family, uint16 style)
82					: familyID(family), styleID(style) {}
83
84				uint32 GetHashCode() const
85				{
86					return familyID | (styleID << 16UL);
87				}
88
89				bool operator==(const FontKey& other) const
90				{
91					return familyID == other.familyID
92						&& styleID == other.styleID;
93				}
94
95				uint16 familyID, styleID;
96			};
97
98private:
99			typedef BObjectList<FontFamily>			FamilyList;
100			FamilyList			fFamilies;
101
102			HashMap<FontKey, BReference<FontStyle> > fStyleHashTable;
103
104			uint16				fNextID;
105};
106
107#endif	/* FONT_MANAGER_H */
108