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