Disabling auto-refresh of game list by default, as it is causing bugs sometimes
[open-ps2-loader.git] / thirdparty / freetype-2.3.12 / src / base / ftobjs.c
blob46bcd3bb8b2a0a59c863b732a5bfd1a78d1801a2
1 /***************************************************************************/
2 /* */
3 /* ftobjs.c */
4 /* */
5 /* The FreeType private base classes (body). */
6 /* */
7 /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */
8 /* 2010 by */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
16 /* */
17 /***************************************************************************/
20 #include <ft2build.h>
21 #include FT_LIST_H
22 #include FT_OUTLINE_H
23 #include FT_INTERNAL_VALIDATE_H
24 #include FT_INTERNAL_OBJECTS_H
25 #include FT_INTERNAL_DEBUG_H
26 #include FT_INTERNAL_RFORK_H
27 #include FT_INTERNAL_STREAM_H
28 #include FT_INTERNAL_SFNT_H /* for SFNT_Load_Table_Func */
29 #include FT_TRUETYPE_TABLES_H
30 #include FT_TRUETYPE_TAGS_H
31 #include FT_TRUETYPE_IDS_H
32 #include FT_OUTLINE_H
34 #include FT_SERVICE_SFNT_H
35 #include FT_SERVICE_POSTSCRIPT_NAME_H
36 #include FT_SERVICE_GLYPH_DICT_H
37 #include FT_SERVICE_TT_CMAP_H
38 #include FT_SERVICE_KERNING_H
39 #include FT_SERVICE_TRUETYPE_ENGINE_H
41 #ifdef FT_CONFIG_OPTION_MAC_FONTS
42 #include "ftbase.h"
43 #endif
45 #define GRID_FIT_METRICS
48 FT_BASE_DEF( FT_Pointer )
49 ft_service_list_lookup( FT_ServiceDesc service_descriptors,
50 const char* service_id )
52 FT_Pointer result = NULL;
53 FT_ServiceDesc desc = service_descriptors;
56 if ( desc && service_id )
58 for ( ; desc->serv_id != NULL; desc++ )
60 if ( ft_strcmp( desc->serv_id, service_id ) == 0 )
62 result = (FT_Pointer)desc->serv_data;
63 break;
68 return result;
72 FT_BASE_DEF( void )
73 ft_validator_init( FT_Validator valid,
74 const FT_Byte* base,
75 const FT_Byte* limit,
76 FT_ValidationLevel level )
78 valid->base = base;
79 valid->limit = limit;
80 valid->level = level;
81 valid->error = FT_Err_Ok;
85 FT_BASE_DEF( FT_Int )
86 ft_validator_run( FT_Validator valid )
88 /* This function doesn't work! None should call it. */
89 FT_UNUSED( valid );
91 return -1;
95 FT_BASE_DEF( void )
96 ft_validator_error( FT_Validator valid,
97 FT_Error error )
99 /* since the cast below also disables the compiler's */
100 /* type check, we introduce a dummy variable, which */
101 /* will be optimized away */
102 volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer;
105 valid->error = error;
107 /* throw away volatileness; use `jump_buffer' or the */
108 /* compiler may warn about an unused local variable */
109 ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 );
113 /*************************************************************************/
114 /*************************************************************************/
115 /*************************************************************************/
116 /**** ****/
117 /**** ****/
118 /**** S T R E A M ****/
119 /**** ****/
120 /**** ****/
121 /*************************************************************************/
122 /*************************************************************************/
123 /*************************************************************************/
126 /* create a new input stream from an FT_Open_Args structure */
127 /* */
128 FT_BASE_DEF( FT_Error )
129 FT_Stream_New( FT_Library library,
130 const FT_Open_Args* args,
131 FT_Stream *astream )
133 FT_Error error;
134 FT_Memory memory;
135 FT_Stream stream;
138 *astream = 0;
140 if ( !library )
141 return FT_Err_Invalid_Library_Handle;
143 if ( !args )
144 return FT_Err_Invalid_Argument;
146 memory = library->memory;
148 if ( FT_NEW( stream ) )
149 goto Exit;
151 stream->memory = memory;
153 if ( args->flags & FT_OPEN_MEMORY )
155 /* create a memory-based stream */
156 FT_Stream_OpenMemory( stream,
157 (const FT_Byte*)args->memory_base,
158 args->memory_size );
160 else if ( args->flags & FT_OPEN_PATHNAME )
162 /* create a normal system stream */
163 error = FT_Stream_Open( stream, args->pathname );
164 stream->pathname.pointer = args->pathname;
166 else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
168 /* use an existing, user-provided stream */
170 /* in this case, we do not need to allocate a new stream object */
171 /* since the caller is responsible for closing it himself */
172 FT_FREE( stream );
173 stream = args->stream;
175 else
176 error = FT_Err_Invalid_Argument;
178 if ( error )
179 FT_FREE( stream );
180 else
181 stream->memory = memory; /* just to be certain */
183 *astream = stream;
185 Exit:
186 return error;
190 FT_BASE_DEF( void )
191 FT_Stream_Free( FT_Stream stream,
192 FT_Int external )
194 if ( stream )
196 FT_Memory memory = stream->memory;
199 FT_Stream_Close( stream );
201 if ( !external )
202 FT_FREE( stream );
207 /*************************************************************************/
208 /* */
209 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
210 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
211 /* messages during execution. */
212 /* */
213 #undef FT_COMPONENT
214 #define FT_COMPONENT trace_objs
217 /*************************************************************************/
218 /*************************************************************************/
219 /*************************************************************************/
220 /**** ****/
221 /**** ****/
222 /**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
223 /**** ****/
224 /**** ****/
225 /*************************************************************************/
226 /*************************************************************************/
227 /*************************************************************************/
230 static FT_Error
231 ft_glyphslot_init( FT_GlyphSlot slot )
233 FT_Driver driver = slot->face->driver;
234 FT_Driver_Class clazz = driver->clazz;
235 FT_Memory memory = driver->root.memory;
236 FT_Error error = FT_Err_Ok;
237 FT_Slot_Internal internal;
240 slot->library = driver->root.library;
242 if ( FT_NEW( internal ) )
243 goto Exit;
245 slot->internal = internal;
247 if ( FT_DRIVER_USES_OUTLINES( driver ) )
248 error = FT_GlyphLoader_New( memory, &internal->loader );
250 if ( !error && clazz->init_slot )
251 error = clazz->init_slot( slot );
253 Exit:
254 return error;
258 FT_BASE_DEF( void )
259 ft_glyphslot_free_bitmap( FT_GlyphSlot slot )
261 if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
263 FT_Memory memory = FT_FACE_MEMORY( slot->face );
266 FT_FREE( slot->bitmap.buffer );
267 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
269 else
271 /* assume that the bitmap buffer was stolen or not */
272 /* allocated from the heap */
273 slot->bitmap.buffer = NULL;
278 FT_BASE_DEF( void )
279 ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
280 FT_Byte* buffer )
282 ft_glyphslot_free_bitmap( slot );
284 slot->bitmap.buffer = buffer;
286 FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 );
290 FT_BASE_DEF( FT_Error )
291 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
292 FT_ULong size )
294 FT_Memory memory = FT_FACE_MEMORY( slot->face );
295 FT_Error error;
298 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
299 FT_FREE( slot->bitmap.buffer );
300 else
301 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
303 (void)FT_ALLOC( slot->bitmap.buffer, size );
304 return error;
308 static void
309 ft_glyphslot_clear( FT_GlyphSlot slot )
311 /* free bitmap if needed */
312 ft_glyphslot_free_bitmap( slot );
314 /* clear all public fields in the glyph slot */
315 FT_ZERO( &slot->metrics );
316 FT_ZERO( &slot->outline );
318 slot->bitmap.width = 0;
319 slot->bitmap.rows = 0;
320 slot->bitmap.pitch = 0;
321 slot->bitmap.pixel_mode = 0;
322 /* `slot->bitmap.buffer' has been handled by ft_glyphslot_free_bitmap */
324 slot->bitmap_left = 0;
325 slot->bitmap_top = 0;
326 slot->num_subglyphs = 0;
327 slot->subglyphs = 0;
328 slot->control_data = 0;
329 slot->control_len = 0;
330 slot->other = 0;
331 slot->format = FT_GLYPH_FORMAT_NONE;
333 slot->linearHoriAdvance = 0;
334 slot->linearVertAdvance = 0;
335 slot->lsb_delta = 0;
336 slot->rsb_delta = 0;
340 static void
341 ft_glyphslot_done( FT_GlyphSlot slot )
343 FT_Driver driver = slot->face->driver;
344 FT_Driver_Class clazz = driver->clazz;
345 FT_Memory memory = driver->root.memory;
348 if ( clazz->done_slot )
349 clazz->done_slot( slot );
351 /* free bitmap buffer if needed */
352 ft_glyphslot_free_bitmap( slot );
354 /* slot->internal might be NULL in out-of-memory situations */
355 if ( slot->internal )
357 /* free glyph loader */
358 if ( FT_DRIVER_USES_OUTLINES( driver ) )
360 FT_GlyphLoader_Done( slot->internal->loader );
361 slot->internal->loader = 0;
364 FT_FREE( slot->internal );
369 /* documentation is in ftobjs.h */
371 FT_BASE_DEF( FT_Error )
372 FT_New_GlyphSlot( FT_Face face,
373 FT_GlyphSlot *aslot )
375 FT_Error error;
376 FT_Driver driver;
377 FT_Driver_Class clazz;
378 FT_Memory memory;
379 FT_GlyphSlot slot;
382 if ( !face || !face->driver )
383 return FT_Err_Invalid_Argument;
385 driver = face->driver;
386 clazz = driver->clazz;
387 memory = driver->root.memory;
389 FT_TRACE4(( "FT_New_GlyphSlot: Creating new slot object\n" ));
390 if ( !FT_ALLOC( slot, clazz->slot_object_size ) )
392 slot->face = face;
394 error = ft_glyphslot_init( slot );
395 if ( error )
397 ft_glyphslot_done( slot );
398 FT_FREE( slot );
399 goto Exit;
402 slot->next = face->glyph;
403 face->glyph = slot;
405 if ( aslot )
406 *aslot = slot;
408 else if ( aslot )
409 *aslot = 0;
412 Exit:
413 FT_TRACE4(( "FT_New_GlyphSlot: Return %d\n", error ));
414 return error;
418 /* documentation is in ftobjs.h */
420 FT_BASE_DEF( void )
421 FT_Done_GlyphSlot( FT_GlyphSlot slot )
423 if ( slot )
425 FT_Driver driver = slot->face->driver;
426 FT_Memory memory = driver->root.memory;
427 FT_GlyphSlot prev;
428 FT_GlyphSlot cur;
431 /* Remove slot from its parent face's list */
432 prev = NULL;
433 cur = slot->face->glyph;
435 while ( cur )
437 if ( cur == slot )
439 if ( !prev )
440 slot->face->glyph = cur->next;
441 else
442 prev->next = cur->next;
444 ft_glyphslot_done( slot );
445 FT_FREE( slot );
446 break;
448 prev = cur;
449 cur = cur->next;
455 /* documentation is in freetype.h */
457 FT_EXPORT_DEF( void )
458 FT_Set_Transform( FT_Face face,
459 FT_Matrix* matrix,
460 FT_Vector* delta )
462 FT_Face_Internal internal;
465 if ( !face )
466 return;
468 internal = face->internal;
470 internal->transform_flags = 0;
472 if ( !matrix )
474 internal->transform_matrix.xx = 0x10000L;
475 internal->transform_matrix.xy = 0;
476 internal->transform_matrix.yx = 0;
477 internal->transform_matrix.yy = 0x10000L;
478 matrix = &internal->transform_matrix;
480 else
481 internal->transform_matrix = *matrix;
483 /* set transform_flags bit flag 0 if `matrix' isn't the identity */
484 if ( ( matrix->xy | matrix->yx ) ||
485 matrix->xx != 0x10000L ||
486 matrix->yy != 0x10000L )
487 internal->transform_flags |= 1;
489 if ( !delta )
491 internal->transform_delta.x = 0;
492 internal->transform_delta.y = 0;
493 delta = &internal->transform_delta;
495 else
496 internal->transform_delta = *delta;
498 /* set transform_flags bit flag 1 if `delta' isn't the null vector */
499 if ( delta->x | delta->y )
500 internal->transform_flags |= 2;
504 static FT_Renderer
505 ft_lookup_glyph_renderer( FT_GlyphSlot slot );
508 #ifdef GRID_FIT_METRICS
509 static void
510 ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot,
511 FT_Bool vertical )
513 FT_Glyph_Metrics* metrics = &slot->metrics;
514 FT_Pos right, bottom;
517 if ( vertical )
519 metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
520 metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
522 right = FT_PIX_CEIL( metrics->vertBearingX + metrics->width );
523 bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height );
525 metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
526 metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
528 metrics->width = right - metrics->vertBearingX;
529 metrics->height = bottom - metrics->vertBearingY;
531 else
533 metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
534 metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
536 right = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width );
537 bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height );
539 metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
540 metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
542 metrics->width = right - metrics->horiBearingX;
543 metrics->height = metrics->horiBearingY - bottom;
546 metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance );
547 metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance );
549 #endif /* GRID_FIT_METRICS */
552 /* documentation is in freetype.h */
554 FT_EXPORT_DEF( FT_Error )
555 FT_Load_Glyph( FT_Face face,
556 FT_UInt glyph_index,
557 FT_Int32 load_flags )
559 FT_Error error;
560 FT_Driver driver;
561 FT_GlyphSlot slot;
562 FT_Library library;
563 FT_Bool autohint = FALSE;
564 FT_Module hinter;
567 if ( !face || !face->size || !face->glyph )
568 return FT_Err_Invalid_Face_Handle;
570 /* The validity test for `glyph_index' is performed by the */
571 /* font drivers. */
573 slot = face->glyph;
574 ft_glyphslot_clear( slot );
576 driver = face->driver;
577 library = driver->root.library;
578 hinter = library->auto_hinter;
580 /* resolve load flags dependencies */
582 if ( load_flags & FT_LOAD_NO_RECURSE )
583 load_flags |= FT_LOAD_NO_SCALE |
584 FT_LOAD_IGNORE_TRANSFORM;
586 if ( load_flags & FT_LOAD_NO_SCALE )
588 load_flags |= FT_LOAD_NO_HINTING |
589 FT_LOAD_NO_BITMAP;
591 load_flags &= ~FT_LOAD_RENDER;
595 * Determine whether we need to auto-hint or not.
596 * The general rules are:
598 * - Do only auto-hinting if we have a hinter module, a scalable font
599 * format dealing with outlines, and no transforms except simple
600 * slants and/or rotations by integer multiples of 90 degrees.
602 * - Then, auto-hint if FT_LOAD_FORCE_AUTOHINT is set or if we don't
603 * have a native font hinter.
605 * - Otherwise, auto-hint for LIGHT hinting mode.
607 * - Exception: The font is `tricky' and requires the native hinter to
608 * load properly.
611 if ( hinter &&
612 !( load_flags & FT_LOAD_NO_HINTING ) &&
613 !( load_flags & FT_LOAD_NO_AUTOHINT ) &&
614 FT_DRIVER_IS_SCALABLE( driver ) &&
615 FT_DRIVER_USES_OUTLINES( driver ) &&
616 !FT_IS_TRICKY( face ) &&
617 ( ( face->internal->transform_matrix.yx == 0 &&
618 face->internal->transform_matrix.xx != 0 ) ||
619 ( face->internal->transform_matrix.xx == 0 &&
620 face->internal->transform_matrix.yx != 0 ) ) )
622 if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ||
623 !FT_DRIVER_HAS_HINTER( driver ) )
624 autohint = TRUE;
625 else
627 FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
630 if ( mode == FT_RENDER_MODE_LIGHT ||
631 face->internal->ignore_unpatented_hinter )
632 autohint = TRUE;
636 if ( autohint )
638 FT_AutoHinter_Service hinting;
641 /* try to load embedded bitmaps first if available */
642 /* */
643 /* XXX: This is really a temporary hack that should disappear */
644 /* promptly with FreeType 2.1! */
645 /* */
646 if ( FT_HAS_FIXED_SIZES( face ) &&
647 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
649 error = driver->clazz->load_glyph( slot, face->size,
650 glyph_index,
651 load_flags | FT_LOAD_SBITS_ONLY );
653 if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP )
654 goto Load_Ok;
658 FT_Face_Internal internal = face->internal;
659 FT_Int transform_flags = internal->transform_flags;
662 /* since the auto-hinter calls FT_Load_Glyph by itself, */
663 /* make sure that glyphs aren't transformed */
664 internal->transform_flags = 0;
666 /* load auto-hinted outline */
667 hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface;
669 error = hinting->load_glyph( (FT_AutoHinter)hinter,
670 slot, face->size,
671 glyph_index, load_flags );
673 internal->transform_flags = transform_flags;
676 else
678 error = driver->clazz->load_glyph( slot,
679 face->size,
680 glyph_index,
681 load_flags );
682 if ( error )
683 goto Exit;
685 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
687 /* check that the loaded outline is correct */
688 error = FT_Outline_Check( &slot->outline );
689 if ( error )
690 goto Exit;
692 #ifdef GRID_FIT_METRICS
693 if ( !( load_flags & FT_LOAD_NO_HINTING ) )
694 ft_glyphslot_grid_fit_metrics( slot,
695 FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
696 #endif
700 Load_Ok:
701 /* compute the advance */
702 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
704 slot->advance.x = 0;
705 slot->advance.y = slot->metrics.vertAdvance;
707 else
709 slot->advance.x = slot->metrics.horiAdvance;
710 slot->advance.y = 0;
713 /* compute the linear advance in 16.16 pixels */
714 if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 &&
715 ( FT_IS_SCALABLE( face ) ) )
717 FT_Size_Metrics* metrics = &face->size->metrics;
720 /* it's tricky! */
721 slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
722 metrics->x_scale, 64 );
724 slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance,
725 metrics->y_scale, 64 );
728 if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 )
730 FT_Face_Internal internal = face->internal;
733 /* now, transform the glyph image if needed */
734 if ( internal->transform_flags )
736 /* get renderer */
737 FT_Renderer renderer = ft_lookup_glyph_renderer( slot );
740 if ( renderer )
741 error = renderer->clazz->transform_glyph(
742 renderer, slot,
743 &internal->transform_matrix,
744 &internal->transform_delta );
745 else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
747 /* apply `standard' transformation if no renderer is available */
748 if ( &internal->transform_matrix )
749 FT_Outline_Transform( &slot->outline,
750 &internal->transform_matrix );
752 if ( &internal->transform_delta )
753 FT_Outline_Translate( &slot->outline,
754 internal->transform_delta.x,
755 internal->transform_delta.y );
758 /* transform advance */
759 FT_Vector_Transform( &slot->advance, &internal->transform_matrix );
763 FT_TRACE5(( " x advance: %d\n" , slot->advance.x ));
764 FT_TRACE5(( " y advance: %d\n" , slot->advance.y ));
766 FT_TRACE5(( " linear x advance: %d\n" , slot->linearHoriAdvance ));
767 FT_TRACE5(( " linear y advance: %d\n" , slot->linearVertAdvance ));
769 /* do we need to render the image now? */
770 if ( !error &&
771 slot->format != FT_GLYPH_FORMAT_BITMAP &&
772 slot->format != FT_GLYPH_FORMAT_COMPOSITE &&
773 load_flags & FT_LOAD_RENDER )
775 FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
778 if ( mode == FT_RENDER_MODE_NORMAL &&
779 (load_flags & FT_LOAD_MONOCHROME ) )
780 mode = FT_RENDER_MODE_MONO;
782 error = FT_Render_Glyph( slot, mode );
785 Exit:
786 return error;
790 /* documentation is in freetype.h */
792 FT_EXPORT_DEF( FT_Error )
793 FT_Load_Char( FT_Face face,
794 FT_ULong char_code,
795 FT_Int32 load_flags )
797 FT_UInt glyph_index;
800 if ( !face )
801 return FT_Err_Invalid_Face_Handle;
803 glyph_index = (FT_UInt)char_code;
804 if ( face->charmap )
805 glyph_index = FT_Get_Char_Index( face, char_code );
807 return FT_Load_Glyph( face, glyph_index, load_flags );
811 /* destructor for sizes list */
812 static void
813 destroy_size( FT_Memory memory,
814 FT_Size size,
815 FT_Driver driver )
817 /* finalize client-specific data */
818 if ( size->generic.finalizer )
819 size->generic.finalizer( size );
821 /* finalize format-specific stuff */
822 if ( driver->clazz->done_size )
823 driver->clazz->done_size( size );
825 FT_FREE( size->internal );
826 FT_FREE( size );
830 static void
831 ft_cmap_done_internal( FT_CMap cmap );
834 static void
835 destroy_charmaps( FT_Face face,
836 FT_Memory memory )
838 FT_Int n;
841 if ( !face )
842 return;
844 for ( n = 0; n < face->num_charmaps; n++ )
846 FT_CMap cmap = FT_CMAP( face->charmaps[n] );
849 ft_cmap_done_internal( cmap );
851 face->charmaps[n] = NULL;
854 FT_FREE( face->charmaps );
855 face->num_charmaps = 0;
859 /* destructor for faces list */
860 static void
861 destroy_face( FT_Memory memory,
862 FT_Face face,
863 FT_Driver driver )
865 FT_Driver_Class clazz = driver->clazz;
868 /* discard auto-hinting data */
869 if ( face->autohint.finalizer )
870 face->autohint.finalizer( face->autohint.data );
872 /* Discard glyph slots for this face. */
873 /* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */
874 while ( face->glyph )
875 FT_Done_GlyphSlot( face->glyph );
877 /* discard all sizes for this face */
878 FT_List_Finalize( &face->sizes_list,
879 (FT_List_Destructor)destroy_size,
880 memory,
881 driver );
882 face->size = 0;
884 /* now discard client data */
885 if ( face->generic.finalizer )
886 face->generic.finalizer( face );
888 /* discard charmaps */
889 destroy_charmaps( face, memory );
891 /* finalize format-specific stuff */
892 if ( clazz->done_face )
893 clazz->done_face( face );
895 /* close the stream for this face if needed */
896 FT_Stream_Free(
897 face->stream,
898 ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
900 face->stream = 0;
902 /* get rid of it */
903 if ( face->internal )
905 FT_FREE( face->internal );
907 FT_FREE( face );
911 static void
912 Destroy_Driver( FT_Driver driver )
914 FT_List_Finalize( &driver->faces_list,
915 (FT_List_Destructor)destroy_face,
916 driver->root.memory,
917 driver );
919 /* check whether we need to drop the driver's glyph loader */
920 if ( FT_DRIVER_USES_OUTLINES( driver ) )
921 FT_GlyphLoader_Done( driver->glyph_loader );
925 /*************************************************************************/
926 /* */
927 /* <Function> */
928 /* find_unicode_charmap */
929 /* */
930 /* <Description> */
931 /* This function finds a Unicode charmap, if there is one. */
932 /* And if there is more than one, it tries to favour the more */
933 /* extensive one, i.e., one that supports UCS-4 against those which */
934 /* are limited to the BMP (said UCS-2 encoding.) */
935 /* */
936 /* This function is called from open_face() (just below), and also */
937 /* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */
938 /* */
939 static FT_Error
940 find_unicode_charmap( FT_Face face )
942 FT_CharMap* first;
943 FT_CharMap* cur;
946 /* caller should have already checked that `face' is valid */
947 FT_ASSERT( face );
949 first = face->charmaps;
951 if ( !first )
952 return FT_Err_Invalid_CharMap_Handle;
955 * The original TrueType specification(s) only specified charmap
956 * formats that are capable of mapping 8 or 16 bit character codes to
957 * glyph indices.
959 * However, recent updates to the Apple and OpenType specifications
960 * introduced new formats that are capable of mapping 32-bit character
961 * codes as well. And these are already used on some fonts, mainly to
962 * map non-BMP Asian ideographs as defined in Unicode.
964 * For compatibility purposes, these fonts generally come with
965 * *several* Unicode charmaps:
967 * - One of them in the "old" 16-bit format, that cannot access
968 * all glyphs in the font.
970 * - Another one in the "new" 32-bit format, that can access all
971 * the glyphs.
973 * This function has been written to always favor a 32-bit charmap
974 * when found. Otherwise, a 16-bit one is returned when found.
977 /* Since the `interesting' table, with IDs (3,10), is normally the */
978 /* last one, we loop backwards. This loses with type1 fonts with */
979 /* non-BMP characters (<.0001%), this wins with .ttf with non-BMP */
980 /* chars (.01% ?), and this is the same about 99.99% of the time! */
982 cur = first + face->num_charmaps; /* points after the last one */
984 for ( ; --cur >= first; )
986 if ( cur[0]->encoding == FT_ENCODING_UNICODE )
988 /* XXX If some new encodings to represent UCS-4 are added, */
989 /* they should be added here. */
990 if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
991 cur[0]->encoding_id == TT_MS_ID_UCS_4 ) ||
992 ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
993 cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) )
995 face->charmap = cur[0];
996 return FT_Err_Ok;
1001 /* We do not have any UCS-4 charmap. */
1002 /* Do the loop again and search for UCS-2 charmaps. */
1003 cur = first + face->num_charmaps;
1005 for ( ; --cur >= first; )
1007 if ( cur[0]->encoding == FT_ENCODING_UNICODE )
1009 face->charmap = cur[0];
1010 return FT_Err_Ok;
1014 return FT_Err_Invalid_CharMap_Handle;
1018 /*************************************************************************/
1019 /* */
1020 /* <Function> */
1021 /* find_variant_selector_charmap */
1022 /* */
1023 /* <Description> */
1024 /* This function finds the variant selector charmap, if there is one. */
1025 /* There can only be one (platform=0, specific=5, format=14). */
1026 /* */
1027 static FT_CharMap
1028 find_variant_selector_charmap( FT_Face face )
1030 FT_CharMap* first;
1031 FT_CharMap* end;
1032 FT_CharMap* cur;
1035 /* caller should have already checked that `face' is valid */
1036 FT_ASSERT( face );
1038 first = face->charmaps;
1040 if ( !first )
1041 return NULL;
1043 end = first + face->num_charmaps; /* points after the last one */
1045 for ( cur = first; cur < end; ++cur )
1047 if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
1048 cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
1049 FT_Get_CMap_Format( cur[0] ) == 14 )
1050 return cur[0];
1053 return NULL;
1057 /*************************************************************************/
1058 /* */
1059 /* <Function> */
1060 /* open_face */
1061 /* */
1062 /* <Description> */
1063 /* This function does some work for FT_Open_Face(). */
1064 /* */
1065 static FT_Error
1066 open_face( FT_Driver driver,
1067 FT_Stream stream,
1068 FT_Long face_index,
1069 FT_Int num_params,
1070 FT_Parameter* params,
1071 FT_Face *aface )
1073 FT_Memory memory;
1074 FT_Driver_Class clazz;
1075 FT_Face face = 0;
1076 FT_Error error, error2;
1077 FT_Face_Internal internal = NULL;
1080 clazz = driver->clazz;
1081 memory = driver->root.memory;
1083 /* allocate the face object and perform basic initialization */
1084 if ( FT_ALLOC( face, clazz->face_object_size ) )
1085 goto Fail;
1087 if ( FT_NEW( internal ) )
1088 goto Fail;
1090 face->internal = internal;
1092 face->driver = driver;
1093 face->memory = memory;
1094 face->stream = stream;
1096 #ifdef FT_CONFIG_OPTION_INCREMENTAL
1098 int i;
1101 face->internal->incremental_interface = 0;
1102 for ( i = 0; i < num_params && !face->internal->incremental_interface;
1103 i++ )
1104 if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
1105 face->internal->incremental_interface =
1106 (FT_Incremental_Interface)params[i].data;
1108 #endif
1110 if ( clazz->init_face )
1111 error = clazz->init_face( stream,
1112 face,
1113 (FT_Int)face_index,
1114 num_params,
1115 params );
1116 if ( error )
1117 goto Fail;
1119 /* select Unicode charmap by default */
1120 error2 = find_unicode_charmap( face );
1122 /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */
1123 /* is returned. */
1125 /* no error should happen, but we want to play safe */
1126 if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle )
1128 error = error2;
1129 goto Fail;
1132 *aface = face;
1134 Fail:
1135 if ( error )
1137 destroy_charmaps( face, memory );
1138 if ( clazz->done_face )
1139 clazz->done_face( face );
1140 FT_FREE( internal );
1141 FT_FREE( face );
1142 *aface = 0;
1145 return error;
1149 /* there's a Mac-specific extended implementation of FT_New_Face() */
1150 /* in src/base/ftmac.c */
1152 #if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
1154 /* documentation is in freetype.h */
1156 FT_EXPORT_DEF( FT_Error )
1157 FT_New_Face( FT_Library library,
1158 const char* pathname,
1159 FT_Long face_index,
1160 FT_Face *aface )
1162 FT_Open_Args args;
1165 /* test for valid `library' and `aface' delayed to FT_Open_Face() */
1166 if ( !pathname )
1167 return FT_Err_Invalid_Argument;
1169 args.flags = FT_OPEN_PATHNAME;
1170 args.pathname = (char*)pathname;
1171 args.stream = NULL;
1173 return FT_Open_Face( library, &args, face_index, aface );
1176 #endif /* defined( FT_MACINTOSH ) && !defined( DARWIN_NO_CARBON ) */
1179 /* documentation is in freetype.h */
1181 FT_EXPORT_DEF( FT_Error )
1182 FT_New_Memory_Face( FT_Library library,
1183 const FT_Byte* file_base,
1184 FT_Long file_size,
1185 FT_Long face_index,
1186 FT_Face *aface )
1188 FT_Open_Args args;
1191 /* test for valid `library' and `face' delayed to FT_Open_Face() */
1192 if ( !file_base )
1193 return FT_Err_Invalid_Argument;
1195 args.flags = FT_OPEN_MEMORY;
1196 args.memory_base = file_base;
1197 args.memory_size = file_size;
1198 args.stream = NULL;
1200 return FT_Open_Face( library, &args, face_index, aface );
1204 #ifdef FT_CONFIG_OPTION_MAC_FONTS
1206 /* The behavior here is very similar to that in base/ftmac.c, but it */
1207 /* is designed to work on non-mac systems, so no mac specific calls. */
1208 /* */
1209 /* We look at the file and determine if it is a mac dfont file or a mac */
1210 /* resource file, or a macbinary file containing a mac resource file. */
1211 /* */
1212 /* Unlike ftmac I'm not going to look at a `FOND'. I don't really see */
1213 /* the point, especially since there may be multiple `FOND' resources. */
1214 /* Instead I'll just look for `sfnt' and `POST' resources, ordered as */
1215 /* they occur in the file. */
1216 /* */
1217 /* Note that multiple `POST' resources do not mean multiple postscript */
1218 /* fonts; they all get jammed together to make what is essentially a */
1219 /* pfb file. */
1220 /* */
1221 /* We aren't interested in `NFNT' or `FONT' bitmap resources. */
1222 /* */
1223 /* As soon as we get an `sfnt' load it into memory and pass it off to */
1224 /* FT_Open_Face. */
1225 /* */
1226 /* If we have a (set of) `POST' resources, massage them into a (memory) */
1227 /* pfb file and pass that to FT_Open_Face. (As with ftmac.c I'm not */
1228 /* going to try to save the kerning info. After all that lives in the */
1229 /* `FOND' which isn't in the file containing the `POST' resources so */
1230 /* we don't really have access to it. */
1233 /* Finalizer for a memory stream; gets called by FT_Done_Face(). */
1234 /* It frees the memory it uses. */
1235 /* From ftmac.c. */
1236 static void
1237 memory_stream_close( FT_Stream stream )
1239 FT_Memory memory = stream->memory;
1242 FT_FREE( stream->base );
1244 stream->size = 0;
1245 stream->base = 0;
1246 stream->close = 0;
1250 /* Create a new memory stream from a buffer and a size. */
1251 /* From ftmac.c. */
1252 static FT_Error
1253 new_memory_stream( FT_Library library,
1254 FT_Byte* base,
1255 FT_ULong size,
1256 FT_Stream_CloseFunc close,
1257 FT_Stream *astream )
1259 FT_Error error;
1260 FT_Memory memory;
1261 FT_Stream stream;
1264 if ( !library )
1265 return FT_Err_Invalid_Library_Handle;
1267 if ( !base )
1268 return FT_Err_Invalid_Argument;
1270 *astream = 0;
1271 memory = library->memory;
1272 if ( FT_NEW( stream ) )
1273 goto Exit;
1275 FT_Stream_OpenMemory( stream, base, size );
1277 stream->close = close;
1279 *astream = stream;
1281 Exit:
1282 return error;
1286 /* Create a new FT_Face given a buffer and a driver name. */
1287 /* from ftmac.c */
1288 FT_LOCAL_DEF( FT_Error )
1289 open_face_from_buffer( FT_Library library,
1290 FT_Byte* base,
1291 FT_ULong size,
1292 FT_Long face_index,
1293 const char* driver_name,
1294 FT_Face *aface )
1296 FT_Open_Args args;
1297 FT_Error error;
1298 FT_Stream stream = NULL;
1299 FT_Memory memory = library->memory;
1302 error = new_memory_stream( library,
1303 base,
1304 size,
1305 memory_stream_close,
1306 &stream );
1307 if ( error )
1309 FT_FREE( base );
1310 return error;
1313 args.flags = FT_OPEN_STREAM;
1314 args.stream = stream;
1315 if ( driver_name )
1317 args.flags = args.flags | FT_OPEN_DRIVER;
1318 args.driver = FT_Get_Module( library, driver_name );
1321 #ifdef FT_MACINTOSH
1322 /* At this point, face_index has served its purpose; */
1323 /* whoever calls this function has already used it to */
1324 /* locate the correct font data. We should not propagate */
1325 /* this index to FT_Open_Face() (unless it is negative). */
1327 if ( face_index > 0 )
1328 face_index = 0;
1329 #endif
1331 error = FT_Open_Face( library, &args, face_index, aface );
1333 if ( error == FT_Err_Ok )
1334 (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
1335 else
1336 #ifdef FT_MACINTOSH
1337 FT_Stream_Free( stream, 0 );
1338 #else
1340 FT_Stream_Close( stream );
1341 FT_FREE( stream );
1343 #endif
1345 return error;
1349 /* Look up `TYP1' or `CID ' table from sfnt table directory. */
1350 /* `offset' and `length' must exclude the binary header in tables. */
1352 /* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
1353 /* format too. Here, since we can't expect that the TrueType font */
1354 /* driver is loaded unconditially, we must parse the font by */
1355 /* ourselves. We are only interested in the name of the table and */
1356 /* the offset. */
1358 static FT_Error
1359 ft_lookup_PS_in_sfnt_stream( FT_Stream stream,
1360 FT_Long face_index,
1361 FT_ULong* offset,
1362 FT_ULong* length,
1363 FT_Bool* is_sfnt_cid )
1365 FT_Error error;
1366 FT_UShort numTables;
1367 FT_Long pstable_index;
1368 FT_ULong tag;
1369 int i;
1372 *offset = 0;
1373 *length = 0;
1374 *is_sfnt_cid = FALSE;
1376 /* TODO: support for sfnt-wrapped PS/CID in TTC format */
1378 /* version check for 'typ1' (should be ignored?) */
1379 if ( FT_READ_ULONG( tag ) )
1380 return error;
1381 if ( tag != TTAG_typ1 )
1382 return FT_Err_Unknown_File_Format;
1384 if ( FT_READ_USHORT( numTables ) )
1385 return error;
1386 if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */
1387 return error;
1389 pstable_index = -1;
1390 *is_sfnt_cid = FALSE;
1392 for ( i = 0; i < numTables; i++ )
1394 if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) ||
1395 FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
1396 return error;
1398 if ( tag == TTAG_CID )
1400 pstable_index++;
1401 *offset += 22;
1402 *length -= 22;
1403 *is_sfnt_cid = TRUE;
1404 if ( face_index < 0 )
1405 return FT_Err_Ok;
1407 else if ( tag == TTAG_TYP1 )
1409 pstable_index++;
1410 *offset += 24;
1411 *length -= 24;
1412 *is_sfnt_cid = FALSE;
1413 if ( face_index < 0 )
1414 return FT_Err_Ok;
1416 if ( face_index >= 0 && pstable_index == face_index )
1417 return FT_Err_Ok;
1419 return FT_Err_Table_Missing;
1423 FT_LOCAL_DEF( FT_Error )
1424 open_face_PS_from_sfnt_stream( FT_Library library,
1425 FT_Stream stream,
1426 FT_Long face_index,
1427 FT_Int num_params,
1428 FT_Parameter *params,
1429 FT_Face *aface )
1431 FT_Error error;
1432 FT_Memory memory = library->memory;
1433 FT_ULong offset, length;
1434 FT_Long pos;
1435 FT_Bool is_sfnt_cid;
1436 FT_Byte* sfnt_ps;
1438 FT_UNUSED( num_params );
1439 FT_UNUSED( params );
1442 pos = FT_Stream_Pos( stream );
1444 error = ft_lookup_PS_in_sfnt_stream( stream,
1445 face_index,
1446 &offset,
1447 &length,
1448 &is_sfnt_cid );
1449 if ( error )
1450 goto Exit;
1452 if ( FT_Stream_Seek( stream, pos + offset ) )
1453 goto Exit;
1455 if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
1456 goto Exit;
1458 error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
1459 if ( error )
1460 goto Exit;
1462 error = open_face_from_buffer( library,
1463 sfnt_ps,
1464 length,
1465 face_index < 0 ? face_index : 0,
1466 is_sfnt_cid ? "cid" : "type1",
1467 aface );
1468 Exit:
1470 FT_Error error1;
1473 if ( error == FT_Err_Unknown_File_Format )
1475 error1 = FT_Stream_Seek( stream, pos );
1476 if ( error1 )
1477 return error1;
1480 return error;
1485 #if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
1487 /* The resource header says we've got resource_cnt `POST' (type1) */
1488 /* resources in this file. They all need to be coalesced into */
1489 /* one lump which gets passed on to the type1 driver. */
1490 /* Here can be only one PostScript font in a file so face_index */
1491 /* must be 0 (or -1). */
1492 /* */
1493 static FT_Error
1494 Mac_Read_POST_Resource( FT_Library library,
1495 FT_Stream stream,
1496 FT_Long *offsets,
1497 FT_Long resource_cnt,
1498 FT_Long face_index,
1499 FT_Face *aface )
1501 FT_Error error = FT_Err_Cannot_Open_Resource;
1502 FT_Memory memory = library->memory;
1503 FT_Byte* pfb_data;
1504 int i, type, flags;
1505 FT_Long len;
1506 FT_Long pfb_len, pfb_pos, pfb_lenpos;
1507 FT_Long rlen, temp;
1510 if ( face_index == -1 )
1511 face_index = 0;
1512 if ( face_index != 0 )
1513 return error;
1515 /* Find the length of all the POST resources, concatenated. Assume */
1516 /* worst case (each resource in its own section). */
1517 pfb_len = 0;
1518 for ( i = 0; i < resource_cnt; ++i )
1520 error = FT_Stream_Seek( stream, offsets[i] );
1521 if ( error )
1522 goto Exit;
1523 if ( FT_READ_LONG( temp ) )
1524 goto Exit;
1525 pfb_len += temp + 6;
1528 if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
1529 goto Exit;
1531 pfb_data[0] = 0x80;
1532 pfb_data[1] = 1; /* Ascii section */
1533 pfb_data[2] = 0; /* 4-byte length, fill in later */
1534 pfb_data[3] = 0;
1535 pfb_data[4] = 0;
1536 pfb_data[5] = 0;
1537 pfb_pos = 6;
1538 pfb_lenpos = 2;
1540 len = 0;
1541 type = 1;
1542 for ( i = 0; i < resource_cnt; ++i )
1544 error = FT_Stream_Seek( stream, offsets[i] );
1545 if ( error )
1546 goto Exit2;
1547 if ( FT_READ_LONG( rlen ) )
1548 goto Exit;
1549 if ( FT_READ_USHORT( flags ) )
1550 goto Exit;
1551 rlen -= 2; /* the flags are part of the resource */
1552 if ( ( flags >> 8 ) == type )
1553 len += rlen;
1554 else
1556 pfb_data[pfb_lenpos ] = (FT_Byte)( len );
1557 pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
1558 pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
1559 pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
1561 if ( ( flags >> 8 ) == 5 ) /* End of font mark */
1562 break;
1564 pfb_data[pfb_pos++] = 0x80;
1566 type = flags >> 8;
1567 len = rlen;
1569 pfb_data[pfb_pos++] = (FT_Byte)type;
1570 pfb_lenpos = pfb_pos;
1571 pfb_data[pfb_pos++] = 0; /* 4-byte length, fill in later */
1572 pfb_data[pfb_pos++] = 0;
1573 pfb_data[pfb_pos++] = 0;
1574 pfb_data[pfb_pos++] = 0;
1577 error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
1578 pfb_pos += rlen;
1581 pfb_data[pfb_pos++] = 0x80;
1582 pfb_data[pfb_pos++] = 3;
1584 pfb_data[pfb_lenpos ] = (FT_Byte)( len );
1585 pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
1586 pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
1587 pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
1589 return open_face_from_buffer( library,
1590 pfb_data,
1591 pfb_pos,
1592 face_index,
1593 "type1",
1594 aface );
1596 Exit2:
1597 FT_FREE( pfb_data );
1599 Exit:
1600 return error;
1604 /* The resource header says we've got resource_cnt `sfnt' */
1605 /* (TrueType/OpenType) resources in this file. Look through */
1606 /* them for the one indicated by face_index, load it into mem, */
1607 /* pass it on the the truetype driver and return it. */
1608 /* */
1609 static FT_Error
1610 Mac_Read_sfnt_Resource( FT_Library library,
1611 FT_Stream stream,
1612 FT_Long *offsets,
1613 FT_Long resource_cnt,
1614 FT_Long face_index,
1615 FT_Face *aface )
1617 FT_Memory memory = library->memory;
1618 FT_Byte* sfnt_data;
1619 FT_Error error;
1620 FT_Long flag_offset;
1621 FT_Long rlen;
1622 int is_cff;
1623 FT_Long face_index_in_resource = 0;
1626 if ( face_index == -1 )
1627 face_index = 0;
1628 if ( face_index >= resource_cnt )
1629 return FT_Err_Cannot_Open_Resource;
1631 flag_offset = offsets[face_index];
1632 error = FT_Stream_Seek( stream, flag_offset );
1633 if ( error )
1634 goto Exit;
1636 if ( FT_READ_LONG( rlen ) )
1637 goto Exit;
1638 if ( rlen == -1 )
1639 return FT_Err_Cannot_Open_Resource;
1641 error = open_face_PS_from_sfnt_stream( library,
1642 stream,
1643 face_index,
1644 0, NULL,
1645 aface );
1646 if ( !error )
1647 goto Exit;
1649 /* rewind sfnt stream before open_face_PS_from_sfnt_stream() */
1650 if ( FT_Stream_Seek( stream, flag_offset + 4 ) )
1651 goto Exit;
1653 if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) )
1654 return error;
1655 error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
1656 if ( error )
1657 goto Exit;
1659 is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
1660 error = open_face_from_buffer( library,
1661 sfnt_data,
1662 rlen,
1663 face_index_in_resource,
1664 is_cff ? "cff" : "truetype",
1665 aface );
1667 Exit:
1668 return error;
1672 /* Check for a valid resource fork header, or a valid dfont */
1673 /* header. In a resource fork the first 16 bytes are repeated */
1674 /* at the location specified by bytes 4-7. In a dfont bytes */
1675 /* 4-7 point to 16 bytes of zeroes instead. */
1676 /* */
1677 static FT_Error
1678 IsMacResource( FT_Library library,
1679 FT_Stream stream,
1680 FT_Long resource_offset,
1681 FT_Long face_index,
1682 FT_Face *aface )
1684 FT_Memory memory = library->memory;
1685 FT_Error error;
1686 FT_Long map_offset, rdara_pos;
1687 FT_Long *data_offsets;
1688 FT_Long count;
1691 error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
1692 &map_offset, &rdara_pos );
1693 if ( error )
1694 return error;
1696 error = FT_Raccess_Get_DataOffsets( library, stream,
1697 map_offset, rdara_pos,
1698 TTAG_POST,
1699 &data_offsets, &count );
1700 if ( !error )
1702 error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
1703 face_index, aface );
1704 FT_FREE( data_offsets );
1705 /* POST exists in an LWFN providing a single face */
1706 if ( !error )
1707 (*aface)->num_faces = 1;
1708 return error;
1711 error = FT_Raccess_Get_DataOffsets( library, stream,
1712 map_offset, rdara_pos,
1713 TTAG_sfnt,
1714 &data_offsets, &count );
1715 if ( !error )
1717 FT_Long face_index_internal = face_index % count;
1720 error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
1721 face_index_internal, aface );
1722 FT_FREE( data_offsets );
1723 if ( !error )
1724 (*aface)->num_faces = count;
1727 return error;
1731 /* Check for a valid macbinary header, and if we find one */
1732 /* check that the (flattened) resource fork in it is valid. */
1733 /* */
1734 static FT_Error
1735 IsMacBinary( FT_Library library,
1736 FT_Stream stream,
1737 FT_Long face_index,
1738 FT_Face *aface )
1740 unsigned char header[128];
1741 FT_Error error;
1742 FT_Long dlen, offset;
1745 if ( NULL == stream )
1746 return FT_Err_Invalid_Stream_Operation;
1748 error = FT_Stream_Seek( stream, 0 );
1749 if ( error )
1750 goto Exit;
1752 error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
1753 if ( error )
1754 goto Exit;
1756 if ( header[ 0] != 0 ||
1757 header[74] != 0 ||
1758 header[82] != 0 ||
1759 header[ 1] == 0 ||
1760 header[ 1] > 33 ||
1761 header[63] != 0 ||
1762 header[2 + header[1]] != 0 )
1763 return FT_Err_Unknown_File_Format;
1765 dlen = ( header[0x53] << 24 ) |
1766 ( header[0x54] << 16 ) |
1767 ( header[0x55] << 8 ) |
1768 header[0x56];
1769 #if 0
1770 rlen = ( header[0x57] << 24 ) |
1771 ( header[0x58] << 16 ) |
1772 ( header[0x59] << 8 ) |
1773 header[0x5a];
1774 #endif /* 0 */
1775 offset = 128 + ( ( dlen + 127 ) & ~127 );
1777 return IsMacResource( library, stream, offset, face_index, aface );
1779 Exit:
1780 return error;
1784 static FT_Error
1785 load_face_in_embedded_rfork( FT_Library library,
1786 FT_Stream stream,
1787 FT_Long face_index,
1788 FT_Face *aface,
1789 const FT_Open_Args *args )
1792 #undef FT_COMPONENT
1793 #define FT_COMPONENT trace_raccess
1795 FT_Memory memory = library->memory;
1796 FT_Error error = FT_Err_Unknown_File_Format;
1797 int i;
1799 char * file_names[FT_RACCESS_N_RULES];
1800 FT_Long offsets[FT_RACCESS_N_RULES];
1801 FT_Error errors[FT_RACCESS_N_RULES];
1803 FT_Open_Args args2;
1804 FT_Stream stream2 = 0;
1807 FT_Raccess_Guess( library, stream,
1808 args->pathname, file_names, offsets, errors );
1810 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
1812 if ( errors[i] )
1814 FT_TRACE3(( "Error[%d] has occurred in rule %d\n", errors[i], i ));
1815 continue;
1818 args2.flags = FT_OPEN_PATHNAME;
1819 args2.pathname = file_names[i] ? file_names[i] : args->pathname;
1821 FT_TRACE3(( "Try rule %d: %s (offset=%d) ...",
1822 i, args2.pathname, offsets[i] ));
1824 error = FT_Stream_New( library, &args2, &stream2 );
1825 if ( error )
1827 FT_TRACE3(( "failed\n" ));
1828 continue;
1831 error = IsMacResource( library, stream2, offsets[i],
1832 face_index, aface );
1833 FT_Stream_Free( stream2, 0 );
1835 FT_TRACE3(( "%s\n", error ? "failed": "successful" ));
1837 if ( !error )
1838 break;
1841 for (i = 0; i < FT_RACCESS_N_RULES; i++)
1843 if ( file_names[i] )
1844 FT_FREE( file_names[i] );
1847 /* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */
1848 if ( error )
1849 error = FT_Err_Unknown_File_Format;
1851 return error;
1853 #undef FT_COMPONENT
1854 #define FT_COMPONENT trace_objs
1859 /* Check for some macintosh formats without Carbon framework. */
1860 /* Is this a macbinary file? If so look at the resource fork. */
1861 /* Is this a mac dfont file? */
1862 /* Is this an old style resource fork? (in data) */
1863 /* Else call load_face_in_embedded_rfork to try extra rules */
1864 /* (defined in `ftrfork.c'). */
1865 /* */
1866 static FT_Error
1867 load_mac_face( FT_Library library,
1868 FT_Stream stream,
1869 FT_Long face_index,
1870 FT_Face *aface,
1871 const FT_Open_Args *args )
1873 FT_Error error;
1874 FT_UNUSED( args );
1877 error = IsMacBinary( library, stream, face_index, aface );
1878 if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format )
1881 #undef FT_COMPONENT
1882 #define FT_COMPONENT trace_raccess
1884 FT_TRACE3(( "Try as dfont: %s ...", args->pathname ));
1886 error = IsMacResource( library, stream, 0, face_index, aface );
1888 FT_TRACE3(( "%s\n", error ? "failed" : "successful" ));
1890 #undef FT_COMPONENT
1891 #define FT_COMPONENT trace_objs
1895 if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format ||
1896 FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation ) &&
1897 ( args->flags & FT_OPEN_PATHNAME ) )
1898 error = load_face_in_embedded_rfork( library, stream,
1899 face_index, aface, args );
1900 return error;
1902 #endif
1904 #endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
1907 /* documentation is in freetype.h */
1909 FT_EXPORT_DEF( FT_Error )
1910 FT_Open_Face( FT_Library library,
1911 const FT_Open_Args* args,
1912 FT_Long face_index,
1913 FT_Face *aface )
1915 FT_Error error;
1916 FT_Driver driver;
1917 FT_Memory memory;
1918 FT_Stream stream = 0;
1919 FT_Face face = 0;
1920 FT_ListNode node = 0;
1921 FT_Bool external_stream;
1922 FT_Module* cur;
1923 FT_Module* limit;
1926 /* test for valid `library' delayed to */
1927 /* FT_Stream_New() */
1929 if ( ( !aface && face_index >= 0 ) || !args )
1930 return FT_Err_Invalid_Argument;
1932 external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
1933 args->stream );
1935 /* create input stream */
1936 error = FT_Stream_New( library, args, &stream );
1937 if ( error )
1938 goto Fail3;
1940 memory = library->memory;
1942 /* If the font driver is specified in the `args' structure, use */
1943 /* it. Otherwise, we scan the list of registered drivers. */
1944 if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver )
1946 driver = FT_DRIVER( args->driver );
1948 /* not all modules are drivers, so check... */
1949 if ( FT_MODULE_IS_DRIVER( driver ) )
1951 FT_Int num_params = 0;
1952 FT_Parameter* params = 0;
1955 if ( args->flags & FT_OPEN_PARAMS )
1957 num_params = args->num_params;
1958 params = args->params;
1961 error = open_face( driver, stream, face_index,
1962 num_params, params, &face );
1963 if ( !error )
1964 goto Success;
1966 else
1967 error = FT_Err_Invalid_Handle;
1969 FT_Stream_Free( stream, external_stream );
1970 goto Fail;
1972 else
1974 /* check each font driver for an appropriate format */
1975 cur = library->modules;
1976 limit = cur + library->num_modules;
1979 for ( ; cur < limit; cur++ )
1981 /* not all modules are font drivers, so check... */
1982 if ( FT_MODULE_IS_DRIVER( cur[0] ) )
1984 FT_Int num_params = 0;
1985 FT_Parameter* params = 0;
1988 driver = FT_DRIVER( cur[0] );
1990 if ( args->flags & FT_OPEN_PARAMS )
1992 num_params = args->num_params;
1993 params = args->params;
1996 error = open_face( driver, stream, face_index,
1997 num_params, params, &face );
1998 if ( !error )
1999 goto Success;
2001 #ifdef FT_CONFIG_OPTION_MAC_FONTS
2002 if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 &&
2003 FT_ERROR_BASE( error ) == FT_Err_Table_Missing )
2005 /* TrueType but essential tables are missing */
2006 if ( FT_Stream_Seek( stream, 0 ) )
2007 break;
2009 error = open_face_PS_from_sfnt_stream( library,
2010 stream,
2011 face_index,
2012 num_params,
2013 params,
2014 aface );
2015 if ( !error )
2017 FT_Stream_Free( stream, external_stream );
2018 return error;
2021 #endif
2023 if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
2024 goto Fail3;
2028 Fail3:
2029 /* If we are on the mac, and we get an FT_Err_Invalid_Stream_Operation */
2030 /* it may be because we have an empty data fork, so we need to check */
2031 /* the resource fork. */
2032 if ( FT_ERROR_BASE( error ) != FT_Err_Cannot_Open_Stream &&
2033 FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format &&
2034 FT_ERROR_BASE( error ) != FT_Err_Invalid_Stream_Operation )
2035 goto Fail2;
2037 #if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
2038 error = load_mac_face( library, stream, face_index, aface, args );
2039 if ( !error )
2041 /* We don't want to go to Success here. We've already done that. */
2042 /* On the other hand, if we succeeded we still need to close this */
2043 /* stream (we opened a different stream which extracted the */
2044 /* interesting information out of this stream here. That stream */
2045 /* will still be open and the face will point to it). */
2046 FT_Stream_Free( stream, external_stream );
2047 return error;
2050 if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
2051 goto Fail2;
2052 #endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
2054 /* no driver is able to handle this format */
2055 error = FT_Err_Unknown_File_Format;
2057 Fail2:
2058 FT_Stream_Free( stream, external_stream );
2059 goto Fail;
2062 Success:
2063 FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
2065 /* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
2066 if ( external_stream )
2067 face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
2069 /* add the face object to its driver's list */
2070 if ( FT_NEW( node ) )
2071 goto Fail;
2073 node->data = face;
2074 /* don't assume driver is the same as face->driver, so use */
2075 /* face->driver instead. */
2076 FT_List_Add( &face->driver->faces_list, node );
2078 /* now allocate a glyph slot object for the face */
2079 FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
2081 if ( face_index >= 0 )
2083 error = FT_New_GlyphSlot( face, NULL );
2084 if ( error )
2085 goto Fail;
2087 /* finally, allocate a size object for the face */
2089 FT_Size size;
2092 FT_TRACE4(( "FT_Open_Face: Creating size object\n" ));
2094 error = FT_New_Size( face, &size );
2095 if ( error )
2096 goto Fail;
2098 face->size = size;
2102 /* some checks */
2104 if ( FT_IS_SCALABLE( face ) )
2106 if ( face->height < 0 )
2107 face->height = (FT_Short)-face->height;
2109 if ( !FT_HAS_VERTICAL( face ) )
2110 face->max_advance_height = (FT_Short)face->height;
2113 if ( FT_HAS_FIXED_SIZES( face ) )
2115 FT_Int i;
2118 for ( i = 0; i < face->num_fixed_sizes; i++ )
2120 FT_Bitmap_Size* bsize = face->available_sizes + i;
2123 if ( bsize->height < 0 )
2124 bsize->height = (FT_Short)-bsize->height;
2125 if ( bsize->x_ppem < 0 )
2126 bsize->x_ppem = (FT_Short)-bsize->x_ppem;
2127 if ( bsize->y_ppem < 0 )
2128 bsize->y_ppem = -bsize->y_ppem;
2132 /* initialize internal face data */
2134 FT_Face_Internal internal = face->internal;
2137 internal->transform_matrix.xx = 0x10000L;
2138 internal->transform_matrix.xy = 0;
2139 internal->transform_matrix.yx = 0;
2140 internal->transform_matrix.yy = 0x10000L;
2142 internal->transform_delta.x = 0;
2143 internal->transform_delta.y = 0;
2146 if ( aface )
2147 *aface = face;
2148 else
2149 FT_Done_Face( face );
2151 goto Exit;
2153 Fail:
2154 FT_Done_Face( face );
2156 Exit:
2157 FT_TRACE4(( "FT_Open_Face: Return %d\n", error ));
2159 return error;
2163 /* documentation is in freetype.h */
2165 FT_EXPORT_DEF( FT_Error )
2166 FT_Attach_File( FT_Face face,
2167 const char* filepathname )
2169 FT_Open_Args open;
2172 /* test for valid `face' delayed to FT_Attach_Stream() */
2174 if ( !filepathname )
2175 return FT_Err_Invalid_Argument;
2177 open.stream = NULL;
2178 open.flags = FT_OPEN_PATHNAME;
2179 open.pathname = (char*)filepathname;
2181 return FT_Attach_Stream( face, &open );
2185 /* documentation is in freetype.h */
2187 FT_EXPORT_DEF( FT_Error )
2188 FT_Attach_Stream( FT_Face face,
2189 FT_Open_Args* parameters )
2191 FT_Stream stream;
2192 FT_Error error;
2193 FT_Driver driver;
2195 FT_Driver_Class clazz;
2198 /* test for valid `parameters' delayed to FT_Stream_New() */
2200 if ( !face )
2201 return FT_Err_Invalid_Face_Handle;
2203 driver = face->driver;
2204 if ( !driver )
2205 return FT_Err_Invalid_Driver_Handle;
2207 error = FT_Stream_New( driver->root.library, parameters, &stream );
2208 if ( error )
2209 goto Exit;
2211 /* we implement FT_Attach_Stream in each driver through the */
2212 /* `attach_file' interface */
2214 error = FT_Err_Unimplemented_Feature;
2215 clazz = driver->clazz;
2216 if ( clazz->attach_file )
2217 error = clazz->attach_file( face, stream );
2219 /* close the attached stream */
2220 FT_Stream_Free( stream,
2221 (FT_Bool)( parameters->stream &&
2222 ( parameters->flags & FT_OPEN_STREAM ) ) );
2224 Exit:
2225 return error;
2229 /* documentation is in freetype.h */
2231 FT_EXPORT_DEF( FT_Error )
2232 FT_Done_Face( FT_Face face )
2234 FT_Error error;
2235 FT_Driver driver;
2236 FT_Memory memory;
2237 FT_ListNode node;
2240 error = FT_Err_Invalid_Face_Handle;
2241 if ( face && face->driver )
2243 driver = face->driver;
2244 memory = driver->root.memory;
2246 /* find face in driver's list */
2247 node = FT_List_Find( &driver->faces_list, face );
2248 if ( node )
2250 /* remove face object from the driver's list */
2251 FT_List_Remove( &driver->faces_list, node );
2252 FT_FREE( node );
2254 /* now destroy the object proper */
2255 destroy_face( memory, face, driver );
2256 error = FT_Err_Ok;
2259 return error;
2263 /* documentation is in ftobjs.h */
2265 FT_EXPORT_DEF( FT_Error )
2266 FT_New_Size( FT_Face face,
2267 FT_Size *asize )
2269 FT_Error error;
2270 FT_Memory memory;
2271 FT_Driver driver;
2272 FT_Driver_Class clazz;
2274 FT_Size size = 0;
2275 FT_ListNode node = 0;
2278 if ( !face )
2279 return FT_Err_Invalid_Face_Handle;
2281 if ( !asize )
2282 return FT_Err_Invalid_Size_Handle;
2284 if ( !face->driver )
2285 return FT_Err_Invalid_Driver_Handle;
2287 *asize = 0;
2289 driver = face->driver;
2290 clazz = driver->clazz;
2291 memory = face->memory;
2293 /* Allocate new size object and perform basic initialisation */
2294 if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) )
2295 goto Exit;
2297 size->face = face;
2299 /* for now, do not use any internal fields in size objects */
2300 size->internal = 0;
2302 if ( clazz->init_size )
2303 error = clazz->init_size( size );
2305 /* in case of success, add to the face's list */
2306 if ( !error )
2308 *asize = size;
2309 node->data = size;
2310 FT_List_Add( &face->sizes_list, node );
2313 Exit:
2314 if ( error )
2316 FT_FREE( node );
2317 FT_FREE( size );
2320 return error;
2324 /* documentation is in ftobjs.h */
2326 FT_EXPORT_DEF( FT_Error )
2327 FT_Done_Size( FT_Size size )
2329 FT_Error error;
2330 FT_Driver driver;
2331 FT_Memory memory;
2332 FT_Face face;
2333 FT_ListNode node;
2336 if ( !size )
2337 return FT_Err_Invalid_Size_Handle;
2339 face = size->face;
2340 if ( !face )
2341 return FT_Err_Invalid_Face_Handle;
2343 driver = face->driver;
2344 if ( !driver )
2345 return FT_Err_Invalid_Driver_Handle;
2347 memory = driver->root.memory;
2349 error = FT_Err_Ok;
2350 node = FT_List_Find( &face->sizes_list, size );
2351 if ( node )
2353 FT_List_Remove( &face->sizes_list, node );
2354 FT_FREE( node );
2356 if ( face->size == size )
2358 face->size = 0;
2359 if ( face->sizes_list.head )
2360 face->size = (FT_Size)(face->sizes_list.head->data);
2363 destroy_size( memory, size, driver );
2365 else
2366 error = FT_Err_Invalid_Size_Handle;
2368 return error;
2372 /* documentation is in ftobjs.h */
2374 FT_BASE_DEF( FT_Error )
2375 FT_Match_Size( FT_Face face,
2376 FT_Size_Request req,
2377 FT_Bool ignore_width,
2378 FT_ULong* size_index )
2380 FT_Int i;
2381 FT_Long w, h;
2384 if ( !FT_HAS_FIXED_SIZES( face ) )
2385 return FT_Err_Invalid_Face_Handle;
2387 /* FT_Bitmap_Size doesn't provide enough info... */
2388 if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
2389 return FT_Err_Unimplemented_Feature;
2391 w = FT_REQUEST_WIDTH ( req );
2392 h = FT_REQUEST_HEIGHT( req );
2394 if ( req->width && !req->height )
2395 h = w;
2396 else if ( !req->width && req->height )
2397 w = h;
2399 w = FT_PIX_ROUND( w );
2400 h = FT_PIX_ROUND( h );
2402 for ( i = 0; i < face->num_fixed_sizes; i++ )
2404 FT_Bitmap_Size* bsize = face->available_sizes + i;
2407 if ( h != FT_PIX_ROUND( bsize->y_ppem ) )
2408 continue;
2410 if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width )
2412 if ( size_index )
2413 *size_index = (FT_ULong)i;
2415 return FT_Err_Ok;
2419 return FT_Err_Invalid_Pixel_Size;
2423 /* documentation is in ftobjs.h */
2425 FT_BASE_DEF( void )
2426 ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics,
2427 FT_Pos advance )
2429 FT_Pos height = metrics->height;
2432 /* compensate for glyph with bbox above/below the baseline */
2433 if ( metrics->horiBearingY < 0 )
2435 if ( height < metrics->horiBearingY )
2436 height = metrics->horiBearingY;
2438 else if ( metrics->horiBearingY > 0 )
2439 height -= metrics->horiBearingY;
2441 /* the factor 1.2 is a heuristical value */
2442 if ( !advance )
2443 advance = height * 12 / 10;
2445 metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2;
2446 metrics->vertBearingY = ( advance - height ) / 2;
2447 metrics->vertAdvance = advance;
2451 static void
2452 ft_recompute_scaled_metrics( FT_Face face,
2453 FT_Size_Metrics* metrics )
2455 /* Compute root ascender, descender, test height, and max_advance */
2457 #ifdef GRID_FIT_METRICS
2458 metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender,
2459 metrics->y_scale ) );
2461 metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender,
2462 metrics->y_scale ) );
2464 metrics->height = FT_PIX_ROUND( FT_MulFix( face->height,
2465 metrics->y_scale ) );
2467 metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width,
2468 metrics->x_scale ) );
2469 #else /* !GRID_FIT_METRICS */
2470 metrics->ascender = FT_MulFix( face->ascender,
2471 metrics->y_scale );
2473 metrics->descender = FT_MulFix( face->descender,
2474 metrics->y_scale );
2476 metrics->height = FT_MulFix( face->height,
2477 metrics->y_scale );
2479 metrics->max_advance = FT_MulFix( face->max_advance_width,
2480 metrics->x_scale );
2481 #endif /* !GRID_FIT_METRICS */
2485 FT_BASE_DEF( void )
2486 FT_Select_Metrics( FT_Face face,
2487 FT_ULong strike_index )
2489 FT_Size_Metrics* metrics;
2490 FT_Bitmap_Size* bsize;
2493 metrics = &face->size->metrics;
2494 bsize = face->available_sizes + strike_index;
2496 metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 );
2497 metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 );
2499 if ( FT_IS_SCALABLE( face ) )
2501 metrics->x_scale = FT_DivFix( bsize->x_ppem,
2502 face->units_per_EM );
2503 metrics->y_scale = FT_DivFix( bsize->y_ppem,
2504 face->units_per_EM );
2506 ft_recompute_scaled_metrics( face, metrics );
2508 else
2510 metrics->x_scale = 1L << 16;
2511 metrics->y_scale = 1L << 16;
2512 metrics->ascender = bsize->y_ppem;
2513 metrics->descender = 0;
2514 metrics->height = bsize->height << 6;
2515 metrics->max_advance = bsize->x_ppem;
2520 FT_BASE_DEF( void )
2521 FT_Request_Metrics( FT_Face face,
2522 FT_Size_Request req )
2524 FT_Size_Metrics* metrics;
2527 metrics = &face->size->metrics;
2529 if ( FT_IS_SCALABLE( face ) )
2531 FT_Long w = 0, h = 0, scaled_w = 0, scaled_h = 0;
2534 switch ( req->type )
2536 case FT_SIZE_REQUEST_TYPE_NOMINAL:
2537 w = h = face->units_per_EM;
2538 break;
2540 case FT_SIZE_REQUEST_TYPE_REAL_DIM:
2541 w = h = face->ascender - face->descender;
2542 break;
2544 case FT_SIZE_REQUEST_TYPE_BBOX:
2545 w = face->bbox.xMax - face->bbox.xMin;
2546 h = face->bbox.yMax - face->bbox.yMin;
2547 break;
2549 case FT_SIZE_REQUEST_TYPE_CELL:
2550 w = face->max_advance_width;
2551 h = face->ascender - face->descender;
2552 break;
2554 case FT_SIZE_REQUEST_TYPE_SCALES:
2555 metrics->x_scale = (FT_Fixed)req->width;
2556 metrics->y_scale = (FT_Fixed)req->height;
2557 if ( !metrics->x_scale )
2558 metrics->x_scale = metrics->y_scale;
2559 else if ( !metrics->y_scale )
2560 metrics->y_scale = metrics->x_scale;
2561 goto Calculate_Ppem;
2563 case FT_SIZE_REQUEST_TYPE_MAX:
2564 break;
2567 /* to be on the safe side */
2568 if ( w < 0 )
2569 w = -w;
2571 if ( h < 0 )
2572 h = -h;
2574 scaled_w = FT_REQUEST_WIDTH ( req );
2575 scaled_h = FT_REQUEST_HEIGHT( req );
2577 /* determine scales */
2578 if ( req->width )
2580 metrics->x_scale = FT_DivFix( scaled_w, w );
2582 if ( req->height )
2584 metrics->y_scale = FT_DivFix( scaled_h, h );
2586 if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
2588 if ( metrics->y_scale > metrics->x_scale )
2589 metrics->y_scale = metrics->x_scale;
2590 else
2591 metrics->x_scale = metrics->y_scale;
2594 else
2596 metrics->y_scale = metrics->x_scale;
2597 scaled_h = FT_MulDiv( scaled_w, h, w );
2600 else
2602 metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
2603 scaled_w = FT_MulDiv( scaled_h, w, h );
2606 Calculate_Ppem:
2607 /* calculate the ppems */
2608 if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
2610 scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale );
2611 scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
2614 metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 );
2615 metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 );
2617 ft_recompute_scaled_metrics( face, metrics );
2619 else
2621 FT_ZERO( metrics );
2622 metrics->x_scale = 1L << 16;
2623 metrics->y_scale = 1L << 16;
2628 /* documentation is in freetype.h */
2630 FT_EXPORT_DEF( FT_Error )
2631 FT_Select_Size( FT_Face face,
2632 FT_Int strike_index )
2634 FT_Driver_Class clazz;
2637 if ( !face || !FT_HAS_FIXED_SIZES( face ) )
2638 return FT_Err_Invalid_Face_Handle;
2640 if ( strike_index < 0 || strike_index >= face->num_fixed_sizes )
2641 return FT_Err_Invalid_Argument;
2643 clazz = face->driver->clazz;
2645 if ( clazz->select_size )
2646 return clazz->select_size( face->size, (FT_ULong)strike_index );
2648 FT_Select_Metrics( face, (FT_ULong)strike_index );
2650 return FT_Err_Ok;
2654 /* documentation is in freetype.h */
2656 FT_EXPORT_DEF( FT_Error )
2657 FT_Request_Size( FT_Face face,
2658 FT_Size_Request req )
2660 FT_Driver_Class clazz;
2661 FT_ULong strike_index;
2664 if ( !face )
2665 return FT_Err_Invalid_Face_Handle;
2667 if ( !req || req->width < 0 || req->height < 0 ||
2668 req->type >= FT_SIZE_REQUEST_TYPE_MAX )
2669 return FT_Err_Invalid_Argument;
2671 clazz = face->driver->clazz;
2673 if ( clazz->request_size )
2674 return clazz->request_size( face->size, req );
2677 * The reason that a driver doesn't have `request_size' defined is
2678 * either that the scaling here suffices or that the supported formats
2679 * are bitmap-only and size matching is not implemented.
2681 * In the latter case, a simple size matching is done.
2683 if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) )
2685 FT_Error error;
2688 error = FT_Match_Size( face, req, 0, &strike_index );
2689 if ( error )
2690 return error;
2692 FT_TRACE3(( "FT_Request_Size: bitmap strike %lu matched\n",
2693 strike_index ));
2695 return FT_Select_Size( face, (FT_Int)strike_index );
2698 FT_Request_Metrics( face, req );
2700 return FT_Err_Ok;
2704 /* documentation is in freetype.h */
2706 FT_EXPORT_DEF( FT_Error )
2707 FT_Set_Char_Size( FT_Face face,
2708 FT_F26Dot6 char_width,
2709 FT_F26Dot6 char_height,
2710 FT_UInt horz_resolution,
2711 FT_UInt vert_resolution )
2713 FT_Size_RequestRec req;
2716 if ( !char_width )
2717 char_width = char_height;
2718 else if ( !char_height )
2719 char_height = char_width;
2721 if ( !horz_resolution )
2722 horz_resolution = vert_resolution;
2723 else if ( !vert_resolution )
2724 vert_resolution = horz_resolution;
2726 if ( char_width < 1 * 64 )
2727 char_width = 1 * 64;
2728 if ( char_height < 1 * 64 )
2729 char_height = 1 * 64;
2731 if ( !horz_resolution )
2732 horz_resolution = vert_resolution = 72;
2734 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
2735 req.width = char_width;
2736 req.height = char_height;
2737 req.horiResolution = horz_resolution;
2738 req.vertResolution = vert_resolution;
2740 return FT_Request_Size( face, &req );
2744 /* documentation is in freetype.h */
2746 FT_EXPORT_DEF( FT_Error )
2747 FT_Set_Pixel_Sizes( FT_Face face,
2748 FT_UInt pixel_width,
2749 FT_UInt pixel_height )
2751 FT_Size_RequestRec req;
2754 if ( pixel_width == 0 )
2755 pixel_width = pixel_height;
2756 else if ( pixel_height == 0 )
2757 pixel_height = pixel_width;
2759 if ( pixel_width < 1 )
2760 pixel_width = 1;
2761 if ( pixel_height < 1 )
2762 pixel_height = 1;
2764 /* use `>=' to avoid potential compiler warning on 16bit platforms */
2765 if ( pixel_width >= 0xFFFFU )
2766 pixel_width = 0xFFFFU;
2767 if ( pixel_height >= 0xFFFFU )
2768 pixel_height = 0xFFFFU;
2770 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
2771 req.width = pixel_width << 6;
2772 req.height = pixel_height << 6;
2773 req.horiResolution = 0;
2774 req.vertResolution = 0;
2776 return FT_Request_Size( face, &req );
2780 /* documentation is in freetype.h */
2782 FT_EXPORT_DEF( FT_Error )
2783 FT_Get_Kerning( FT_Face face,
2784 FT_UInt left_glyph,
2785 FT_UInt right_glyph,
2786 FT_UInt kern_mode,
2787 FT_Vector *akerning )
2789 FT_Error error = FT_Err_Ok;
2790 FT_Driver driver;
2793 if ( !face )
2794 return FT_Err_Invalid_Face_Handle;
2796 if ( !akerning )
2797 return FT_Err_Invalid_Argument;
2799 driver = face->driver;
2801 akerning->x = 0;
2802 akerning->y = 0;
2804 if ( driver->clazz->get_kerning )
2806 error = driver->clazz->get_kerning( face,
2807 left_glyph,
2808 right_glyph,
2809 akerning );
2810 if ( !error )
2812 if ( kern_mode != FT_KERNING_UNSCALED )
2814 akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale );
2815 akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale );
2817 if ( kern_mode != FT_KERNING_UNFITTED )
2819 /* we scale down kerning values for small ppem values */
2820 /* to avoid that rounding makes them too big. */
2821 /* `25' has been determined heuristically. */
2822 if ( face->size->metrics.x_ppem < 25 )
2823 akerning->x = FT_MulDiv( akerning->x,
2824 face->size->metrics.x_ppem, 25 );
2825 if ( face->size->metrics.y_ppem < 25 )
2826 akerning->y = FT_MulDiv( akerning->y,
2827 face->size->metrics.y_ppem, 25 );
2829 akerning->x = FT_PIX_ROUND( akerning->x );
2830 akerning->y = FT_PIX_ROUND( akerning->y );
2836 return error;
2840 /* documentation is in freetype.h */
2842 FT_EXPORT_DEF( FT_Error )
2843 FT_Get_Track_Kerning( FT_Face face,
2844 FT_Fixed point_size,
2845 FT_Int degree,
2846 FT_Fixed* akerning )
2848 FT_Service_Kerning service;
2849 FT_Error error = FT_Err_Ok;
2852 if ( !face )
2853 return FT_Err_Invalid_Face_Handle;
2855 if ( !akerning )
2856 return FT_Err_Invalid_Argument;
2858 FT_FACE_FIND_SERVICE( face, service, KERNING );
2859 if ( !service )
2860 return FT_Err_Unimplemented_Feature;
2862 error = service->get_track( face,
2863 point_size,
2864 degree,
2865 akerning );
2867 return error;
2871 /* documentation is in freetype.h */
2873 FT_EXPORT_DEF( FT_Error )
2874 FT_Select_Charmap( FT_Face face,
2875 FT_Encoding encoding )
2877 FT_CharMap* cur;
2878 FT_CharMap* limit;
2881 if ( !face )
2882 return FT_Err_Invalid_Face_Handle;
2884 if ( encoding == FT_ENCODING_NONE )
2885 return FT_Err_Invalid_Argument;
2887 /* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */
2888 /* charmap available, i.e., one with UCS-4 characters, if possible. */
2889 /* */
2890 /* This is done by find_unicode_charmap() above, to share code. */
2891 if ( encoding == FT_ENCODING_UNICODE )
2892 return find_unicode_charmap( face );
2894 cur = face->charmaps;
2895 if ( !cur )
2896 return FT_Err_Invalid_CharMap_Handle;
2898 limit = cur + face->num_charmaps;
2900 for ( ; cur < limit; cur++ )
2902 if ( cur[0]->encoding == encoding )
2904 face->charmap = cur[0];
2905 return 0;
2909 return FT_Err_Invalid_Argument;
2913 /* documentation is in freetype.h */
2915 FT_EXPORT_DEF( FT_Error )
2916 FT_Set_Charmap( FT_Face face,
2917 FT_CharMap charmap )
2919 FT_CharMap* cur;
2920 FT_CharMap* limit;
2923 if ( !face )
2924 return FT_Err_Invalid_Face_Handle;
2926 cur = face->charmaps;
2927 if ( !cur )
2928 return FT_Err_Invalid_CharMap_Handle;
2929 if ( FT_Get_CMap_Format( charmap ) == 14 )
2930 return FT_Err_Invalid_Argument;
2932 limit = cur + face->num_charmaps;
2934 for ( ; cur < limit; cur++ )
2936 if ( cur[0] == charmap )
2938 face->charmap = cur[0];
2939 return 0;
2942 return FT_Err_Invalid_Argument;
2946 /* documentation is in freetype.h */
2948 FT_EXPORT_DEF( FT_Int )
2949 FT_Get_Charmap_Index( FT_CharMap charmap )
2951 FT_Int i;
2954 for ( i = 0; i < charmap->face->num_charmaps; i++ )
2955 if ( charmap->face->charmaps[i] == charmap )
2956 break;
2958 FT_ASSERT( i < charmap->face->num_charmaps );
2960 return i;
2964 static void
2965 ft_cmap_done_internal( FT_CMap cmap )
2967 FT_CMap_Class clazz = cmap->clazz;
2968 FT_Face face = cmap->charmap.face;
2969 FT_Memory memory = FT_FACE_MEMORY(face);
2972 if ( clazz->done )
2973 clazz->done( cmap );
2975 FT_FREE( cmap );
2979 FT_BASE_DEF( void )
2980 FT_CMap_Done( FT_CMap cmap )
2982 if ( cmap )
2984 FT_Face face = cmap->charmap.face;
2985 FT_Memory memory = FT_FACE_MEMORY( face );
2986 FT_Error error;
2987 FT_Int i, j;
2990 for ( i = 0; i < face->num_charmaps; i++ )
2992 if ( (FT_CMap)face->charmaps[i] == cmap )
2994 FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1];
2997 if ( FT_RENEW_ARRAY( face->charmaps,
2998 face->num_charmaps,
2999 face->num_charmaps - 1 ) )
3000 return;
3002 /* remove it from our list of charmaps */
3003 for ( j = i + 1; j < face->num_charmaps; j++ )
3005 if ( j == face->num_charmaps - 1 )
3006 face->charmaps[j - 1] = last_charmap;
3007 else
3008 face->charmaps[j - 1] = face->charmaps[j];
3011 face->num_charmaps--;
3013 if ( (FT_CMap)face->charmap == cmap )
3014 face->charmap = NULL;
3016 ft_cmap_done_internal( cmap );
3018 break;
3025 FT_BASE_DEF( FT_Error )
3026 FT_CMap_New( FT_CMap_Class clazz,
3027 FT_Pointer init_data,
3028 FT_CharMap charmap,
3029 FT_CMap *acmap )
3031 FT_Error error = FT_Err_Ok;
3032 FT_Face face;
3033 FT_Memory memory;
3034 FT_CMap cmap;
3037 if ( clazz == NULL || charmap == NULL || charmap->face == NULL )
3038 return FT_Err_Invalid_Argument;
3040 face = charmap->face;
3041 memory = FT_FACE_MEMORY( face );
3043 if ( !FT_ALLOC( cmap, clazz->size ) )
3045 cmap->charmap = *charmap;
3046 cmap->clazz = clazz;
3048 if ( clazz->init )
3050 error = clazz->init( cmap, init_data );
3051 if ( error )
3052 goto Fail;
3055 /* add it to our list of charmaps */
3056 if ( FT_RENEW_ARRAY( face->charmaps,
3057 face->num_charmaps,
3058 face->num_charmaps + 1 ) )
3059 goto Fail;
3061 face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
3064 Exit:
3065 if ( acmap )
3066 *acmap = cmap;
3068 return error;
3070 Fail:
3071 ft_cmap_done_internal( cmap );
3072 cmap = NULL;
3073 goto Exit;
3077 /* documentation is in freetype.h */
3079 FT_EXPORT_DEF( FT_UInt )
3080 FT_Get_Char_Index( FT_Face face,
3081 FT_ULong charcode )
3083 FT_UInt result = 0;
3086 if ( face && face->charmap )
3088 FT_CMap cmap = FT_CMAP( face->charmap );
3091 if ( charcode > 0xFFFFFFFFUL )
3093 FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3094 FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3096 result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
3098 return result;
3102 /* documentation is in freetype.h */
3104 FT_EXPORT_DEF( FT_ULong )
3105 FT_Get_First_Char( FT_Face face,
3106 FT_UInt *agindex )
3108 FT_ULong result = 0;
3109 FT_UInt gindex = 0;
3112 if ( face && face->charmap )
3114 gindex = FT_Get_Char_Index( face, 0 );
3115 if ( gindex == 0 )
3116 result = FT_Get_Next_Char( face, 0, &gindex );
3119 if ( agindex )
3120 *agindex = gindex;
3122 return result;
3126 /* documentation is in freetype.h */
3128 FT_EXPORT_DEF( FT_ULong )
3129 FT_Get_Next_Char( FT_Face face,
3130 FT_ULong charcode,
3131 FT_UInt *agindex )
3133 FT_ULong result = 0;
3134 FT_UInt gindex = 0;
3137 if ( face && face->charmap )
3139 FT_UInt32 code = (FT_UInt32)charcode;
3140 FT_CMap cmap = FT_CMAP( face->charmap );
3143 gindex = cmap->clazz->char_next( cmap, &code );
3144 result = ( gindex == 0 ) ? 0 : code;
3147 if ( agindex )
3148 *agindex = gindex;
3150 return result;
3154 /* documentation is in freetype.h */
3156 FT_EXPORT_DEF( FT_UInt )
3157 FT_Face_GetCharVariantIndex( FT_Face face,
3158 FT_ULong charcode,
3159 FT_ULong variantSelector )
3161 FT_UInt result = 0;
3164 if ( face && face->charmap &&
3165 face->charmap->encoding == FT_ENCODING_UNICODE )
3167 FT_CharMap charmap = find_variant_selector_charmap( face );
3168 FT_CMap ucmap = FT_CMAP( face->charmap );
3171 if ( charmap != NULL )
3173 FT_CMap vcmap = FT_CMAP( charmap );
3176 if ( charcode > 0xFFFFFFFFUL )
3178 FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3179 FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3181 if ( variantSelector > 0xFFFFFFFFUL )
3183 FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3184 FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3187 result = vcmap->clazz->char_var_index( vcmap, ucmap,
3188 (FT_UInt32)charcode,
3189 (FT_UInt32)variantSelector );
3193 return result;
3197 /* documentation is in freetype.h */
3199 FT_EXPORT_DEF( FT_Int )
3200 FT_Face_GetCharVariantIsDefault( FT_Face face,
3201 FT_ULong charcode,
3202 FT_ULong variantSelector )
3204 FT_Int result = -1;
3207 if ( face )
3209 FT_CharMap charmap = find_variant_selector_charmap( face );
3212 if ( charmap != NULL )
3214 FT_CMap vcmap = FT_CMAP( charmap );
3217 if ( charcode > 0xFFFFFFFFUL )
3219 FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3220 FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3222 if ( variantSelector > 0xFFFFFFFFUL )
3224 FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3225 FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3228 result = vcmap->clazz->char_var_default( vcmap,
3229 (FT_UInt32)charcode,
3230 (FT_UInt32)variantSelector );
3234 return result;
3238 /* documentation is in freetype.h */
3240 FT_EXPORT_DEF( FT_UInt32* )
3241 FT_Face_GetVariantSelectors( FT_Face face )
3243 FT_UInt32 *result = NULL;
3246 if ( face )
3248 FT_CharMap charmap = find_variant_selector_charmap( face );
3251 if ( charmap != NULL )
3253 FT_CMap vcmap = FT_CMAP( charmap );
3254 FT_Memory memory = FT_FACE_MEMORY( face );
3257 result = vcmap->clazz->variant_list( vcmap, memory );
3261 return result;
3265 /* documentation is in freetype.h */
3267 FT_EXPORT_DEF( FT_UInt32* )
3268 FT_Face_GetVariantsOfChar( FT_Face face,
3269 FT_ULong charcode )
3271 FT_UInt32 *result = NULL;
3274 if ( face )
3276 FT_CharMap charmap = find_variant_selector_charmap( face );
3279 if ( charmap != NULL )
3281 FT_CMap vcmap = FT_CMAP( charmap );
3282 FT_Memory memory = FT_FACE_MEMORY( face );
3285 if ( charcode > 0xFFFFFFFFUL )
3287 FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3288 FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3291 result = vcmap->clazz->charvariant_list( vcmap, memory,
3292 (FT_UInt32)charcode );
3295 return result;
3299 /* documentation is in freetype.h */
3301 FT_EXPORT_DEF( FT_UInt32* )
3302 FT_Face_GetCharsOfVariant( FT_Face face,
3303 FT_ULong variantSelector )
3305 FT_UInt32 *result = NULL;
3308 if ( face )
3310 FT_CharMap charmap = find_variant_selector_charmap( face );
3313 if ( charmap != NULL )
3315 FT_CMap vcmap = FT_CMAP( charmap );
3316 FT_Memory memory = FT_FACE_MEMORY( face );
3319 if ( variantSelector > 0xFFFFFFFFUL )
3321 FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3322 FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3325 result = vcmap->clazz->variantchar_list( vcmap, memory,
3326 (FT_UInt32)variantSelector );
3330 return result;
3334 /* documentation is in freetype.h */
3336 FT_EXPORT_DEF( FT_UInt )
3337 FT_Get_Name_Index( FT_Face face,
3338 FT_String* glyph_name )
3340 FT_UInt result = 0;
3343 if ( face && FT_HAS_GLYPH_NAMES( face ) )
3345 FT_Service_GlyphDict service;
3348 FT_FACE_LOOKUP_SERVICE( face,
3349 service,
3350 GLYPH_DICT );
3352 if ( service && service->name_index )
3353 result = service->name_index( face, glyph_name );
3356 return result;
3360 /* documentation is in freetype.h */
3362 FT_EXPORT_DEF( FT_Error )
3363 FT_Get_Glyph_Name( FT_Face face,
3364 FT_UInt glyph_index,
3365 FT_Pointer buffer,
3366 FT_UInt buffer_max )
3368 FT_Error error = FT_Err_Invalid_Argument;
3371 /* clean up buffer */
3372 if ( buffer && buffer_max > 0 )
3373 ((FT_Byte*)buffer)[0] = 0;
3375 if ( face &&
3376 (FT_Long)glyph_index <= face->num_glyphs &&
3377 FT_HAS_GLYPH_NAMES( face ) )
3379 FT_Service_GlyphDict service;
3382 FT_FACE_LOOKUP_SERVICE( face,
3383 service,
3384 GLYPH_DICT );
3386 if ( service && service->get_name )
3387 error = service->get_name( face, glyph_index, buffer, buffer_max );
3390 return error;
3394 /* documentation is in freetype.h */
3396 FT_EXPORT_DEF( const char* )
3397 FT_Get_Postscript_Name( FT_Face face )
3399 const char* result = NULL;
3402 if ( !face )
3403 goto Exit;
3405 if ( !result )
3407 FT_Service_PsFontName service;
3410 FT_FACE_LOOKUP_SERVICE( face,
3411 service,
3412 POSTSCRIPT_FONT_NAME );
3414 if ( service && service->get_ps_font_name )
3415 result = service->get_ps_font_name( face );
3418 Exit:
3419 return result;
3423 /* documentation is in tttables.h */
3425 FT_EXPORT_DEF( void* )
3426 FT_Get_Sfnt_Table( FT_Face face,
3427 FT_Sfnt_Tag tag )
3429 void* table = 0;
3430 FT_Service_SFNT_Table service;
3433 if ( face && FT_IS_SFNT( face ) )
3435 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3436 if ( service != NULL )
3437 table = service->get_table( face, tag );
3440 return table;
3444 /* documentation is in tttables.h */
3446 FT_EXPORT_DEF( FT_Error )
3447 FT_Load_Sfnt_Table( FT_Face face,
3448 FT_ULong tag,
3449 FT_Long offset,
3450 FT_Byte* buffer,
3451 FT_ULong* length )
3453 FT_Service_SFNT_Table service;
3456 if ( !face || !FT_IS_SFNT( face ) )
3457 return FT_Err_Invalid_Face_Handle;
3459 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3460 if ( service == NULL )
3461 return FT_Err_Unimplemented_Feature;
3463 return service->load_table( face, tag, offset, buffer, length );
3467 /* documentation is in tttables.h */
3469 FT_EXPORT_DEF( FT_Error )
3470 FT_Sfnt_Table_Info( FT_Face face,
3471 FT_UInt table_index,
3472 FT_ULong *tag,
3473 FT_ULong *length )
3475 FT_Service_SFNT_Table service;
3476 FT_ULong offset;
3479 if ( !face || !FT_IS_SFNT( face ) )
3480 return FT_Err_Invalid_Face_Handle;
3482 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3483 if ( service == NULL )
3484 return FT_Err_Unimplemented_Feature;
3486 return service->table_info( face, table_index, tag, &offset, length );
3490 /* documentation is in tttables.h */
3492 FT_EXPORT_DEF( FT_ULong )
3493 FT_Get_CMap_Language_ID( FT_CharMap charmap )
3495 FT_Service_TTCMaps service;
3496 FT_Face face;
3497 TT_CMapInfo cmap_info;
3500 if ( !charmap || !charmap->face )
3501 return 0;
3503 face = charmap->face;
3504 FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
3505 if ( service == NULL )
3506 return 0;
3507 if ( service->get_cmap_info( charmap, &cmap_info ))
3508 return 0;
3510 return cmap_info.language;
3514 /* documentation is in tttables.h */
3516 FT_EXPORT_DEF( FT_Long )
3517 FT_Get_CMap_Format( FT_CharMap charmap )
3519 FT_Service_TTCMaps service;
3520 FT_Face face;
3521 TT_CMapInfo cmap_info;
3524 if ( !charmap || !charmap->face )
3525 return -1;
3527 face = charmap->face;
3528 FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
3529 if ( service == NULL )
3530 return -1;
3531 if ( service->get_cmap_info( charmap, &cmap_info ))
3532 return -1;
3534 return cmap_info.format;
3538 /* documentation is in ftsizes.h */
3540 FT_EXPORT_DEF( FT_Error )
3541 FT_Activate_Size( FT_Size size )
3543 FT_Face face;
3546 if ( size == NULL )
3547 return FT_Err_Invalid_Argument;
3549 face = size->face;
3550 if ( face == NULL || face->driver == NULL )
3551 return FT_Err_Invalid_Argument;
3553 /* we don't need anything more complex than that; all size objects */
3554 /* are already listed by the face */
3555 face->size = size;
3557 return FT_Err_Ok;
3561 /*************************************************************************/
3562 /*************************************************************************/
3563 /*************************************************************************/
3564 /**** ****/
3565 /**** ****/
3566 /**** R E N D E R E R S ****/
3567 /**** ****/
3568 /**** ****/
3569 /*************************************************************************/
3570 /*************************************************************************/
3571 /*************************************************************************/
3573 /* lookup a renderer by glyph format in the library's list */
3574 FT_BASE_DEF( FT_Renderer )
3575 FT_Lookup_Renderer( FT_Library library,
3576 FT_Glyph_Format format,
3577 FT_ListNode* node )
3579 FT_ListNode cur;
3580 FT_Renderer result = 0;
3583 if ( !library )
3584 goto Exit;
3586 cur = library->renderers.head;
3588 if ( node )
3590 if ( *node )
3591 cur = (*node)->next;
3592 *node = 0;
3595 while ( cur )
3597 FT_Renderer renderer = FT_RENDERER( cur->data );
3600 if ( renderer->glyph_format == format )
3602 if ( node )
3603 *node = cur;
3605 result = renderer;
3606 break;
3608 cur = cur->next;
3611 Exit:
3612 return result;
3616 static FT_Renderer
3617 ft_lookup_glyph_renderer( FT_GlyphSlot slot )
3619 FT_Face face = slot->face;
3620 FT_Library library = FT_FACE_LIBRARY( face );
3621 FT_Renderer result = library->cur_renderer;
3624 if ( !result || result->glyph_format != slot->format )
3625 result = FT_Lookup_Renderer( library, slot->format, 0 );
3627 return result;
3631 static void
3632 ft_set_current_renderer( FT_Library library )
3634 FT_Renderer renderer;
3637 renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 );
3638 library->cur_renderer = renderer;
3642 static FT_Error
3643 ft_add_renderer( FT_Module module )
3645 FT_Library library = module->library;
3646 FT_Memory memory = library->memory;
3647 FT_Error error;
3648 FT_ListNode node;
3651 if ( FT_NEW( node ) )
3652 goto Exit;
3655 FT_Renderer render = FT_RENDERER( module );
3656 FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz;
3659 render->clazz = clazz;
3660 render->glyph_format = clazz->glyph_format;
3662 /* allocate raster object if needed */
3663 if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
3664 clazz->raster_class->raster_new )
3666 error = clazz->raster_class->raster_new( memory, &render->raster );
3667 if ( error )
3668 goto Fail;
3670 render->raster_render = clazz->raster_class->raster_render;
3671 render->render = clazz->render_glyph;
3674 /* add to list */
3675 node->data = module;
3676 FT_List_Add( &library->renderers, node );
3678 ft_set_current_renderer( library );
3681 Fail:
3682 if ( error )
3683 FT_FREE( node );
3685 Exit:
3686 return error;
3690 static void
3691 ft_remove_renderer( FT_Module module )
3693 FT_Library library = module->library;
3694 FT_Memory memory = library->memory;
3695 FT_ListNode node;
3698 node = FT_List_Find( &library->renderers, module );
3699 if ( node )
3701 FT_Renderer render = FT_RENDERER( module );
3704 /* release raster object, if any */
3705 if ( render->raster )
3706 render->clazz->raster_class->raster_done( render->raster );
3708 /* remove from list */
3709 FT_List_Remove( &library->renderers, node );
3710 FT_FREE( node );
3712 ft_set_current_renderer( library );
3717 /* documentation is in ftrender.h */
3719 FT_EXPORT_DEF( FT_Renderer )
3720 FT_Get_Renderer( FT_Library library,
3721 FT_Glyph_Format format )
3723 /* test for valid `library' delayed to FT_Lookup_Renderer() */
3725 return FT_Lookup_Renderer( library, format, 0 );
3729 /* documentation is in ftrender.h */
3731 FT_EXPORT_DEF( FT_Error )
3732 FT_Set_Renderer( FT_Library library,
3733 FT_Renderer renderer,
3734 FT_UInt num_params,
3735 FT_Parameter* parameters )
3737 FT_ListNode node;
3738 FT_Error error = FT_Err_Ok;
3741 if ( !library )
3742 return FT_Err_Invalid_Library_Handle;
3744 if ( !renderer )
3745 return FT_Err_Invalid_Argument;
3747 node = FT_List_Find( &library->renderers, renderer );
3748 if ( !node )
3750 error = FT_Err_Invalid_Argument;
3751 goto Exit;
3754 FT_List_Up( &library->renderers, node );
3756 if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
3757 library->cur_renderer = renderer;
3759 if ( num_params > 0 )
3761 FT_Renderer_SetModeFunc set_mode = renderer->clazz->set_mode;
3764 for ( ; num_params > 0; num_params-- )
3766 error = set_mode( renderer, parameters->tag, parameters->data );
3767 if ( error )
3768 break;
3772 Exit:
3773 return error;
3777 FT_BASE_DEF( FT_Error )
3778 FT_Render_Glyph_Internal( FT_Library library,
3779 FT_GlyphSlot slot,
3780 FT_Render_Mode render_mode )
3782 FT_Error error = FT_Err_Ok;
3783 FT_Renderer renderer;
3786 /* if it is already a bitmap, no need to do anything */
3787 switch ( slot->format )
3789 case FT_GLYPH_FORMAT_BITMAP: /* already a bitmap, don't do anything */
3790 break;
3792 default:
3794 FT_ListNode node = 0;
3795 FT_Bool update = 0;
3798 /* small shortcut for the very common case */
3799 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
3801 renderer = library->cur_renderer;
3802 node = library->renderers.head;
3804 else
3805 renderer = FT_Lookup_Renderer( library, slot->format, &node );
3807 error = FT_Err_Unimplemented_Feature;
3808 while ( renderer )
3810 error = renderer->render( renderer, slot, render_mode, NULL );
3811 if ( !error ||
3812 FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph )
3813 break;
3815 /* FT_Err_Cannot_Render_Glyph is returned if the render mode */
3816 /* is unsupported by the current renderer for this glyph image */
3817 /* format. */
3819 /* now, look for another renderer that supports the same */
3820 /* format. */
3821 renderer = FT_Lookup_Renderer( library, slot->format, &node );
3822 update = 1;
3825 /* if we changed the current renderer for the glyph image format */
3826 /* we need to select it as the next current one */
3827 if ( !error && update && renderer )
3828 FT_Set_Renderer( library, renderer, 0, 0 );
3832 return error;
3836 /* documentation is in freetype.h */
3838 FT_EXPORT_DEF( FT_Error )
3839 FT_Render_Glyph( FT_GlyphSlot slot,
3840 FT_Render_Mode render_mode )
3842 FT_Library library;
3845 if ( !slot )
3846 return FT_Err_Invalid_Argument;
3848 library = FT_FACE_LIBRARY( slot->face );
3850 return FT_Render_Glyph_Internal( library, slot, render_mode );
3854 /*************************************************************************/
3855 /*************************************************************************/
3856 /*************************************************************************/
3857 /**** ****/
3858 /**** ****/
3859 /**** M O D U L E S ****/
3860 /**** ****/
3861 /**** ****/
3862 /*************************************************************************/
3863 /*************************************************************************/
3864 /*************************************************************************/
3867 /*************************************************************************/
3868 /* */
3869 /* <Function> */
3870 /* Destroy_Module */
3871 /* */
3872 /* <Description> */
3873 /* Destroys a given module object. For drivers, this also destroys */
3874 /* all child faces. */
3875 /* */
3876 /* <InOut> */
3877 /* module :: A handle to the target driver object. */
3878 /* */
3879 /* <Note> */
3880 /* The driver _must_ be LOCKED! */
3881 /* */
3882 static void
3883 Destroy_Module( FT_Module module )
3885 FT_Memory memory = module->memory;
3886 FT_Module_Class* clazz = module->clazz;
3887 FT_Library library = module->library;
3890 /* finalize client-data - before anything else */
3891 if ( module->generic.finalizer )
3892 module->generic.finalizer( module );
3894 if ( library && library->auto_hinter == module )
3895 library->auto_hinter = 0;
3897 /* if the module is a renderer */
3898 if ( FT_MODULE_IS_RENDERER( module ) )
3899 ft_remove_renderer( module );
3901 /* if the module is a font driver, add some steps */
3902 if ( FT_MODULE_IS_DRIVER( module ) )
3903 Destroy_Driver( FT_DRIVER( module ) );
3905 /* finalize the module object */
3906 if ( clazz->module_done )
3907 clazz->module_done( module );
3909 /* discard it */
3910 FT_FREE( module );
3914 /* documentation is in ftmodapi.h */
3916 FT_EXPORT_DEF( FT_Error )
3917 FT_Add_Module( FT_Library library,
3918 const FT_Module_Class* clazz )
3920 FT_Error error;
3921 FT_Memory memory;
3922 FT_Module module;
3923 FT_UInt nn;
3926 #define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \
3927 FREETYPE_MINOR )
3929 if ( !library )
3930 return FT_Err_Invalid_Library_Handle;
3932 if ( !clazz )
3933 return FT_Err_Invalid_Argument;
3935 /* check freetype version */
3936 if ( clazz->module_requires > FREETYPE_VER_FIXED )
3937 return FT_Err_Invalid_Version;
3939 /* look for a module with the same name in the library's table */
3940 for ( nn = 0; nn < library->num_modules; nn++ )
3942 module = library->modules[nn];
3943 if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 )
3945 /* this installed module has the same name, compare their versions */
3946 if ( clazz->module_version <= module->clazz->module_version )
3947 return FT_Err_Lower_Module_Version;
3949 /* remove the module from our list, then exit the loop to replace */
3950 /* it by our new version.. */
3951 FT_Remove_Module( library, module );
3952 break;
3956 memory = library->memory;
3957 error = FT_Err_Ok;
3959 if ( library->num_modules >= FT_MAX_MODULES )
3961 error = FT_Err_Too_Many_Drivers;
3962 goto Exit;
3965 /* allocate module object */
3966 if ( FT_ALLOC( module, clazz->module_size ) )
3967 goto Exit;
3969 /* base initialization */
3970 module->library = library;
3971 module->memory = memory;
3972 module->clazz = (FT_Module_Class*)clazz;
3974 /* check whether the module is a renderer - this must be performed */
3975 /* before the normal module initialization */
3976 if ( FT_MODULE_IS_RENDERER( module ) )
3978 /* add to the renderers list */
3979 error = ft_add_renderer( module );
3980 if ( error )
3981 goto Fail;
3984 /* is the module a auto-hinter? */
3985 if ( FT_MODULE_IS_HINTER( module ) )
3986 library->auto_hinter = module;
3988 /* if the module is a font driver */
3989 if ( FT_MODULE_IS_DRIVER( module ) )
3991 /* allocate glyph loader if needed */
3992 FT_Driver driver = FT_DRIVER( module );
3995 driver->clazz = (FT_Driver_Class)module->clazz;
3996 if ( FT_DRIVER_USES_OUTLINES( driver ) )
3998 error = FT_GlyphLoader_New( memory, &driver->glyph_loader );
3999 if ( error )
4000 goto Fail;
4004 if ( clazz->module_init )
4006 error = clazz->module_init( module );
4007 if ( error )
4008 goto Fail;
4011 /* add module to the library's table */
4012 library->modules[library->num_modules++] = module;
4014 Exit:
4015 return error;
4017 Fail:
4018 if ( FT_MODULE_IS_DRIVER( module ) )
4020 FT_Driver driver = FT_DRIVER( module );
4023 if ( FT_DRIVER_USES_OUTLINES( driver ) )
4024 FT_GlyphLoader_Done( driver->glyph_loader );
4027 if ( FT_MODULE_IS_RENDERER( module ) )
4029 FT_Renderer renderer = FT_RENDERER( module );
4032 if ( renderer->raster )
4033 renderer->clazz->raster_class->raster_done( renderer->raster );
4036 FT_FREE( module );
4037 goto Exit;
4041 /* documentation is in ftmodapi.h */
4043 FT_EXPORT_DEF( FT_Module )
4044 FT_Get_Module( FT_Library library,
4045 const char* module_name )
4047 FT_Module result = 0;
4048 FT_Module* cur;
4049 FT_Module* limit;
4052 if ( !library || !module_name )
4053 return result;
4055 cur = library->modules;
4056 limit = cur + library->num_modules;
4058 for ( ; cur < limit; cur++ )
4059 if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 )
4061 result = cur[0];
4062 break;
4065 return result;
4069 /* documentation is in ftobjs.h */
4071 FT_BASE_DEF( const void* )
4072 FT_Get_Module_Interface( FT_Library library,
4073 const char* mod_name )
4075 FT_Module module;
4078 /* test for valid `library' delayed to FT_Get_Module() */
4080 module = FT_Get_Module( library, mod_name );
4082 return module ? module->clazz->module_interface : 0;
4086 FT_BASE_DEF( FT_Pointer )
4087 ft_module_get_service( FT_Module module,
4088 const char* service_id )
4090 FT_Pointer result = NULL;
4092 if ( module )
4094 FT_ASSERT( module->clazz && module->clazz->get_interface );
4096 /* first, look for the service in the module
4098 if ( module->clazz->get_interface )
4099 result = module->clazz->get_interface( module, service_id );
4101 if ( result == NULL )
4103 /* we didn't find it, look in all other modules then
4105 FT_Library library = module->library;
4106 FT_Module* cur = library->modules;
4107 FT_Module* limit = cur + library->num_modules;
4109 for ( ; cur < limit; cur++ )
4111 if ( cur[0] != module )
4113 FT_ASSERT( cur[0]->clazz );
4115 if ( cur[0]->clazz->get_interface )
4117 result = cur[0]->clazz->get_interface( cur[0], service_id );
4118 if ( result != NULL )
4119 break;
4126 return result;
4130 /* documentation is in ftmodapi.h */
4132 FT_EXPORT_DEF( FT_Error )
4133 FT_Remove_Module( FT_Library library,
4134 FT_Module module )
4136 /* try to find the module from the table, then remove it from there */
4138 if ( !library )
4139 return FT_Err_Invalid_Library_Handle;
4141 if ( module )
4143 FT_Module* cur = library->modules;
4144 FT_Module* limit = cur + library->num_modules;
4147 for ( ; cur < limit; cur++ )
4149 if ( cur[0] == module )
4151 /* remove it from the table */
4152 library->num_modules--;
4153 limit--;
4154 while ( cur < limit )
4156 cur[0] = cur[1];
4157 cur++;
4159 limit[0] = 0;
4161 /* destroy the module */
4162 Destroy_Module( module );
4164 return FT_Err_Ok;
4168 return FT_Err_Invalid_Driver_Handle;
4172 /*************************************************************************/
4173 /*************************************************************************/
4174 /*************************************************************************/
4175 /**** ****/
4176 /**** ****/
4177 /**** L I B R A R Y ****/
4178 /**** ****/
4179 /**** ****/
4180 /*************************************************************************/
4181 /*************************************************************************/
4182 /*************************************************************************/
4185 /* documentation is in ftmodapi.h */
4187 FT_EXPORT_DEF( FT_Error )
4188 FT_New_Library( FT_Memory memory,
4189 FT_Library *alibrary )
4191 FT_Library library = 0;
4192 FT_Error error;
4195 if ( !memory )
4196 return FT_Err_Invalid_Argument;
4198 #ifdef FT_DEBUG_LEVEL_ERROR
4199 /* init debugging support */
4200 ft_debug_init();
4201 #endif
4203 /* first of all, allocate the library object */
4204 if ( FT_NEW( library ) )
4205 return error;
4207 library->memory = memory;
4209 #ifdef FT_CONFIG_OPTION_PIC
4210 /* initialize position independent code containers */
4211 error = ft_pic_container_init( library );
4212 if ( error )
4213 goto Fail;
4214 #endif
4216 /* allocate the render pool */
4217 library->raster_pool_size = FT_RENDER_POOL_SIZE;
4218 #if FT_RENDER_POOL_SIZE > 0
4219 if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) )
4220 goto Fail;
4221 #endif
4223 library->version_major = FREETYPE_MAJOR;
4224 library->version_minor = FREETYPE_MINOR;
4225 library->version_patch = FREETYPE_PATCH;
4227 /* That's ok now */
4228 *alibrary = library;
4230 return FT_Err_Ok;
4232 Fail:
4233 #ifdef FT_CONFIG_OPTION_PIC
4234 ft_pic_container_destroy( library );
4235 #endif
4236 FT_FREE( library );
4237 return error;
4241 /* documentation is in freetype.h */
4243 FT_EXPORT_DEF( void )
4244 FT_Library_Version( FT_Library library,
4245 FT_Int *amajor,
4246 FT_Int *aminor,
4247 FT_Int *apatch )
4249 FT_Int major = 0;
4250 FT_Int minor = 0;
4251 FT_Int patch = 0;
4254 if ( library )
4256 major = library->version_major;
4257 minor = library->version_minor;
4258 patch = library->version_patch;
4261 if ( amajor )
4262 *amajor = major;
4264 if ( aminor )
4265 *aminor = minor;
4267 if ( apatch )
4268 *apatch = patch;
4272 /* documentation is in ftmodapi.h */
4274 FT_EXPORT_DEF( FT_Error )
4275 FT_Done_Library( FT_Library library )
4277 FT_Memory memory;
4280 if ( !library )
4281 return FT_Err_Invalid_Library_Handle;
4283 memory = library->memory;
4285 /* Discard client-data */
4286 if ( library->generic.finalizer )
4287 library->generic.finalizer( library );
4289 /* Close all faces in the library. If we don't do
4290 * this, we can have some subtle memory leaks.
4291 * Example:
4293 * - the cff font driver uses the pshinter module in cff_size_done
4294 * - if the pshinter module is destroyed before the cff font driver,
4295 * opened FT_Face objects managed by the driver are not properly
4296 * destroyed, resulting in a memory leak
4299 FT_UInt n;
4302 for ( n = 0; n < library->num_modules; n++ )
4304 FT_Module module = library->modules[n];
4305 FT_List faces;
4308 if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 )
4309 continue;
4311 faces = &FT_DRIVER(module)->faces_list;
4312 while ( faces->head )
4314 FT_Done_Face( FT_FACE( faces->head->data ) );
4315 if ( faces->head )
4316 FT_TRACE0(( "FT_Done_Library: failed to free some faces\n" ));
4321 /* Close all other modules in the library */
4322 #if 1
4323 /* XXX Modules are removed in the reversed order so that */
4324 /* type42 module is removed before truetype module. This */
4325 /* avoids double free in some occasions. It is a hack. */
4326 while ( library->num_modules > 0 )
4327 FT_Remove_Module( library,
4328 library->modules[library->num_modules - 1] );
4329 #else
4331 FT_UInt n;
4334 for ( n = 0; n < library->num_modules; n++ )
4336 FT_Module module = library->modules[n];
4339 if ( module )
4341 Destroy_Module( module );
4342 library->modules[n] = 0;
4346 #endif
4348 /* Destroy raster objects */
4349 FT_FREE( library->raster_pool );
4350 library->raster_pool_size = 0;
4352 #ifdef FT_CONFIG_OPTION_PIC
4353 /* Destroy pic container contents */
4354 ft_pic_container_destroy( library );
4355 #endif
4357 FT_FREE( library );
4358 return FT_Err_Ok;
4362 /* documentation is in ftmodapi.h */
4364 FT_EXPORT_DEF( void )
4365 FT_Set_Debug_Hook( FT_Library library,
4366 FT_UInt hook_index,
4367 FT_DebugHook_Func debug_hook )
4369 if ( library && debug_hook &&
4370 hook_index <
4371 ( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
4372 library->debug_hooks[hook_index] = debug_hook;
4376 /* documentation is in ftmodapi.h */
4378 FT_EXPORT_DEF( FT_TrueTypeEngineType )
4379 FT_Get_TrueType_Engine_Type( FT_Library library )
4381 FT_TrueTypeEngineType result = FT_TRUETYPE_ENGINE_TYPE_NONE;
4384 if ( library )
4386 FT_Module module = FT_Get_Module( library, "truetype" );
4389 if ( module )
4391 FT_Service_TrueTypeEngine service;
4394 service = (FT_Service_TrueTypeEngine)
4395 ft_module_get_service( module,
4396 FT_SERVICE_ID_TRUETYPE_ENGINE );
4397 if ( service )
4398 result = service->engine_type;
4402 return result;
4406 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
4408 FT_BASE_DEF( FT_Error )
4409 ft_stub_set_char_sizes( FT_Size size,
4410 FT_F26Dot6 width,
4411 FT_F26Dot6 height,
4412 FT_UInt horz_res,
4413 FT_UInt vert_res )
4415 FT_Size_RequestRec req;
4416 FT_Driver driver = size->face->driver;
4419 if ( driver->clazz->request_size )
4421 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
4422 req.width = width;
4423 req.height = height;
4425 if ( horz_res == 0 )
4426 horz_res = vert_res;
4428 if ( vert_res == 0 )
4429 vert_res = horz_res;
4431 if ( horz_res == 0 )
4432 horz_res = vert_res = 72;
4434 req.horiResolution = horz_res;
4435 req.vertResolution = vert_res;
4437 return driver->clazz->request_size( size, &req );
4440 return 0;
4444 FT_BASE_DEF( FT_Error )
4445 ft_stub_set_pixel_sizes( FT_Size size,
4446 FT_UInt width,
4447 FT_UInt height )
4449 FT_Size_RequestRec req;
4450 FT_Driver driver = size->face->driver;
4453 if ( driver->clazz->request_size )
4455 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
4456 req.width = width << 6;
4457 req.height = height << 6;
4458 req.horiResolution = 0;
4459 req.vertResolution = 0;
4461 return driver->clazz->request_size( size, &req );
4464 return 0;
4467 #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
4470 FT_EXPORT_DEF( FT_Error )
4471 FT_Get_SubGlyph_Info( FT_GlyphSlot glyph,
4472 FT_UInt sub_index,
4473 FT_Int *p_index,
4474 FT_UInt *p_flags,
4475 FT_Int *p_arg1,
4476 FT_Int *p_arg2,
4477 FT_Matrix *p_transform )
4479 FT_Error error = FT_Err_Invalid_Argument;
4482 if ( glyph != NULL &&
4483 glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
4484 sub_index < glyph->num_subglyphs )
4486 FT_SubGlyph subg = glyph->subglyphs + sub_index;
4489 *p_index = subg->index;
4490 *p_flags = subg->flags;
4491 *p_arg1 = subg->arg1;
4492 *p_arg2 = subg->arg2;
4493 *p_transform = subg->transform;
4496 return error;
4500 /* END */