Make UEFI boot-platform build again
[haiku.git] / headers / os / interface / Font.h
blob5277950a0d912a51d571f1b93f298ff29451648a
1 /*
2 * Copyright 2005-2016, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef _FONT_H_
6 #define _FONT_H_
9 #include <SupportDefs.h>
10 #include <InterfaceDefs.h>
13 class BPoint;
16 #define B_FONT_FAMILY_LENGTH 63
17 #define B_FONT_STYLE_LENGTH 63
18 typedef char font_family[B_FONT_FAMILY_LENGTH + 1];
19 typedef char font_style[B_FONT_STYLE_LENGTH + 1];
22 // font spacing
23 enum {
24 B_CHAR_SPACING = 0,
25 B_STRING_SPACING = 1,
26 B_BITMAP_SPACING = 2,
27 B_FIXED_SPACING = 3
31 enum font_direction {
32 B_FONT_LEFT_TO_RIGHT = 0,
33 B_FONT_RIGHT_TO_LEFT = 1
37 // font flags
38 enum {
39 B_DISABLE_ANTIALIASING = 0x00000001,
40 B_FORCE_ANTIALIASING = 0x00000002
44 // truncation modes
45 enum {
46 B_NO_TRUNCATION = ~0U,
47 B_TRUNCATE_END = 0,
48 B_TRUNCATE_BEGINNING = 1,
49 B_TRUNCATE_MIDDLE = 2,
50 B_TRUNCATE_SMART = 3
54 // font encodings
55 enum {
56 B_UNICODE_UTF8 = 0,
57 B_ISO_8859_1 = 1,
58 B_ISO_8859_2 = 2,
59 B_ISO_8859_3 = 3,
60 B_ISO_8859_4 = 4,
61 B_ISO_8859_5 = 5,
62 B_ISO_8859_6 = 6,
63 B_ISO_8859_7 = 7,
64 B_ISO_8859_8 = 8,
65 B_ISO_8859_9 = 9,
66 B_ISO_8859_10 = 10,
67 B_MACINTOSH_ROMAN = 11
71 // flags for get_font_family() and get_font_style()
72 enum {
73 B_HAS_TUNED_FONT = 0x0001,
74 B_IS_FIXED = 0x0002
78 // font face flags
79 enum {
80 B_ITALIC_FACE = 0x0001,
81 B_UNDERSCORE_FACE = 0x0002,
82 B_NEGATIVE_FACE = 0x0004,
83 B_OUTLINED_FACE = 0x0008,
84 B_STRIKEOUT_FACE = 0x0010,
85 B_BOLD_FACE = 0x0020,
86 B_REGULAR_FACE = 0x0040,
87 // new in Haiku:
88 B_CONDENSED_FACE = 0x0080,
89 B_LIGHT_FACE = 0x0100,
90 B_HEAVY_FACE = 0x0200,
94 enum font_metric_mode {
95 B_SCREEN_METRIC = 0,
96 B_PRINTING_METRIC = 1
100 enum font_file_format {
101 B_TRUETYPE_WINDOWS = 0,
102 B_POSTSCRIPT_TYPE1_WINDOWS = 1
106 class unicode_block {
107 public:
108 inline unicode_block();
109 inline unicode_block(uint64 block2, uint64 block1);
111 inline bool Includes(const unicode_block& block) const;
112 inline unicode_block operator&(const unicode_block& block) const;
113 inline unicode_block operator|(const unicode_block& block) const;
114 inline unicode_block& operator=(const unicode_block& block);
115 inline bool operator==(const unicode_block& block) const;
116 inline bool operator!=(const unicode_block& block) const;
118 private:
119 uint64 fData[2];
123 struct unicode_block_range {
124 uint32 start;
125 uint32 end;
126 const unicode_block& block;
128 uint32 Count() const { return end + 1 - start; }
132 struct edge_info {
133 float left;
134 float right;
138 struct font_height {
139 float ascent;
140 float descent;
141 float leading;
145 struct escapement_delta {
146 float nonspace;
147 float space;
151 struct font_cache_info {
152 int32 sheared_font_penalty;
153 int32 rotated_font_penalty;
154 float oversize_threshold;
155 int32 oversize_penalty;
156 int32 cache_size;
157 float spacing_size_threshold;
161 struct tuned_font_info {
162 float size;
163 float shear;
164 float rotation;
165 uint32 flags;
166 uint16 face;
170 class BShape;
171 class BString;
172 class BFontPrivate;
175 class BFont {
176 public:
177 BFont();
178 BFont(const BFont& font);
179 BFont(const BFont* font);
181 status_t SetFamilyAndStyle(const font_family family,
182 const font_style style);
183 void SetFamilyAndStyle(uint32 code);
184 status_t SetFamilyAndFace(const font_family family,
185 uint16 face);
187 void SetSize(float size);
188 void SetShear(float shear);
189 void SetRotation(float rotation);
190 void SetFalseBoldWidth(float width);
191 void SetSpacing(uint8 spacing);
192 void SetEncoding(uint8 encoding);
193 void SetFace(uint16 face);
194 void SetFlags(uint32 flags);
196 void GetFamilyAndStyle(font_family* family,
197 font_style* style) const;
198 uint32 FamilyAndStyle() const;
199 float Size() const;
200 float Shear() const;
201 float Rotation() const;
202 float FalseBoldWidth() const;
203 uint8 Spacing() const;
204 uint8 Encoding() const;
205 uint16 Face() const;
206 uint32 Flags() const;
208 font_direction Direction() const;
209 bool IsFixed() const;
210 bool IsFullAndHalfFixed() const;
211 BRect BoundingBox() const;
212 unicode_block Blocks() const;
213 bool IncludesBlock(uint32 start, uint32 end) const;
214 font_file_format FileFormat() const;
216 int32 CountTuned() const;
217 void GetTunedInfo(int32 index,
218 tuned_font_info* info) const;
220 void TruncateString(BString* inOut, uint32 mode,
221 float width) const;
222 void GetTruncatedStrings(const char* stringArray[],
223 int32 numStrings, uint32 mode, float width,
224 BString resultArray[]) const;
225 void GetTruncatedStrings(const char* stringArray[],
226 int32 numStrings, uint32 mode,
227 float width, char* resultArray[]) const;
229 float StringWidth(const char* string) const;
230 float StringWidth(const char* string,
231 int32 length) const;
232 void GetStringWidths(const char* stringArray[],
233 const int32 lengthArray[],
234 int32 numStrings,
235 float widthArray[]) const;
237 void GetEscapements(const char charArray[],
238 int32 numChars,
239 float escapementArray[]) const;
240 void GetEscapements(const char charArray[],
241 int32 numChars, escapement_delta* delta,
242 float escapementArray[]) const;
243 void GetEscapements(const char charArray[],
244 int32 numChars, escapement_delta* delta,
245 BPoint escapementArray[]) const;
246 void GetEscapements(const char charArray[],
247 int32 numChars, escapement_delta* delta,
248 BPoint escapementArray[],
249 BPoint offsetArray[]) const;
251 void GetEdges(const char charArray[],
252 int32 numBytes,
253 edge_info edgeArray[]) const;
254 void GetHeight(font_height* height) const;
256 void GetBoundingBoxesAsGlyphs(
257 const char charArray[], int32 numChars,
258 font_metric_mode mode,
259 BRect boundingBoxArray[]) const;
260 void GetBoundingBoxesAsString(
261 const char charArray[], int32 numChars,
262 font_metric_mode mode,
263 escapement_delta* delta,
264 BRect boundingBoxArray[]) const;
265 void GetBoundingBoxesForStrings(
266 const char* stringArray[],
267 int32 numStrings, font_metric_mode mode,
268 escapement_delta deltas[],
269 BRect boundingBoxArray[]) const;
271 void GetGlyphShapes(const char charArray[],
272 int32 numChars,
273 BShape* glyphShapeArray[]) const;
275 void GetHasGlyphs(const char charArray[],
276 int32 numChars,
277 bool hasArray[]) const;
279 BFont& operator=(const BFont& font);
280 bool operator==(const BFont& font) const;
281 bool operator!=(const BFont& font) const;
283 void PrintToStream() const;
285 private:
286 friend void _init_global_fonts_();
288 void _GetExtraFlags() const;
289 void _GetBoundingBoxes(const char charArray[],
290 int32 numChars, font_metric_mode mode,
291 bool string_escapement,
292 escapement_delta* delta,
293 BRect boundingBoxArray[],
294 bool asString) const;
296 private:
297 uint16 fFamilyID;
298 uint16 fStyleID;
299 float fSize;
300 float fShear;
301 float fRotation;
302 float fFalseBoldWidth;
303 uint8 fSpacing;
304 uint8 fEncoding;
305 uint16 fFace;
306 uint32 fFlags;
307 mutable font_height fHeight;
308 mutable uint32 fExtraFlags;
310 uint32 _reserved[1];
314 // #pragma mark - BFont related declarations
316 extern const BFont* be_plain_font;
317 extern const BFont* be_bold_font;
318 extern const BFont* be_fixed_font;
320 int32 count_font_families(void);
321 status_t get_font_family(int32 index, font_family* name,
322 uint32* flags = NULL);
324 int32 count_font_styles(font_family name);
325 status_t get_font_style(font_family family, int32 index, font_style* name,
326 uint32* flags = NULL);
327 status_t get_font_style(font_family family, int32 index, font_style* name,
328 uint16* face, uint32* flags = NULL);
329 bool update_font_families(bool checkOnly);
333 // #pragma mark - unicode_block inlines
336 unicode_block::unicode_block()
338 fData[0] = fData[1] = 0LL;
342 unicode_block::unicode_block(uint64 block2, uint64 block1)
344 fData[0] = block1;
345 fData[1] = block2;
349 bool
350 unicode_block::Includes(const unicode_block& block) const
352 return (fData[0] & block.fData[0]) == block.fData[0]
353 && (fData[1] & block.fData[1]) == block.fData[1];
357 unicode_block
358 unicode_block::operator&(const unicode_block& block) const
360 unicode_block result;
361 result.fData[0] = fData[0] & block.fData[0];
362 result.fData[1] = fData[1] & block.fData[1];
364 return result;
368 unicode_block
369 unicode_block::operator|(const unicode_block& block) const
371 unicode_block result;
372 result.fData[0] = fData[0] | block.fData[0];
373 result.fData[1] = fData[1] | block.fData[1];
375 return result;
379 unicode_block&
380 unicode_block::operator=(const unicode_block& block)
382 fData[0] = block.fData[0];
383 fData[1] = block.fData[1];
385 return *this;
389 bool
390 unicode_block::operator==(const unicode_block& block) const
392 return fData[0] == block.fData[0] && fData[1] == block.fData[1];
396 bool
397 unicode_block::operator!=(const unicode_block& block) const
399 return fData[0] != block.fData[0] || fData[1] != block.fData[1];
403 #endif // _FONT_H_