1/****************************************************************************
2 *
3 * fttypes.h
4 *
5 * FreeType simple types definitions (specification only).
6 *
7 * Copyright (C) 1996-2026 by
8 * David Turner, Robert Wilhelm, and Werner Lemberg.
9 *
10 * This file is part of the FreeType project, and may only be used,
11 * modified, and distributed under the terms of the FreeType project
12 * license, LICENSE.TXT. By continuing to use, modify, or distribute
13 * this file you indicate that you have read the license and
14 * understand and accept it fully.
15 *
16 */
17
18
19#ifndef FTTYPES_H_
20#define FTTYPES_H_
21
22
23#include <ft2build.h>
24#include FT_CONFIG_CONFIG_H
25#include <freetype/ftsystem.h>
26#include <freetype/ftimage.h>
27
28
29FT_BEGIN_HEADER
30
31
32 /**************************************************************************
33 *
34 * @section:
35 * basic_types
36 *
37 * @title:
38 * Basic Data Types
39 *
40 * @abstract:
41 * The basic data types defined by the library.
42 *
43 * @description:
44 * This section contains the basic data types defined by FreeType~2,
45 * ranging from simple scalar types to bitmap descriptors. More
46 * font-specific structures are defined in a different section. Note
47 * that FreeType does not use floating-point data types. Fractional
48 * values are represented by fixed-point integers, with lower bits
49 * storing the fractional part.
50 *
51 * @order:
52 * FT_Byte
53 * FT_Bytes
54 * FT_Char
55 * FT_Int
56 * FT_UInt
57 * FT_Int16
58 * FT_UInt16
59 * FT_Int32
60 * FT_UInt32
61 * FT_Int64
62 * FT_UInt64
63 * FT_Short
64 * FT_UShort
65 * FT_Long
66 * FT_ULong
67 * FT_Bool
68 * FT_Offset
69 * FT_PtrDist
70 * FT_String
71 * FT_Tag
72 * FT_Error
73 * FT_Fixed
74 * FT_Pointer
75 * FT_Pos
76 * FT_Vector
77 * FT_BBox
78 * FT_Matrix
79 * FT_FWord
80 * FT_UFWord
81 * FT_F2Dot14
82 * FT_UnitVector
83 * FT_F26Dot6
84 * FT_Data
85 *
86 * FT_MAKE_TAG
87 *
88 * FT_Generic
89 * FT_Generic_Finalizer
90 *
91 * FT_Bitmap
92 * FT_Pixel_Mode
93 * FT_Palette_Mode
94 * FT_Glyph_Format
95 * FT_IMAGE_TAG
96 *
97 */
98
99
100 /**************************************************************************
101 *
102 * @type:
103 * FT_Bool
104 *
105 * @description:
106 * A typedef of unsigned char, used for simple booleans. As usual,
107 * values 1 and~0 represent true and false, respectively.
108 */
109 typedef unsigned char FT_Bool;
110
111
112 /**************************************************************************
113 *
114 * @type:
115 * FT_FWord
116 *
117 * @description:
118 * A signed 16-bit integer used to store a distance in original font
119 * units.
120 */
121 typedef signed short FT_FWord; /* distance in FUnits */
122
123
124 /**************************************************************************
125 *
126 * @type:
127 * FT_UFWord
128 *
129 * @description:
130 * An unsigned 16-bit integer used to store a distance in original font
131 * units.
132 */
133 typedef unsigned short FT_UFWord; /* unsigned distance */
134
135
136 /**************************************************************************
137 *
138 * @type:
139 * FT_Char
140 *
141 * @description:
142 * A simple typedef for the _signed_ char type.
143 */
144 typedef signed char FT_Char;
145
146
147 /**************************************************************************
148 *
149 * @type:
150 * FT_Byte
151 *
152 * @description:
153 * A simple typedef for the _unsigned_ char type.
154 */
155 typedef unsigned char FT_Byte;
156
157
158 /**************************************************************************
159 *
160 * @type:
161 * FT_Bytes
162 *
163 * @description:
164 * A typedef for constant memory areas.
165 */
166 typedef const FT_Byte* FT_Bytes;
167
168
169 /**************************************************************************
170 *
171 * @type:
172 * FT_Tag
173 *
174 * @description:
175 * A typedef for 32-bit tags (as used in the SFNT format).
176 */
177 typedef FT_UInt32 FT_Tag;
178
179
180 /**************************************************************************
181 *
182 * @type:
183 * FT_String
184 *
185 * @description:
186 * A simple typedef for the char type, usually used for strings.
187 */
188 typedef char FT_String;
189
190
191 /**************************************************************************
192 *
193 * @type:
194 * FT_Short
195 *
196 * @description:
197 * A typedef for signed short.
198 */
199 typedef signed short FT_Short;
200
201
202 /**************************************************************************
203 *
204 * @type:
205 * FT_UShort
206 *
207 * @description:
208 * A typedef for unsigned short.
209 */
210 typedef unsigned short FT_UShort;
211
212
213 /**************************************************************************
214 *
215 * @type:
216 * FT_Int
217 *
218 * @description:
219 * A typedef for the int type.
220 */
221 typedef signed int FT_Int;
222
223
224 /**************************************************************************
225 *
226 * @type:
227 * FT_UInt
228 *
229 * @description:
230 * A typedef for the unsigned int type.
231 */
232 typedef unsigned int FT_UInt;
233
234
235 /**************************************************************************
236 *
237 * @type:
238 * FT_Long
239 *
240 * @description:
241 * A typedef for signed long.
242 */
243 typedef signed long FT_Long;
244
245
246 /**************************************************************************
247 *
248 * @type:
249 * FT_ULong
250 *
251 * @description:
252 * A typedef for unsigned long.
253 */
254 typedef unsigned long FT_ULong;
255
256
257 /**************************************************************************
258 *
259 * @type:
260 * FT_F2Dot14
261 *
262 * @description:
263 * A signed 2.14 fixed-point type used for unit vectors.
264 */
265 typedef signed short FT_F2Dot14;
266
267
268 /**************************************************************************
269 *
270 * @type:
271 * FT_F26Dot6
272 *
273 * @description:
274 * A signed 26.6 fixed-point type used for vectorial pixel coordinates.
275 */
276 typedef signed long FT_F26Dot6;
277
278
279 /**************************************************************************
280 *
281 * @type:
282 * FT_Fixed
283 *
284 * @description:
285 * This type is used to store 16.16 fixed-point values, like scaling
286 * values or matrix coefficients.
287 */
288 typedef signed long FT_Fixed;
289
290
291 /**************************************************************************
292 *
293 * @type:
294 * FT_Error
295 *
296 * @description:
297 * The FreeType error code type. A value of~0 is always interpreted as a
298 * successful operation.
299 */
300 typedef int FT_Error;
301
302
303 /**************************************************************************
304 *
305 * @type:
306 * FT_Pointer
307 *
308 * @description:
309 * A simple typedef for a typeless pointer.
310 */
311 typedef void* FT_Pointer;
312
313
314 /**************************************************************************
315 *
316 * @type:
317 * FT_Offset
318 *
319 * @description:
320 * This is equivalent to the ANSI~C `size_t` type, i.e., the largest
321 * _unsigned_ integer type used to express a file size or position, or a
322 * memory block size.
323 */
324 typedef size_t FT_Offset;
325
326
327 /**************************************************************************
328 *
329 * @type:
330 * FT_PtrDist
331 *
332 * @description:
333 * This is equivalent to the ANSI~C `ptrdiff_t` type, i.e., the largest
334 * _signed_ integer type used to express the distance between two
335 * pointers.
336 */
337 typedef ft_ptrdiff_t FT_PtrDist;
338
339
340 /**************************************************************************
341 *
342 * @struct:
343 * FT_UnitVector
344 *
345 * @description:
346 * A simple structure used to store a 2D vector unit vector. Uses
347 * FT_F2Dot14 types.
348 *
349 * @fields:
350 * x ::
351 * Horizontal coordinate.
352 *
353 * y ::
354 * Vertical coordinate.
355 */
356 typedef struct FT_UnitVector_
357 {
358 FT_F2Dot14 x;
359 FT_F2Dot14 y;
360
361 } FT_UnitVector;
362
363
364 /**************************************************************************
365 *
366 * @struct:
367 * FT_Matrix
368 *
369 * @description:
370 * A simple structure used to store a 2x2 matrix. Coefficients are in
371 * 16.16 fixed-point format. The computation performed is:
372 *
373 * ```
374 * x' = x*xx + y*xy
375 * y' = x*yx + y*yy
376 * ```
377 *
378 * @fields:
379 * xx ::
380 * Matrix coefficient.
381 *
382 * xy ::
383 * Matrix coefficient.
384 *
385 * yx ::
386 * Matrix coefficient.
387 *
388 * yy ::
389 * Matrix coefficient.
390 */
391 typedef struct FT_Matrix_
392 {
393 FT_Fixed xx, xy;
394 FT_Fixed yx, yy;
395
396 } FT_Matrix;
397
398
399 /**************************************************************************
400 *
401 * @struct:
402 * FT_Data
403 *
404 * @description:
405 * Read-only binary data represented as a pointer and a length.
406 *
407 * @fields:
408 * pointer ::
409 * The data.
410 *
411 * length ::
412 * The length of the data in bytes.
413 */
414 typedef struct FT_Data_
415 {
416 const FT_Byte* pointer;
417 FT_UInt length;
418
419 } FT_Data;
420
421
422 /**************************************************************************
423 *
424 * @functype:
425 * FT_Generic_Finalizer
426 *
427 * @description:
428 * Describe a function used to destroy the 'client' data of any FreeType
429 * object. See the description of the @FT_Generic type for details of
430 * usage.
431 *
432 * @input:
433 * The address of the FreeType object that is under finalization. Its
434 * client data is accessed through its `generic` field.
435 */
436 typedef void (*FT_Generic_Finalizer)( void* object );
437
438
439 /**************************************************************************
440 *
441 * @struct:
442 * FT_Generic
443 *
444 * @description:
445 * Client applications often need to associate their own data to a
446 * variety of FreeType core objects. For example, a text layout API
447 * might want to associate a glyph cache to a given size object.
448 *
449 * Some FreeType object contains a `generic` field, of type `FT_Generic`,
450 * which usage is left to client applications and font servers.
451 *
452 * It can be used to store a pointer to client-specific data, as well as
453 * the address of a 'finalizer' function, which will be called by
454 * FreeType when the object is destroyed (for example, the previous
455 * client example would put the address of the glyph cache destructor in
456 * the `finalizer` field).
457 *
458 * @fields:
459 * data ::
460 * A typeless pointer to any client-specified data. This field is
461 * completely ignored by the FreeType library.
462 *
463 * finalizer ::
464 * A pointer to a 'generic finalizer' function, which will be called
465 * when the object is destroyed. If this field is set to `NULL`, no
466 * code will be called.
467 */
468 typedef struct FT_Generic_
469 {
470 void* data;
471 FT_Generic_Finalizer finalizer;
472
473 } FT_Generic;
474
475
476 /**************************************************************************
477 *
478 * @macro:
479 * FT_MAKE_TAG
480 *
481 * @description:
482 * This macro converts four-letter tags that are used to label TrueType
483 * tables into an `FT_Tag` type, to be used within FreeType.
484 *
485 * @note:
486 * The produced values **must** be 32-bit integers. Don't redefine this
487 * macro.
488 */
489#define FT_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
490 ( ( FT_STATIC_BYTE_CAST( FT_Tag, _x1 ) << 24 ) | \
491 ( FT_STATIC_BYTE_CAST( FT_Tag, _x2 ) << 16 ) | \
492 ( FT_STATIC_BYTE_CAST( FT_Tag, _x3 ) << 8 ) | \
493 FT_STATIC_BYTE_CAST( FT_Tag, _x4 ) )
494
495
496 /*************************************************************************/
497 /*************************************************************************/
498 /* */
499 /* L I S T M A N A G E M E N T */
500 /* */
501 /*************************************************************************/
502 /*************************************************************************/
503
504
505 /**************************************************************************
506 *
507 * @section:
508 * list_processing
509 *
510 */
511
512
513 /**************************************************************************
514 *
515 * @type:
516 * FT_ListNode
517 *
518 * @description:
519 * Many elements and objects in FreeType are listed through an @FT_List
520 * record (see @FT_ListRec). As its name suggests, an FT_ListNode is a
521 * handle to a single list element.
522 */
523 typedef struct FT_ListNodeRec_* FT_ListNode;
524
525
526 /**************************************************************************
527 *
528 * @type:
529 * FT_List
530 *
531 * @description:
532 * A handle to a list record (see @FT_ListRec).
533 */
534 typedef struct FT_ListRec_* FT_List;
535
536
537 /**************************************************************************
538 *
539 * @struct:
540 * FT_ListNodeRec
541 *
542 * @description:
543 * A structure used to hold a single list element.
544 *
545 * @fields:
546 * prev ::
547 * The previous element in the list. `NULL` if first.
548 *
549 * next ::
550 * The next element in the list. `NULL` if last.
551 *
552 * data ::
553 * A typeless pointer to the listed object.
554 */
555 typedef struct FT_ListNodeRec_
556 {
557 FT_ListNode prev;
558 FT_ListNode next;
559 void* data;
560
561 } FT_ListNodeRec;
562
563
564 /**************************************************************************
565 *
566 * @struct:
567 * FT_ListRec
568 *
569 * @description:
570 * A structure used to hold a simple doubly-linked list. These are used
571 * in many parts of FreeType.
572 *
573 * @fields:
574 * head ::
575 * The head (first element) of doubly-linked list.
576 *
577 * tail ::
578 * The tail (last element) of doubly-linked list.
579 */
580 typedef struct FT_ListRec_
581 {
582 FT_ListNode head;
583 FT_ListNode tail;
584
585 } FT_ListRec;
586
587 /* */
588
589
590#define FT_IS_EMPTY( list ) ( (list).head == 0 )
591#define FT_BOOL( x ) FT_STATIC_CAST( FT_Bool, (x) != 0 )
592
593 /* concatenate C tokens */
594#define FT_ERR_XCAT( x, y ) x ## y
595#define FT_ERR_CAT( x, y ) FT_ERR_XCAT( x, y )
596
597 /* see `ftmoderr.h` for descriptions of the following macros */
598
599#define FT_ERR( e ) FT_ERR_CAT( FT_ERR_PREFIX, e )
600
601#define FT_ERROR_BASE( x ) ( (x) & 0xFF )
602#define FT_ERROR_MODULE( x ) ( (x) & 0xFF00U )
603
604#define FT_ERR_EQ( x, e ) \
605 ( FT_ERROR_BASE( x ) == FT_ERROR_BASE( FT_ERR( e ) ) )
606#define FT_ERR_NEQ( x, e ) \
607 ( FT_ERROR_BASE( x ) != FT_ERROR_BASE( FT_ERR( e ) ) )
608
609
610FT_END_HEADER
611
612#endif /* FTTYPES_H_ */
613
614
615/* END */
616