xref: /haiku/src/servers/app/ServerFont.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
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, bool shear) const;
117 			void				PutTransformedFace(FT_Face face) const;
118 
119 			status_t			GetGlyphShapes(const char charArray[],
120 									int32 numChars, BShape *shapeArray[]) const;
121 
122 			status_t			GetHasGlyphs(const char charArray[],
123 									int32 numChars, bool hasArray[]) const;
124 
125 			status_t			GetEdges(const char charArray[],
126 									int32 numChars, edge_info edgeArray[]) const;
127 
128 			status_t			GetEscapements(const char charArray[],
129 									int32 numChars, escapement_delta delta,
130 									BPoint escapementArray[],
131 									BPoint offsetArray[]) const;
132 
133 			status_t			GetEscapements(const char charArray[],
134 									int32 numChars, escapement_delta delta,
135 									float widthArray[]) const;
136 
137 			status_t			GetBoundingBoxesAsString(const char charArray[],
138 									int32 numChars, BRect rectArray[],
139 									bool stringEscapement, font_metric_mode mode,
140 									escapement_delta delta);
141 
142 			status_t			GetBoundingBoxesForStrings(char *charArray[],
143 									int32 lengthArray[], int32 numStrings,
144 									BRect rectArray[], font_metric_mode mode,
145 									escapement_delta deltaArray[]);
146 
147 			float				StringWidth(const char *string, int32 numChars) const;
148 
149 			bool				Lock() const { return fStyle->Lock(); }
150 			void				Unlock() const { fStyle->Unlock(); }
151 
152 			FT_Face				GetFTFace() const
153 									{ return fStyle->FreeTypeFace(); };
154 
155 			BRect				BoundingBox();
156 			void				GetHeight(font_height& height) const;
157 
158 			void				TruncateString(BString* inOut,
159 											   uint32 mode,
160 											   float width) const;
161 
162 protected:
163 	friend class FontStyle;
164 
165 			FontStyle*			fStyle;
166 			edge_info			fEdges;
167 			float				fSize;
168 			float				fRotation;
169 			float				fShear;
170 			float				fFalseBoldWidth;
171 			BRect				fBounds;
172 			uint32				fFlags;
173 			uint32				fSpacing;
174 			font_direction		fDirection;
175 			uint16				fFace;
176 			uint32				fEncoding;
177 };
178 
179 #endif	/* SERVER_FONT_H */
180