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