1/*
2 * Copyright 2001-2008, 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_STYLE_H_
10#define FONT_STYLE_H_
11
12
13#include <Font.h>
14#include <Locker.h>
15#include <Node.h>
16#include <ObjectList.h>
17#include <Path.h>
18#include <Rect.h>
19#include <Referenceable.h>
20#include <String.h>
21
22#include <ft2build.h>
23#include FT_FREETYPE_H
24
25
26struct node_ref;
27class FontFamily;
28class FontManager;
29class ServerFont;
30
31
32/*!
33	\class FontStyle FontStyle.h
34	\brief Object used to represent a font style
35
36	FontStyle objects help abstract a lot of the font engine details while
37	still offering plenty of information the style in question.
38*/
39class FontStyle : public BReferenceable {
40	public:
41						FontStyle(node_ref& nodeRef, const char* path,
42							FT_Face face, FontManager* fontManager);
43		virtual			~FontStyle();
44
45		const node_ref& NodeRef() const { return fNodeRef; }
46
47		bool			Lock();
48		void			Unlock();
49
50/*!
51	\fn bool FontStyle::IsFixedWidth(void)
52	\brief Determines whether the font's character width is fixed
53	\return true if fixed, false if not
54*/
55		bool			IsFixedWidth() const
56							{ return FT_IS_FIXED_WIDTH(fFreeTypeFace); }
57
58
59/*	\fn bool FontStyle::IsFullAndHalfFixed()
60	\brief Determines whether the font has 2 different, fixed, widths.
61	\return false (for now)
62*/
63		bool			IsFullAndHalfFixed() const
64							{ return fFullAndHalfFixed; };
65
66/*!
67	\fn bool FontStyle::IsScalable(void)
68	\brief Determines whether the font can be scaled to any size
69	\return true if scalable, false if not
70*/
71		bool			IsScalable() const
72							{ return FT_IS_SCALABLE(fFreeTypeFace); }
73/*!
74	\fn bool FontStyle::HasKerning(void)
75	\brief Determines whether the font has kerning information
76	\return true if kerning info is available, false if not
77*/
78		bool			HasKerning() const
79							{ return FT_HAS_KERNING(fFreeTypeFace); }
80/*!
81	\fn bool FontStyle::HasTuned(void)
82	\brief Determines whether the font contains strikes
83	\return true if it has strikes included, false if not
84*/
85		bool			HasTuned() const
86							{ return FT_HAS_FIXED_SIZES(fFreeTypeFace); }
87/*!
88	\fn bool FontStyle::TunedCount(void)
89	\brief Returns the number of strikes the style contains
90	\return The number of strikes the style contains
91*/
92		int32			TunedCount() const
93							{ return fFreeTypeFace->num_fixed_sizes; }
94/*!
95	\fn bool FontStyle::GlyphCount(void)
96	\brief Returns the number of glyphs in the style
97	\return The number of glyphs the style contains
98*/
99		uint16			GlyphCount() const
100							{ return fFreeTypeFace->num_glyphs; }
101/*!
102	\fn bool FontStyle::CharMapCount(void)
103	\brief Returns the number of character maps the style contains
104	\return The number of character maps the style contains
105*/
106		uint16			CharMapCount() const
107							{ return fFreeTypeFace->num_charmaps; }
108
109		const char*		Name() const
110							{ return fName.String(); }
111		FontFamily*		Family() const
112							{ return fFamily; }
113		uint16			ID() const
114							{ return fID; }
115		uint32			Flags() const;
116
117		uint16			Face() const
118							{ return fFace; }
119		uint16			PreservedFace(uint16) const;
120
121		const char*		Path() const;
122		void			UpdatePath(const node_ref& parentNodeRef);
123
124		void			GetHeight(float size, font_height &heigth) const;
125		font_direction	Direction() const
126							{ return B_FONT_LEFT_TO_RIGHT; }
127		font_file_format FileFormat() const
128							{ return B_TRUETYPE_WINDOWS; }
129
130		FT_Face			FreeTypeFace() const
131							{ return fFreeTypeFace; }
132
133		status_t		UpdateFace(FT_Face face);
134
135		FontManager*	Manager() const
136							{ return fFontManager; }
137
138		uint32			FontDataSize() const
139							{ return fFontDataSize; }
140
141		void 			SetFontData(FT_Byte* location, uint32 size);
142		FT_Byte*  		FontData() const
143							{ return fFontData; }
144
145	private:
146		friend class FontFamily;
147		uint16			_TranslateStyleToFace(const char *name) const;
148		void			_SetFontFamily(FontFamily* family, uint16 id);
149	private:
150		FT_Face			fFreeTypeFace;
151		BString			fName;
152		BPath			fPath;
153		node_ref		fNodeRef;
154
155		FontFamily*		fFamily;
156		uint16			fID;
157
158		BRect			fBounds;
159
160		font_height		fHeight;
161		uint16			fFace;
162		bool			fFullAndHalfFixed;
163
164		FT_Byte*		fFontData;
165		uint32			fFontDataSize;
166		FontManager*	fFontManager;
167};
168
169#endif	// FONT_STYLE_H_
170