xref: /haiku/src/servers/app/ServerFont.h (revision a5061ecec55353a5f394759473f1fd6df04890da)
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, float rotation = 0.0,
31 									float shear = 90.0,
32 									float falseBoldWidth = 0.0,
33 									uint16 flags = 0,
34 									uint8 spacing = B_BITMAP_SPACING);
35 								ServerFont(const ServerFont& font);
36 	virtual						~ServerFont();
37 
38 			ServerFont			&operator=(const ServerFont& font);
39 			bool				operator==(const ServerFont& other) const;
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, int32 numChars,
120 									bool hasArray[]) const;
121 
122 			status_t			GetEdges(const char charArray[], int32 numBytes,
123 									int32 numChars, edge_info edgeArray[])
124 									const;
125 
126 			status_t			GetEscapements(const char charArray[],
127 									int32 numBytes, int32 numChars,
128 									escapement_delta delta,
129 									BPoint escapementArray[],
130 									BPoint offsetArray[]) const;
131 
132 			status_t			GetEscapements(const char charArray[],
133 									int32 numBytes, int32 numChars,
134 									escapement_delta delta,
135 									float widthArray[]) const;
136 
137 			status_t			GetBoundingBoxes(const char charArray[],
138 									int32 numBytes, int32 numChars,
139 									BRect rectArray[], bool stringEscapement,
140 									font_metric_mode mode,
141 									escapement_delta delta,
142 									bool asString);
143 
144 			status_t			GetBoundingBoxesForStrings(char *charArray[],
145 									size_t lengthArray[], int32 numStrings,
146 									BRect rectArray[], font_metric_mode mode,
147 									escapement_delta deltaArray[]);
148 
149 			float				StringWidth(const char *string,
150 									int32 numBytes,
151 									const escapement_delta* delta = NULL) const;
152 
153 			bool				Lock() const { return fStyle->Lock(); }
154 			void				Unlock() const { fStyle->Unlock(); }
155 
156 //			FT_Face				GetFTFace() const
157 //									{ return fStyle->FreeTypeFace(); };
158 
159 			BRect				BoundingBox();
160 			void				GetHeight(font_height& height) const;
161 
162 			void				TruncateString(BString* inOut,
163 									uint32 mode, float width) const;
164 
165 			Transformable		EmbeddedTransformation() const;
166 			status_t			GetUnicodeBlocks(unicode_block &blocksForFont);
167 			status_t			IncludesUnicodeBlock(uint32 start, uint32 end,
168 									bool &hasBlock);
169 
170 protected:
171 	friend class FontStyle;
172 			FT_Face				GetTransformedFace(bool rotate,
173 									bool shear) const;
174 			void				PutTransformedFace(FT_Face face) const;
175 
176 			BReference<FontStyle>
177 								fStyle;
178 			float				fSize;
179 			float				fRotation;
180 			float				fShear;
181 			float				fFalseBoldWidth;
182 			BRect				fBounds;
183 			uint32				fFlags;
184 			uint32				fSpacing;
185 			font_direction		fDirection;
186 			uint16				fFace;
187 			uint32				fEncoding;
188 };
189 
190 inline bool ServerFont::Hinting() const
191 {
192 	switch (gDefaultHintingMode) {
193 		case HINTING_MODE_OFF:
194 			return false;
195 		default:
196 		case HINTING_MODE_ON:
197 			return true;
198 		case HINTING_MODE_MONOSPACED_ONLY:
199 			return IsFixedWidth();
200 	}
201 }
202 
203 #endif	/* SERVER_FONT_H */
204