xref: /haiku/src/servers/app/ServerFont.h (revision 079c69cbfd7cd3c97baae91332251c8388a8bb02)
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 			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				SetEncoding(uint32 encoding)
83 									{ fEncoding = encoding; }
84 			void				SetFlags(uint32 value)
85 									{ fFlags = value; }
86 			void				SetSpacing(uint32 value)
87 									{ fSpacing = value; }
88 			void				SetShear(float value)
89 									{ fShear = value; }
90 			void				SetSize(float value)
91 									{ fSize = value; }
92 			void				SetRotation(float value)
93 									{ fRotation = value; }
94 			void				SetFalseBoldWidth(float value)
95 									{ fFalseBoldWidth = value; }
96 			void				SetFace(uint32 face);
97 
98 			bool				IsFixedWidth() const
99 									{ return fStyle->IsFixedWidth(); }
100 			bool				IsScalable() const
101 									{ return fStyle->IsScalable(); }
102 			bool				HasKerning() const
103 									{ return fStyle->HasKerning(); }
104 			bool				HasTuned() const
105 									{ return fStyle->HasTuned(); }
106 			int32				TunedCount() const
107 									{ return fStyle->TunedCount(); }
108 			uint16				GlyphCount() const
109 									{ return fStyle->GlyphCount(); }
110 			uint16				CharMapCount() const
111 									{ return fStyle->CharMapCount(); }
112 
113 
114 			FT_Face				GetTransformedFace(bool rotate,
115 									bool shear) const;
116 			void				PutTransformedFace(FT_Face face) const;
117 
118 			status_t			GetGlyphShapes(const char charArray[],
119 									int32 numChars, BShape *shapeArray[]) const;
120 
121 			status_t			GetHasGlyphs(const char charArray[],
122 									int32 numBytes, bool hasArray[]) const;
123 
124 			status_t			GetEdges(const char charArray[], int32 numBytes,
125 									edge_info edgeArray[]) const;
126 
127 			status_t			GetEscapements(const char charArray[],
128 									int32 numBytes, escapement_delta delta,
129 									BPoint escapementArray[],
130 									BPoint offsetArray[]) const;
131 
132 			status_t			GetEscapements(const char charArray[],
133 									int32 numBytes, escapement_delta delta,
134 									float widthArray[]) const;
135 
136 			status_t			GetBoundingBoxes(const char charArray[],
137 									int32 numBytes, BRect rectArray[],
138 									bool stringEscapement,
139 									font_metric_mode mode,
140 									escapement_delta delta,
141 									bool asString);
142 
143 			status_t			GetBoundingBoxesForStrings(char *charArray[],
144 									int32 lengthArray[], int32 numStrings,
145 									BRect rectArray[], font_metric_mode mode,
146 									escapement_delta deltaArray[]);
147 
148 			float				StringWidth(const char *string,
149 									int32 numBytes,
150 									const escapement_delta* delta = NULL) 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 			Transformable		EmbeddedTransformation() const;
166 
167 protected:
168 	friend class FontStyle;
169 
170 			FontStyle*			fStyle;
171 			float				fSize;
172 			float				fRotation;
173 			float				fShear;
174 			float				fFalseBoldWidth;
175 			BRect				fBounds;
176 			uint32				fFlags;
177 			uint32				fSpacing;
178 			font_direction		fDirection;
179 			uint16				fFace;
180 			uint32				fEncoding;
181 };
182 
183 #endif	/* SERVER_FONT_H */
184