1 /***************************************************************************/
2 /* */
3 /* ftobjs.h */
4 /* */
5 /* The FreeType private base classes (specification). */
6 /* */
7 /* Copyright 1996-2001 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 /***************************************************************************/
19 /*************************************************************************/
20 /* */
21 /* This file contains the definition of all internal FreeType classes. */
22 /* */
23 /*************************************************************************/
26 #ifndef __FTOBJS_H__
27 #define __FTOBJS_H__
30 #include <ft2build.h>
31 #include FT_RENDER_H
32 #include FT_SIZES_H
33 #include FT_INTERNAL_MEMORY_H
34 #include FT_INTERNAL_DRIVER_H
35 #include FT_INTERNAL_AUTOHINT_H
38 FT_BEGIN_HEADER
41 /*************************************************************************/
42 /* */
43 /* Some generic definitions. */
44 /* */
45 #ifndef TRUE
46 #define TRUE 1
47 #endif
49 #ifndef FALSE
50 #define FALSE 0
51 #endif
53 #ifndef NULL
54 #define NULL (void*)0
55 #endif
57 #ifndef UNUSED
58 #define UNUSED( arg ) ( (arg)=(arg) )
59 #endif
62 /*************************************************************************/
63 /* */
64 /* The min and max functions missing in C. As usual, be careful not to */
65 /* write things like MIN( a++, b++ ) to avoid side effects. */
66 /* */
67 #ifndef MIN
68 #define MIN( a, b ) ( (a) < (b) ? (a) : (b) )
69 #endif
71 #ifndef MAX
72 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
73 #endif
75 #ifndef ABS
76 #define ABS( a ) ( (a) < 0 ? -(a) : (a) )
77 #endif
80 /*************************************************************************/
81 /* */
82 /* <Struct> */
83 /* FT_GlyphLoader */
84 /* */
85 /* <Description> */
86 /* The glyph loader is an internal object used to load several glyphs */
87 /* together (for example, in the case of composites). */
88 /* */
89 /* <Note> */
90 /* The glyph loader implementation is not part of the high-level API, */
91 /* hence the forward structure declaration. */
92 /* */
93 typedef struct FT_GlyphLoader_ FT_GlyphLoader;
96 /*************************************************************************/
97 /* */
98 /* <Struct> */
99 /* FT_Face_InternalRec */
100 /* */
101 /* <Description> */
102 /* This structure contains the internal fields of each FT_Face */
103 /* object. These fields may change between different releases of */
104 /* FreeType. */
105 /* */
106 /* <Fields> */
107 /* max_points :: The maximal number of points used to store the */
108 /* vectorial outline of any glyph in this face. */
109 /* If this value cannot be known in advance, or */
110 /* if the face isn't scalable, this should be set */
111 /* to 0. Only relevant for scalable formats. */
112 /* */
113 /* max_contours :: The maximal number of contours used to store */
114 /* the vectorial outline of any glyph in this */
115 /* face. If this value cannot be known in */
116 /* advance, or if the face isn't scalable, this */
117 /* should be set to 0. Only relevant for */
118 /* scalable formats. */
119 /* */
120 /* transform_matrix :: A 2x2 matrix of 16.16 coefficients used to */
121 /* transform glyph outlines after they are loaded */
122 /* from the font. Only used by the convenience */
123 /* functions. */
124 /* */
125 /* transform_delta :: A translation vector used to transform glyph */
126 /* outlines after they are loaded from the font. */
127 /* Only used by the convenience functions. */
128 /* */
129 /* transform_flags :: Some flags used to classify the transform. */
130 /* Only used by the convenience functions. */
131 /* */
132 /* postscript_name :: Postscript font name for this face. */
133 /* */
134 typedef struct FT_Face_InternalRec_
135 {
136 FT_UShort max_points;
137 FT_Short max_contours;
139 FT_Matrix transform_matrix;
140 FT_Vector transform_delta;
141 FT_Int transform_flags;
143 const char* postscript_name;
145 } FT_Face_InternalRec;
148 /*************************************************************************/
149 /* */
150 /* <Struct> */
151 /* FT_Slot_InternalRec */
152 /* */
153 /* <Description> */
154 /* This structure contains the internal fields of each FT_GlyphSlot */
155 /* object. These fields may change between different releases of */
156 /* FreeType. */
157 /* */
158 /* <Fields> */
159 /* loader :: The glyph loader object used to load outlines */
160 /* into the glyph slot. */
161 /* */
162 /* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
163 /* must be transformed through a specific */
164 /* font transformation. This is _not_ the same */
165 /* as the face transform set through */
166 /* FT_Set_Transform(). */
167 /* */
168 /* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
169 /* transformation, if necessary. */
170 /* */
171 /* glyph_delta :: The 2d translation vector corresponding to */
172 /* the glyph transformation, if necessary. */
173 /* */
174 typedef struct FT_Slot_InternalRec_
175 {
176 FT_GlyphLoader* loader;
177 FT_Bool glyph_transformed;
178 FT_Matrix glyph_matrix;
179 FT_Vector glyph_delta;
181 } FT_GlyphSlot_InternalRec;
184 /*************************************************************************/
185 /*************************************************************************/
186 /*************************************************************************/
187 /**** ****/
188 /**** ****/
189 /**** M O D U L E S ****/
190 /**** ****/
191 /**** ****/
192 /*************************************************************************/
193 /*************************************************************************/
194 /*************************************************************************/
197 /*************************************************************************/
198 /* */
199 /* <Struct> */
200 /* FT_ModuleRec */
201 /* */
202 /* <Description> */
203 /* A module object instance. */
204 /* */
205 /* <Fields> */
206 /* clazz :: A pointer to the module's class. */
207 /* */
208 /* library :: A handle to the parent library object. */
209 /* */
210 /* memory :: A handle to the memory manager. */
211 /* */
212 /* generic :: A generic structure for user-level extensibility (?). */
213 /* */
214 typedef struct FT_ModuleRec_
215 {
216 FT_Module_Class* clazz;
217 FT_Library library;
218 FT_Memory memory;
219 FT_Generic generic;
221 } FT_ModuleRec;
224 /* typecast an object to a FT_Module */
225 #define FT_MODULE( x ) ((FT_Module)(x))
226 #define FT_MODULE_CLASS( x ) FT_MODULE(x)->clazz
227 #define FT_MODULE_LIBRARY( x ) FT_MODULE(x)->library
228 #define FT_MODULE_MEMORY( x ) FT_MODULE(x)->memory
230 #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
231 ft_module_font_driver )
233 #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
234 ft_module_renderer )
236 #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
237 ft_module_hinter )
239 #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
240 ft_module_styler )
242 #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS(x)->module_flags & \
243 ft_module_driver_scalable )
245 #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS(x)->module_flags & \
246 ft_module_driver_no_outlines )
248 #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS(x)->module_flags & \
249 ft_module_driver_has_hinter )
252 /*************************************************************************/
253 /* */
254 /* <Function> */
255 /* FT_Get_Module_Interface */
256 /* */
257 /* <Description> */
258 /* Finds a module and returns its specific interface as a typeless */
259 /* pointer. */
260 /* */
261 /* <Input> */
262 /* library :: A handle to the library object. */
263 /* */
264 /* module_name :: The module's name (as an ASCII string). */
265 /* */
266 /* <Return> */
267 /* A module-specific interface if available, 0 otherwise. */
268 /* */
269 /* <Note> */
270 /* You should better be familiar with FreeType internals to know */
271 /* which module to look for, and what its interface is :-) */
272 /* */
273 FT_BASE( const void* )
274 FT_Get_Module_Interface( FT_Library library,
275 const char* mod_name );
278 /*************************************************************************/
279 /*************************************************************************/
280 /*************************************************************************/
281 /**** ****/
282 /**** ****/
283 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
284 /**** ****/
285 /**** ****/
286 /*************************************************************************/
287 /*************************************************************************/
288 /*************************************************************************/
290 /* a few macros used to perform easy typecasts with minimal brain damage */
292 #define FT_FACE( x ) ((FT_Face)(x))
293 #define FT_SIZE( x ) ((FT_Size)(x))
294 #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
296 #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
297 #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
298 #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
300 #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
301 #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
303 #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
304 #define FT_FACE_SIZE( x ) FT_FACE( x )->size
307 /*************************************************************************/
308 /* */
309 /* <Function> */
310 /* FT_New_GlyphSlot */
311 /* */
312 /* <Description> */
313 /* It is sometimes useful to have more than one glyph slot for a */
314 /* given face object. This function is used to create additional */
315 /* slots. All of them are automatically discarded when the face is */
316 /* destroyed. */
317 /* */
318 /* <Input> */
319 /* face :: A handle to a parent face object. */
320 /* */
321 /* <Output> */
322 /* aslot :: A handle to a new glyph slot object. */
323 /* */
324 /* <Return> */
325 /* FreeType error code. 0 means success. */
326 /* */
327 FT_BASE( FT_Error )
328 FT_New_GlyphSlot( FT_Face face,
329 FT_GlyphSlot *aslot );
332 /*************************************************************************/
333 /* */
334 /* <Function> */
335 /* FT_Done_GlyphSlot */
336 /* */
337 /* <Description> */
338 /* Destroys a given glyph slot. Remember however that all slots are */
339 /* automatically destroyed with its parent. Using this function is */
340 /* not always mandatory. */
341 /* */
342 /* <Input> */
343 /* slot :: A handle to a target glyph slot. */
344 /* */
345 FT_BASE( void )
346 FT_Done_GlyphSlot( FT_GlyphSlot slot );
349 /*************************************************************************/
350 /*************************************************************************/
351 /*************************************************************************/
352 /**** ****/
353 /**** ****/
354 /**** G L Y P H L O A D E R ****/
355 /**** ****/
356 /**** ****/
357 /*************************************************************************/
358 /*************************************************************************/
359 /*************************************************************************/
362 #define FT_SUBGLYPH_FLAG_ARGS_ARE_WORDS 1
363 #define FT_SUBGLYPH_FLAG_ARGS_ARE_XY_VALUES 2
364 #define FT_SUBGLYPH_FLAG_ROUND_XY_TO_GRID 4
365 #define FT_SUBGLYPH_FLAG_SCALE 8
366 #define FT_SUBGLYPH_FLAG_XY_SCALE 0x40
367 #define FT_SUBGLYPH_FLAG_2X2 0x80
368 #define FT_SUBGLYPH_FLAG_USE_MY_METRICS 0x200
371 enum
372 {
373 ft_glyph_own_bitmap = 1
374 };
377 struct FT_SubGlyph_
378 {
379 FT_Int index;
380 FT_UShort flags;
381 FT_Int arg1;
382 FT_Int arg2;
383 FT_Matrix transform;
384 };
387 typedef struct FT_GlyphLoad_
388 {
389 FT_Outline outline; /* outline */
390 FT_UInt num_subglyphs; /* number of subglyphs */
391 FT_SubGlyph* subglyphs; /* subglyphs */
392 FT_Vector* extra_points; /* extra points table */
394 } FT_GlyphLoad;
397 struct FT_GlyphLoader_
398 {
399 FT_Memory memory;
400 FT_UInt max_points;
401 FT_UInt max_contours;
402 FT_UInt max_subglyphs;
403 FT_Bool use_extra;
405 FT_GlyphLoad base;
406 FT_GlyphLoad current;
408 void* other; /* for possible future extension? */
410 };
413 FT_BASE( FT_Error )
414 FT_GlyphLoader_New( FT_Memory memory,
415 FT_GlyphLoader* *aloader );
417 FT_BASE( FT_Error )
418 FT_GlyphLoader_Create_Extra( FT_GlyphLoader* loader );
420 FT_BASE( void )
421 FT_GlyphLoader_Done( FT_GlyphLoader* loader );
423 FT_BASE( void )
424 FT_GlyphLoader_Reset( FT_GlyphLoader* loader );
426 FT_BASE( void )
427 FT_GlyphLoader_Rewind( FT_GlyphLoader* loader );
429 FT_BASE( FT_Error )
430 FT_GlyphLoader_Check_Points( FT_GlyphLoader* loader,
431 FT_UInt n_points,
432 FT_UInt n_contours );
434 FT_BASE( FT_Error )
435 FT_GlyphLoader_Check_Subglyphs( FT_GlyphLoader* loader,
436 FT_UInt n_subs );
438 FT_BASE( void )
439 FT_GlyphLoader_Prepare( FT_GlyphLoader* loader );
441 FT_BASE( void )
442 FT_GlyphLoader_Add( FT_GlyphLoader* loader );
444 FT_BASE( FT_Error )
445 FT_GlyphLoader_Copy_Points( FT_GlyphLoader* target,
446 FT_GlyphLoader* source );
449 /*************************************************************************/
450 /*************************************************************************/
451 /*************************************************************************/
452 /**** ****/
453 /**** ****/
454 /**** R E N D E R E R S ****/
455 /**** ****/
456 /**** ****/
457 /*************************************************************************/
458 /*************************************************************************/
459 /*************************************************************************/
462 #define FT_RENDERER( x ) ((FT_Renderer)( x ))
463 #define FT_GLYPH( x ) ((FT_Glyph)( x ))
464 #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
465 #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
468 typedef struct FT_RendererRec_
469 {
470 FT_ModuleRec root;
471 FT_Renderer_Class* clazz;
472 FT_Glyph_Format glyph_format;
473 FT_Glyph_Class glyph_class;
475 FT_Raster raster;
476 FT_Raster_Render_Func raster_render;
477 FTRenderer_render render;
479 } FT_RendererRec;
482 /*************************************************************************/
483 /*************************************************************************/
484 /*************************************************************************/
485 /**** ****/
486 /**** ****/
487 /**** F O N T D R I V E R S ****/
488 /**** ****/
489 /**** ****/
490 /*************************************************************************/
491 /*************************************************************************/
492 /*************************************************************************/
495 /* typecast a module into a driver easily */
496 #define FT_DRIVER( x ) ((FT_Driver)(x))
498 /* typecast a module as a driver, and get its driver class */
499 #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
502 /*************************************************************************/
503 /* */
504 /* <Struct> */
505 /* FT_DriverRec */
506 /* */
507 /* <Description> */
508 /* The root font driver class. A font driver is responsible for */
509 /* managing and loading font files of a given format. */
510 /* */
511 /* <Fields> */
512 /* root :: Contains the fields of the root module class. */
513 /* */
514 /* clazz :: A pointer to the font driver's class. Note that */
515 /* this is NOT root.clazz. `class' wasn't used */
516 /* as it is a reserved word in C++. */
517 /* */
518 /* faces_list :: The list of faces currently opened by this */
519 /* driver. */
520 /* */
521 /* extensions :: A typeless pointer to the driver's extensions */
522 /* registry, if they are supported through the */
523 /* configuration macro FT_CONFIG_OPTION_EXTENSIONS. */
524 /* */
525 /* glyph_loader :: The glyph loader for all faces managed by this */
526 /* driver. This object isn't defined for unscalable */
527 /* formats. */
528 /* */
529 typedef struct FT_DriverRec_
530 {
531 FT_ModuleRec root;
532 FT_Driver_Class* clazz;
534 FT_ListRec faces_list;
535 void* extensions;
537 FT_GlyphLoader* glyph_loader;
539 } FT_DriverRec;
542 /*************************************************************************/
543 /*************************************************************************/
544 /*************************************************************************/
545 /**** ****/
546 /**** ****/
547 /**** L I B R A R I E S ****/
548 /**** ****/
549 /**** ****/
550 /*************************************************************************/
551 /*************************************************************************/
552 /*************************************************************************/
555 #define FT_DEBUG_HOOK_TRUETYPE 0
556 #define FT_DEBUG_HOOK_TYPE1 1
559 /*************************************************************************/
560 /* */
561 /* <Struct> */
562 /* FT_LibraryRec */
563 /* */
564 /* <Description> */
565 /* The FreeType library class. This is the root of all FreeType */
566 /* data. Use FT_New_Library() to create a library object, and */
567 /* FT_Done_Library() to discard it and all child objects. */
568 /* */
569 /* <Fields> */
570 /* memory :: The library's memory object. Manages memory */
571 /* allocation. */
572 /* */
573 /* generic :: Client data variable. Used to extend the */
574 /* Library class by higher levels and clients. */
575 /* */
576 /* num_modules :: The number of modules currently registered */
577 /* within this library. This is set to 0 for new */
578 /* libraries. New modules are added through the */
579 /* FT_Add_Module() API function. */
580 /* */
581 /* modules :: A table used to store handles to the currently */
582 /* registered modules. Note that each font driver */
583 /* contains a list of its opened faces. */
584 /* */
585 /* renderers :: The list of renderers currently registered */
586 /* within the library. */
587 /* */
588 /* cur_renderer :: The current outline renderer. This is a */
589 /* shortcut used to avoid parsing the list on */
590 /* each call to FT_Outline_Render(). It is a */
591 /* handle to the current renderer for the */
592 /* ft_glyph_format_outline format. */
593 /* */
594 /* auto_hinter :: XXX */
595 /* */
596 /* raster_pool :: The raster object's render pool. This can */
597 /* ideally be changed dynamically at run-time. */
598 /* */
599 /* raster_pool_size :: The size of the render pool in bytes. */
600 /* */
601 /* debug_hooks :: XXX */
602 /* */
603 typedef struct FT_LibraryRec_
604 {
605 FT_Memory memory; /* library's memory manager */
607 FT_Generic generic;
609 FT_UInt num_modules;
610 FT_Module modules[FT_MAX_MODULES]; /* module objects */
612 FT_ListRec renderers; /* list of renderers */
613 FT_Renderer cur_renderer; /* current outline renderer */
614 FT_Module auto_hinter;
616 FT_Byte* raster_pool; /* scan-line conversion */
617 /* render pool */
618 FT_ULong raster_pool_size; /* size of render pool in bytes */
620 FT_DebugHook_Func debug_hooks[4];
622 } FT_LibraryRec;
625 FT_BASE( FT_Renderer )
626 FT_Lookup_Renderer( FT_Library library,
627 FT_Glyph_Format format,
628 FT_ListNode* node );
630 FT_BASE( FT_Error )
631 FT_Render_Glyph_Internal( FT_Library library,
632 FT_GlyphSlot slot,
633 FT_UInt render_mode );
635 typedef const char*
636 (*FT_PSName_Requester)( FT_Face face );
638 typedef FT_Error
639 (*FT_Glyph_Name_Requester)( FT_Face face,
640 FT_UInt glyph_index,
641 FT_Pointer buffer,
642 FT_UInt buffer_max );
644 typedef FT_UInt
645 (*FT_Name_Index_Requester)( FT_Face face,
646 FT_String* glyph_name );
649 #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
651 /*************************************************************************/
652 /* */
653 /* <Function> */
654 /* FT_New_Stream */
655 /* */
656 /* <Description> */
657 /* Creates a new stream object. */
658 /* */
659 /* <Input> */
660 /* filepathname :: The name of the stream (usually a file) to be */
661 /* opened. */
662 /* */
663 /* stream :: A pointer to the stream object. */
664 /* */
665 /* <Return> */
666 /* FreeType error code. 0 means success. */
667 /* */
668 FT_EXPORT( FT_Error )
669 FT_New_Stream( const char* filepathname,
670 FT_Stream astream );
673 /*************************************************************************/
674 /* */
675 /* <Function> */
676 /* FT_Done_Stream */
677 /* */
678 /* <Description> */
679 /* Closes and destroys a stream object. */
680 /* */
681 /* <Input> */
682 /* stream :: The stream to be closed and destroyed. */
683 /* */
684 FT_EXPORT( void )
685 FT_Done_Stream( FT_Stream stream );
688 /*************************************************************************/
689 /* */
690 /* <Function> */
691 /* FT_New_Memory */
692 /* */
693 /* <Description> */
694 /* Creates a new memory object. */
695 /* */
696 /* <Return> */
697 /* A pointer to the new memory object. 0 in case of error. */
698 /* */
699 FT_EXPORT( FT_Memory )
700 FT_New_Memory( void );
703 /*************************************************************************/
704 /* */
705 /* <Function> */
706 /* FT_Done_Memory */
707 /* */
708 /* <Description> */
709 /* Discards memory manager. */
710 /* */
711 /* <Input> */
712 /* memory :: A handle to the memory manager. */
713 /* */
714 FT_EXPORT( void )
715 FT_Done_Memory( FT_Memory memory );
717 #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
720 /* Define default raster's interface. The default raster is located in */
721 /* `src/base/ftraster.c'. */
722 /* */
723 /* Client applications can register new rasters through the */
724 /* FT_Set_Raster() API. */
726 #ifndef FT_NO_DEFAULT_RASTER
727 FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster;
728 #endif
731 FT_END_HEADER
733 #endif /* __FTOBJS_H__ */
736 /* END */