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