xref: /haiku/src/servers/app/ServerFont.h (revision 582da17386c4a192ca30270d6b0b95f561cf5843)
1 /*
2  * Copyright 2001-2005, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Jérôme Duval, jerome.duval@free.fr
8  *		Axel Dörfler, axeld@pinc-software.de
9  */
10 #ifndef SERVER_FONT_H
11 #define SERVER_FONT_H
12 
13 
14 #include <Font.h>
15 #include <Rect.h>
16 
17 #include "FontFamily.h"
18 
19 class BShape;
20 class BString;
21 
22 
23 class ServerFont {
24  public:
25 								ServerFont();
26 								ServerFont(FontStyle& style,
27 										   float size = 12.0,
28 										   float rotation = 0.0,
29 										   float shear = 90.0,
30 										   float falseBoldWidth = 0.0,
31 										   uint16 flags = 0,
32 										   uint8 spacing = B_CHAR_SPACING);
33 								ServerFont(const ServerFont& font);
34 	virtual						~ServerFont();
35 
36 			ServerFont			&operator=(const ServerFont& font);
37 
38 			font_direction		Direction() const
39 									{ return fDirection; }
40 			uint32				Encoding() const
41 									{ return fEncoding; }
42 			edge_info			Edges() const
43 									{ return fEdges; }
44 			uint32				Flags() const
45 									{ return fFlags; }
46 			uint32				Spacing() const
47 									{ return fSpacing; }
48 			float				Shear() const
49 									{ return fShear; }
50 			float				Rotation() const
51 									{ return fRotation; }
52 			float				FalseBoldWidth() const
53 									{ return fFalseBoldWidth; }
54 			float				Size() const
55 									{ return fSize; }
56 			uint16				Face() const
57 									{ return fFace; }
58 			uint32				CountGlyphs()
59 									{ return fStyle->GlyphCount(); }
60 			int32				CountTuned();
61 
62 			font_file_format	FileFormat();
63 
64 			const char*			Style() const;
65 			const char*			Family() const;
66 			const char*			Path() const
67 									{ return fStyle->Path(); }
68 
69 			void				SetStyle(FontStyle* style);
70 			status_t			SetFamilyAndStyle(uint16 familyID,
71 												  uint16 styleID);
72 			status_t			SetFamilyAndStyle(uint32 fontID);
73 
74 			uint16				StyleID() const
75 									{ return fStyle->ID(); }
76 			uint16				FamilyID() const
77 									{ return fStyle->Family()->ID(); }
78 			uint32				GetFamilyAndStyle() const;
79 
80 			void				SetDirection(font_direction dir)
81 									{ fDirection = dir; }
82 			void				SetEdges(edge_info info)
83 									{ fEdges = info; }
84 			void				SetEncoding(uint32 encoding)
85 									{ fEncoding = encoding; }
86 			void				SetFlags(uint32 value)
87 									{ fFlags = value; }
88 			void				SetSpacing(uint32 value)
89 									{ fSpacing = value; }
90 			void				SetShear(float value)
91 									{ fShear = value; }
92 			void				SetSize(float value)
93 									{ fSize = value; }
94 			void				SetRotation(float value)
95 									{ fRotation = value; }
96 			void				SetFalseBoldWidth(float value)
97 									{ fFalseBoldWidth = value; }
98 			void				SetFace(uint32 face);
99 
100 			bool				IsFixedWidth() const
101 									{ return fStyle->IsFixedWidth(); }
102 			bool				IsScalable() const
103 									{ return fStyle->IsScalable(); }
104 			bool				HasKerning() const
105 									{ return fStyle->HasKerning(); }
106 			bool				HasTuned() const
107 									{ return fStyle->HasTuned(); }
108 			int32				TunedCount() const
109 									{ return fStyle->TunedCount(); }
110 			uint16				GlyphCount() const
111 									{ return fStyle->GlyphCount(); }
112 			uint16				CharMapCount() const
113 									{ return fStyle->CharMapCount(); }
114 
115 
116 			FT_Face				GetTransformedFace(bool rotate,
117 									bool shear) const;
118 			void				PutTransformedFace(FT_Face face) const;
119 
120 			status_t			GetGlyphShapes(const char charArray[],
121 									int32 numChars, BShape *shapeArray[]) const;
122 
123 			status_t			GetHasGlyphs(const char charArray[],
124 									int32 numChars, bool hasArray[]) const;
125 
126 			status_t			GetEdges(const char charArray[], int32 numChars,
127 									edge_info edgeArray[]) const;
128 
129 			status_t			GetEscapements(const char charArray[],
130 									int32 numChars, escapement_delta delta,
131 									BPoint escapementArray[],
132 									BPoint offsetArray[]) const;
133 
134 			status_t			GetEscapements(const char charArray[],
135 									int32 numChars, escapement_delta delta,
136 									float widthArray[]) const;
137 
138 			status_t			GetBoundingBoxesAsString(const char charArray[],
139 									int32 numChars, BRect rectArray[],
140 									bool stringEscapement,
141 									font_metric_mode mode,
142 									escapement_delta delta);
143 
144 			status_t			GetBoundingBoxesForStrings(char *charArray[],
145 									int32 lengthArray[], int32 numStrings,
146 									BRect rectArray[], font_metric_mode mode,
147 									escapement_delta deltaArray[]);
148 
149 			float				StringWidth(const char *string,
150 									int32 numChars) const;
151 
152 			bool				Lock() const { return fStyle->Lock(); }
153 			void				Unlock() const { fStyle->Unlock(); }
154 
155 			FT_Face				GetFTFace() const
156 									{ return fStyle->FreeTypeFace(); };
157 
158 			BRect				BoundingBox();
159 			void				GetHeight(font_height& height) const;
160 
161 			void				TruncateString(BString* inOut,
162 											   uint32 mode,
163 											   float width) const;
164 
165 protected:
166 	friend class FontStyle;
167 
168 			FontStyle*			fStyle;
169 			edge_info			fEdges;
170 			float				fSize;
171 			float				fRotation;
172 			float				fShear;
173 			float				fFalseBoldWidth;
174 			BRect				fBounds;
175 			uint32				fFlags;
176 			uint32				fSpacing;
177 			font_direction		fDirection;
178 			uint16				fFace;
179 			uint32				fEncoding;
180 };
181 
182 #endif	/* SERVER_FONT_H */
183