2 * Copyright 2005-2016, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
9 #include <SupportDefs.h>
10 #include <InterfaceDefs.h>
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];
32 B_FONT_LEFT_TO_RIGHT
= 0,
33 B_FONT_RIGHT_TO_LEFT
= 1
39 B_DISABLE_ANTIALIASING
= 0x00000001,
40 B_FORCE_ANTIALIASING
= 0x00000002
46 B_NO_TRUNCATION
= ~0U,
48 B_TRUNCATE_BEGINNING
= 1,
49 B_TRUNCATE_MIDDLE
= 2,
67 B_MACINTOSH_ROMAN
= 11
71 // flags for get_font_family() and get_font_style()
73 B_HAS_TUNED_FONT
= 0x0001,
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,
86 B_REGULAR_FACE
= 0x0040,
88 B_CONDENSED_FACE
= 0x0080,
89 B_LIGHT_FACE
= 0x0100,
90 B_HEAVY_FACE
= 0x0200,
94 enum font_metric_mode
{
100 enum font_file_format
{
101 B_TRUETYPE_WINDOWS
= 0,
102 B_POSTSCRIPT_TYPE1_WINDOWS
= 1
106 class unicode_block
{
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;
123 struct unicode_block_range
{
126 const unicode_block
& block
;
128 uint32
Count() const { return end
+ 1 - start
; }
145 struct escapement_delta
{
151 struct font_cache_info
{
152 int32 sheared_font_penalty
;
153 int32 rotated_font_penalty
;
154 float oversize_threshold
;
155 int32 oversize_penalty
;
157 float spacing_size_threshold
;
161 struct tuned_font_info
{
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
,
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;
201 float Rotation() const;
202 float FalseBoldWidth() const;
203 uint8
Spacing() const;
204 uint8
Encoding() 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
,
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
,
232 void GetStringWidths(const char* stringArray
[],
233 const int32 lengthArray
[],
235 float widthArray
[]) const;
237 void GetEscapements(const char charArray
[],
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
[],
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
[],
273 BShape
* glyphShapeArray
[]) const;
275 void GetHasGlyphs(const char charArray
[],
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;
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;
302 float fFalseBoldWidth
;
307 mutable font_height fHeight
;
308 mutable uint32 fExtraFlags
;
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
)
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];
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];
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];
380 unicode_block::operator=(const unicode_block
& block
)
382 fData
[0] = block
.fData
[0];
383 fData
[1] = block
.fData
[1];
390 unicode_block::operator==(const unicode_block
& block
) const
392 return fData
[0] == block
.fData
[0] && fData
[1] == block
.fData
[1];
397 unicode_block::operator!=(const unicode_block
& block
) const
399 return fData
[0] != block
.fData
[0] || fData
[1] != block
.fData
[1];