1
/***************************************************************************/
5
/* The FreeType private base classes (body). */
7
/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */
9
/* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
17
/***************************************************************************/
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
33
#include FT_SERVICE_SFNT_H
34
#include FT_SERVICE_POSTSCRIPT_NAME_H
35
#include FT_SERVICE_GLYPH_DICT_H
36
#include FT_SERVICE_TT_CMAP_H
37
#include FT_SERVICE_KERNING_H
38
#include FT_SERVICE_TRUETYPE_ENGINE_H
40
#ifdef FT_CONFIG_OPTION_MAC_FONTS
44
#define GRID_FIT_METRICS
47
FT_BASE_DEF( FT_Pointer )
48
ft_service_list_lookup( FT_ServiceDesc service_descriptors,
49
const char* service_id )
51
FT_Pointer result = NULL;
52
FT_ServiceDesc desc = service_descriptors;
55
if ( desc && service_id )
57
for ( ; desc->serv_id != NULL; desc++ )
59
if ( ft_strcmp( desc->serv_id, service_id ) == 0 )
61
result = (FT_Pointer)desc->serv_data;
72
ft_validator_init( FT_Validator valid,
75
FT_ValidationLevel level )
80
valid->error = FT_Err_Ok;
85
ft_validator_run( FT_Validator valid )
87
/* This function doesn't work! None should call it. */
95
ft_validator_error( FT_Validator valid,
98
/* since the cast below also disables the compiler's */
99
/* type check, we introduce a dummy variable, which */
100
/* will be optimized away */
101
volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer;
104
valid->error = error;
106
/* throw away volatileness; use `jump_buffer' or the */
107
/* compiler may warn about an unused local variable */
108
ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 );
112
/*************************************************************************/
113
/*************************************************************************/
114
/*************************************************************************/
117
/**** S T R E A M ****/
120
/*************************************************************************/
121
/*************************************************************************/
122
/*************************************************************************/
125
/* create a new input stream from an FT_Open_Args structure */
127
FT_BASE_DEF( FT_Error )
128
FT_Stream_New( FT_Library library,
129
const FT_Open_Args* args,
140
return FT_Err_Invalid_Library_Handle;
143
return FT_Err_Invalid_Argument;
145
memory = library->memory;
147
if ( FT_NEW( stream ) )
150
stream->memory = memory;
152
if ( args->flags & FT_OPEN_MEMORY )
154
/* create a memory-based stream */
155
FT_Stream_OpenMemory( stream,
156
(const FT_Byte*)args->memory_base,
159
else if ( args->flags & FT_OPEN_PATHNAME )
161
/* create a normal system stream */
162
error = FT_Stream_Open( stream, args->pathname );
163
stream->pathname.pointer = args->pathname;
165
else if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
167
/* use an existing, user-provided stream */
169
/* in this case, we do not need to allocate a new stream object */
170
/* since the caller is responsible for closing it himself */
172
stream = args->stream;
175
error = FT_Err_Invalid_Argument;
180
stream->memory = memory; /* just to be certain */
190
FT_Stream_Free( FT_Stream stream,
195
FT_Memory memory = stream->memory;
198
FT_Stream_Close( stream );
206
/*************************************************************************/
208
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
209
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
210
/* messages during execution. */
213
#define FT_COMPONENT trace_objs
216
/*************************************************************************/
217
/*************************************************************************/
218
/*************************************************************************/
221
/**** FACE, SIZE & GLYPH SLOT OBJECTS ****/
224
/*************************************************************************/
225
/*************************************************************************/
226
/*************************************************************************/
230
ft_glyphslot_init( FT_GlyphSlot slot )
232
FT_Driver driver = slot->face->driver;
233
FT_Driver_Class clazz = driver->clazz;
234
FT_Memory memory = driver->root.memory;
235
FT_Error error = FT_Err_Ok;
236
FT_Slot_Internal internal = NULL;
239
slot->library = driver->root.library;
241
if ( FT_NEW( internal ) )
244
slot->internal = internal;
246
if ( FT_DRIVER_USES_OUTLINES( driver ) )
247
error = FT_GlyphLoader_New( memory, &internal->loader );
249
if ( !error && clazz->init_slot )
250
error = clazz->init_slot( slot );
258
ft_glyphslot_free_bitmap( FT_GlyphSlot slot )
260
if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
262
FT_Memory memory = FT_FACE_MEMORY( slot->face );
265
FT_FREE( slot->bitmap.buffer );
266
slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
270
/* assume that the bitmap buffer was stolen or not */
271
/* allocated from the heap */
272
slot->bitmap.buffer = NULL;
278
ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
281
ft_glyphslot_free_bitmap( slot );
283
slot->bitmap.buffer = buffer;
285
FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 );
289
FT_BASE_DEF( FT_Error )
290
ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
293
FT_Memory memory = FT_FACE_MEMORY( slot->face );
297
if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
298
FT_FREE( slot->bitmap.buffer );
300
slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
302
(void)FT_ALLOC( slot->bitmap.buffer, size );
308
ft_glyphslot_clear( FT_GlyphSlot slot )
310
/* free bitmap if needed */
311
ft_glyphslot_free_bitmap( slot );
313
/* clear all public fields in the glyph slot */
314
FT_ZERO( &slot->metrics );
315
FT_ZERO( &slot->outline );
317
slot->bitmap.width = 0;
318
slot->bitmap.rows = 0;
319
slot->bitmap.pitch = 0;
320
slot->bitmap.pixel_mode = 0;
321
/* `slot->bitmap.buffer' has been handled by ft_glyphslot_free_bitmap */
323
slot->bitmap_left = 0;
324
slot->bitmap_top = 0;
325
slot->num_subglyphs = 0;
327
slot->control_data = 0;
328
slot->control_len = 0;
330
slot->format = FT_GLYPH_FORMAT_NONE;
332
slot->linearHoriAdvance = 0;
333
slot->linearVertAdvance = 0;
340
ft_glyphslot_done( FT_GlyphSlot slot )
342
FT_Driver driver = slot->face->driver;
343
FT_Driver_Class clazz = driver->clazz;
344
FT_Memory memory = driver->root.memory;
347
if ( clazz->done_slot )
348
clazz->done_slot( slot );
350
/* free bitmap buffer if needed */
351
ft_glyphslot_free_bitmap( slot );
353
/* slot->internal might be NULL in out-of-memory situations */
354
if ( slot->internal )
356
/* free glyph loader */
357
if ( FT_DRIVER_USES_OUTLINES( driver ) )
359
FT_GlyphLoader_Done( slot->internal->loader );
360
slot->internal->loader = 0;
363
FT_FREE( slot->internal );
368
/* documentation is in ftobjs.h */
370
FT_BASE_DEF( FT_Error )
371
FT_New_GlyphSlot( FT_Face face,
372
FT_GlyphSlot *aslot )
376
FT_Driver_Class clazz;
381
if ( !face || !face->driver )
382
return FT_Err_Invalid_Argument;
384
driver = face->driver;
385
clazz = driver->clazz;
386
memory = driver->root.memory;
388
FT_TRACE4(( "FT_New_GlyphSlot: Creating new slot object\n" ));
389
if ( !FT_ALLOC( slot, clazz->slot_object_size ) )
393
error = ft_glyphslot_init( slot );
396
ft_glyphslot_done( slot );
401
slot->next = face->glyph;
412
FT_TRACE4(( "FT_New_GlyphSlot: Return %d\n", error ));
417
/* documentation is in ftobjs.h */
420
FT_Done_GlyphSlot( FT_GlyphSlot slot )
424
FT_Driver driver = slot->face->driver;
425
FT_Memory memory = driver->root.memory;
430
/* Remove slot from its parent face's list */
432
cur = slot->face->glyph;
439
slot->face->glyph = cur->next;
441
prev->next = cur->next;
443
ft_glyphslot_done( slot );
454
/* documentation is in freetype.h */
456
FT_EXPORT_DEF( void )
457
FT_Set_Transform( FT_Face face,
461
FT_Face_Internal internal;
467
internal = face->internal;
469
internal->transform_flags = 0;
473
internal->transform_matrix.xx = 0x10000L;
474
internal->transform_matrix.xy = 0;
475
internal->transform_matrix.yx = 0;
476
internal->transform_matrix.yy = 0x10000L;
477
matrix = &internal->transform_matrix;
480
internal->transform_matrix = *matrix;
482
/* set transform_flags bit flag 0 if `matrix' isn't the identity */
483
if ( ( matrix->xy | matrix->yx ) ||
484
matrix->xx != 0x10000L ||
485
matrix->yy != 0x10000L )
486
internal->transform_flags |= 1;
490
internal->transform_delta.x = 0;
491
internal->transform_delta.y = 0;
492
delta = &internal->transform_delta;
495
internal->transform_delta = *delta;
497
/* set transform_flags bit flag 1 if `delta' isn't the null vector */
498
if ( delta->x | delta->y )
499
internal->transform_flags |= 2;
504
ft_lookup_glyph_renderer( FT_GlyphSlot slot );
507
#ifdef GRID_FIT_METRICS
509
ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot,
512
FT_Glyph_Metrics* metrics = &slot->metrics;
513
FT_Pos right, bottom;
518
metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
519
metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
521
right = FT_PIX_CEIL( metrics->vertBearingX + metrics->width );
522
bottom = FT_PIX_CEIL( metrics->vertBearingY + metrics->height );
524
metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
525
metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
527
metrics->width = right - metrics->vertBearingX;
528
metrics->height = bottom - metrics->vertBearingY;
532
metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
533
metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
535
right = FT_PIX_CEIL ( metrics->horiBearingX + metrics->width );
536
bottom = FT_PIX_FLOOR( metrics->horiBearingY - metrics->height );
538
metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
539
metrics->horiBearingY = FT_PIX_CEIL ( metrics->horiBearingY );
541
metrics->width = right - metrics->horiBearingX;
542
metrics->height = metrics->horiBearingY - bottom;
545
metrics->horiAdvance = FT_PIX_ROUND( metrics->horiAdvance );
546
metrics->vertAdvance = FT_PIX_ROUND( metrics->vertAdvance );
548
#endif /* GRID_FIT_METRICS */
551
/* documentation is in freetype.h */
553
FT_EXPORT_DEF( FT_Error )
554
FT_Load_Glyph( FT_Face face,
556
FT_Int32 load_flags )
562
FT_Bool autohint = FALSE;
566
if ( !face || !face->size || !face->glyph )
567
return FT_Err_Invalid_Face_Handle;
569
/* The validity test for `glyph_index' is performed by the */
573
ft_glyphslot_clear( slot );
575
driver = face->driver;
576
library = driver->root.library;
577
hinter = library->auto_hinter;
579
/* resolve load flags dependencies */
581
if ( load_flags & FT_LOAD_NO_RECURSE )
582
load_flags |= FT_LOAD_NO_SCALE |
583
FT_LOAD_IGNORE_TRANSFORM;
585
if ( load_flags & FT_LOAD_NO_SCALE )
587
load_flags |= FT_LOAD_NO_HINTING |
590
load_flags &= ~FT_LOAD_RENDER;
594
* Determine whether we need to auto-hint or not.
595
* The general rules are:
597
* - Do only auto-hinting if we have a hinter module, a scalable font
598
* format dealing with outlines, and no transforms except simple
599
* slants and/or rotations by integer multiples of 90 degrees.
601
* - Then, auto-hint if FT_LOAD_FORCE_AUTOHINT is set or if we don't
602
* have a native font hinter.
604
* - Otherwise, auto-hint for LIGHT hinting mode.
606
* - Exception: The font is `tricky' and requires the native hinter to
611
!( load_flags & FT_LOAD_NO_HINTING ) &&
612
!( load_flags & FT_LOAD_NO_AUTOHINT ) &&
613
FT_DRIVER_IS_SCALABLE( driver ) &&
614
FT_DRIVER_USES_OUTLINES( driver ) &&
615
!FT_IS_TRICKY( face ) &&
616
( ( face->internal->transform_matrix.yx == 0 &&
617
face->internal->transform_matrix.xx != 0 ) ||
618
( face->internal->transform_matrix.xx == 0 &&
619
face->internal->transform_matrix.yx != 0 ) ) )
621
if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ||
622
!FT_DRIVER_HAS_HINTER( driver ) )
626
FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
629
if ( mode == FT_RENDER_MODE_LIGHT ||
630
face->internal->ignore_unpatented_hinter )
637
FT_AutoHinter_Service hinting;
640
/* try to load embedded bitmaps first if available */
642
/* XXX: This is really a temporary hack that should disappear */
643
/* promptly with FreeType 2.1! */
645
if ( FT_HAS_FIXED_SIZES( face ) &&
646
( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
648
error = driver->clazz->load_glyph( slot, face->size,
650
load_flags | FT_LOAD_SBITS_ONLY );
652
if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP )
657
FT_Face_Internal internal = face->internal;
658
FT_Int transform_flags = internal->transform_flags;
661
/* since the auto-hinter calls FT_Load_Glyph by itself, */
662
/* make sure that glyphs aren't transformed */
663
internal->transform_flags = 0;
665
/* load auto-hinted outline */
666
hinting = (FT_AutoHinter_Service)hinter->clazz->module_interface;
668
error = hinting->load_glyph( (FT_AutoHinter)hinter,
670
glyph_index, load_flags );
672
internal->transform_flags = transform_flags;
677
error = driver->clazz->load_glyph( slot,
684
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
686
/* check that the loaded outline is correct */
687
error = FT_Outline_Check( &slot->outline );
691
#ifdef GRID_FIT_METRICS
692
if ( !( load_flags & FT_LOAD_NO_HINTING ) )
693
ft_glyphslot_grid_fit_metrics( slot,
694
FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
700
/* compute the advance */
701
if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
704
slot->advance.y = slot->metrics.vertAdvance;
708
slot->advance.x = slot->metrics.horiAdvance;
712
/* compute the linear advance in 16.16 pixels */
713
if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 &&
714
( FT_IS_SCALABLE( face ) ) )
716
FT_Size_Metrics* metrics = &face->size->metrics;
720
slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
721
metrics->x_scale, 64 );
723
slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance,
724
metrics->y_scale, 64 );
727
if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 )
729
FT_Face_Internal internal = face->internal;
732
/* now, transform the glyph image if needed */
733
if ( internal->transform_flags )
736
FT_Renderer renderer = ft_lookup_glyph_renderer( slot );
740
error = renderer->clazz->transform_glyph(
742
&internal->transform_matrix,
743
&internal->transform_delta );
744
else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
746
/* apply `standard' transformation if no renderer is available */
747
if ( &internal->transform_matrix )
748
FT_Outline_Transform( &slot->outline,
749
&internal->transform_matrix );
751
if ( &internal->transform_delta )
752
FT_Outline_Translate( &slot->outline,
753
internal->transform_delta.x,
754
internal->transform_delta.y );
757
/* transform advance */
758
FT_Vector_Transform( &slot->advance, &internal->transform_matrix );
762
FT_TRACE5(( " x advance: %d\n" , slot->advance.x ));
763
FT_TRACE5(( " y advance: %d\n" , slot->advance.y ));
765
FT_TRACE5(( " linear x advance: %d\n" , slot->linearHoriAdvance ));
766
FT_TRACE5(( " linear y advance: %d\n" , slot->linearVertAdvance ));
768
/* do we need to render the image now? */
770
slot->format != FT_GLYPH_FORMAT_BITMAP &&
771
slot->format != FT_GLYPH_FORMAT_COMPOSITE &&
772
load_flags & FT_LOAD_RENDER )
774
FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
777
if ( mode == FT_RENDER_MODE_NORMAL &&
778
(load_flags & FT_LOAD_MONOCHROME ) )
779
mode = FT_RENDER_MODE_MONO;
781
error = FT_Render_Glyph( slot, mode );
789
/* documentation is in freetype.h */
791
FT_EXPORT_DEF( FT_Error )
792
FT_Load_Char( FT_Face face,
794
FT_Int32 load_flags )
800
return FT_Err_Invalid_Face_Handle;
802
glyph_index = (FT_UInt)char_code;
804
glyph_index = FT_Get_Char_Index( face, char_code );
806
return FT_Load_Glyph( face, glyph_index, load_flags );
810
/* destructor for sizes list */
812
destroy_size( FT_Memory memory,
816
/* finalize client-specific data */
817
if ( size->generic.finalizer )
818
size->generic.finalizer( size );
820
/* finalize format-specific stuff */
821
if ( driver->clazz->done_size )
822
driver->clazz->done_size( size );
824
FT_FREE( size->internal );
830
ft_cmap_done_internal( FT_CMap cmap );
834
destroy_charmaps( FT_Face face,
843
for ( n = 0; n < face->num_charmaps; n++ )
845
FT_CMap cmap = FT_CMAP( face->charmaps[n] );
848
ft_cmap_done_internal( cmap );
850
face->charmaps[n] = NULL;
853
FT_FREE( face->charmaps );
854
face->num_charmaps = 0;
858
/* destructor for faces list */
860
destroy_face( FT_Memory memory,
864
FT_Driver_Class clazz = driver->clazz;
867
/* discard auto-hinting data */
868
if ( face->autohint.finalizer )
869
face->autohint.finalizer( face->autohint.data );
871
/* Discard glyph slots for this face. */
872
/* Beware! FT_Done_GlyphSlot() changes the field `face->glyph' */
873
while ( face->glyph )
874
FT_Done_GlyphSlot( face->glyph );
876
/* discard all sizes for this face */
877
FT_List_Finalize( &face->sizes_list,
878
(FT_List_Destructor)destroy_size,
883
/* now discard client data */
884
if ( face->generic.finalizer )
885
face->generic.finalizer( face );
887
/* discard charmaps */
888
destroy_charmaps( face, memory );
890
/* finalize format-specific stuff */
891
if ( clazz->done_face )
892
clazz->done_face( face );
894
/* close the stream for this face if needed */
897
( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
902
if ( face->internal )
904
FT_FREE( face->internal );
911
Destroy_Driver( FT_Driver driver )
913
FT_List_Finalize( &driver->faces_list,
914
(FT_List_Destructor)destroy_face,
918
/* check whether we need to drop the driver's glyph loader */
919
if ( FT_DRIVER_USES_OUTLINES( driver ) )
920
FT_GlyphLoader_Done( driver->glyph_loader );
924
/*************************************************************************/
927
/* find_unicode_charmap */
930
/* This function finds a Unicode charmap, if there is one. */
931
/* And if there is more than one, it tries to favour the more */
932
/* extensive one, i.e., one that supports UCS-4 against those which */
933
/* are limited to the BMP (said UCS-2 encoding.) */
935
/* This function is called from open_face() (just below), and also */
936
/* from FT_Select_Charmap( ..., FT_ENCODING_UNICODE ). */
939
find_unicode_charmap( FT_Face face )
945
/* caller should have already checked that `face' is valid */
948
first = face->charmaps;
951
return FT_Err_Invalid_CharMap_Handle;
954
* The original TrueType specification(s) only specified charmap
955
* formats that are capable of mapping 8 or 16 bit character codes to
958
* However, recent updates to the Apple and OpenType specifications
959
* introduced new formats that are capable of mapping 32-bit character
960
* codes as well. And these are already used on some fonts, mainly to
961
* map non-BMP Asian ideographs as defined in Unicode.
963
* For compatibility purposes, these fonts generally come with
964
* *several* Unicode charmaps:
966
* - One of them in the "old" 16-bit format, that cannot access
967
* all glyphs in the font.
969
* - Another one in the "new" 32-bit format, that can access all
972
* This function has been written to always favor a 32-bit charmap
973
* when found. Otherwise, a 16-bit one is returned when found.
976
/* Since the `interesting' table, with IDs (3,10), is normally the */
977
/* last one, we loop backwards. This loses with type1 fonts with */
978
/* non-BMP characters (<.0001%), this wins with .ttf with non-BMP */
979
/* chars (.01% ?), and this is the same about 99.99% of the time! */
981
cur = first + face->num_charmaps; /* points after the last one */
983
for ( ; --cur >= first; )
985
if ( cur[0]->encoding == FT_ENCODING_UNICODE )
987
/* XXX If some new encodings to represent UCS-4 are added, */
988
/* they should be added here. */
989
if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
990
cur[0]->encoding_id == TT_MS_ID_UCS_4 ) ||
991
( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
992
cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) )
994
#ifdef FT_MAX_CHARMAP_CACHEABLE
995
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
997
FT_ERROR(( "find_unicode_charmap: UCS-4 cmap is found "
998
"at too late position (%d)\n", cur - first ));
1002
face->charmap = cur[0];
1008
/* We do not have any UCS-4 charmap. */
1009
/* Do the loop again and search for UCS-2 charmaps. */
1010
cur = first + face->num_charmaps;
1012
for ( ; --cur >= first; )
1014
if ( cur[0]->encoding == FT_ENCODING_UNICODE )
1016
#ifdef FT_MAX_CHARMAP_CACHEABLE
1017
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
1019
FT_ERROR(( "find_unicode_charmap: UCS-2 cmap is found "
1020
"at too late position (%d)\n", cur - first ));
1024
face->charmap = cur[0];
1029
return FT_Err_Invalid_CharMap_Handle;
1033
/*************************************************************************/
1036
/* find_variant_selector_charmap */
1039
/* This function finds the variant selector charmap, if there is one. */
1040
/* There can only be one (platform=0, specific=5, format=14). */
1043
find_variant_selector_charmap( FT_Face face )
1050
/* caller should have already checked that `face' is valid */
1053
first = face->charmaps;
1058
end = first + face->num_charmaps; /* points after the last one */
1060
for ( cur = first; cur < end; ++cur )
1062
if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
1063
cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
1064
FT_Get_CMap_Format( cur[0] ) == 14 )
1066
#ifdef FT_MAX_CHARMAP_CACHEABLE
1067
if ( cur - first > FT_MAX_CHARMAP_CACHEABLE )
1069
FT_ERROR(( "find_unicode_charmap: UVS cmap is found "
1070
"at too late position (%d)\n", cur - first ));
1082
/*************************************************************************/
1088
/* This function does some work for FT_Open_Face(). */
1091
open_face( FT_Driver driver,
1095
FT_Parameter* params,
1099
FT_Driver_Class clazz;
1101
FT_Error error, error2;
1102
FT_Face_Internal internal = NULL;
1105
clazz = driver->clazz;
1106
memory = driver->root.memory;
1108
/* allocate the face object and perform basic initialization */
1109
if ( FT_ALLOC( face, clazz->face_object_size ) )
1112
if ( FT_NEW( internal ) )
1115
face->internal = internal;
1117
face->driver = driver;
1118
face->memory = memory;
1119
face->stream = stream;
1121
#ifdef FT_CONFIG_OPTION_INCREMENTAL
1126
face->internal->incremental_interface = 0;
1127
for ( i = 0; i < num_params && !face->internal->incremental_interface;
1129
if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
1130
face->internal->incremental_interface =
1131
(FT_Incremental_Interface)params[i].data;
1135
if ( clazz->init_face )
1136
error = clazz->init_face( stream,
1144
/* select Unicode charmap by default */
1145
error2 = find_unicode_charmap( face );
1147
/* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */
1150
/* no error should happen, but we want to play safe */
1151
if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle )
1162
destroy_charmaps( face, memory );
1163
if ( clazz->done_face )
1164
clazz->done_face( face );
1165
FT_FREE( internal );
1174
/* there's a Mac-specific extended implementation of FT_New_Face() */
1175
/* in src/base/ftmac.c */
1177
#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
1179
/* documentation is in freetype.h */
1181
FT_EXPORT_DEF( FT_Error )
1182
FT_New_Face( FT_Library library,
1183
const char* pathname,
1190
/* test for valid `library' and `aface' delayed to FT_Open_Face() */
1192
return FT_Err_Invalid_Argument;
1194
args.flags = FT_OPEN_PATHNAME;
1195
args.pathname = (char*)pathname;
1198
return FT_Open_Face( library, &args, face_index, aface );
1201
#endif /* defined( FT_MACINTOSH ) && !defined( DARWIN_NO_CARBON ) */
1204
/* documentation is in freetype.h */
1206
FT_EXPORT_DEF( FT_Error )
1207
FT_New_Memory_Face( FT_Library library,
1208
const FT_Byte* file_base,
1216
/* test for valid `library' and `face' delayed to FT_Open_Face() */
1218
return FT_Err_Invalid_Argument;
1220
args.flags = FT_OPEN_MEMORY;
1221
args.memory_base = file_base;
1222
args.memory_size = file_size;
1225
return FT_Open_Face( library, &args, face_index, aface );
1229
#ifdef FT_CONFIG_OPTION_MAC_FONTS
1231
/* The behavior here is very similar to that in base/ftmac.c, but it */
1232
/* is designed to work on non-mac systems, so no mac specific calls. */
1234
/* We look at the file and determine if it is a mac dfont file or a mac */
1235
/* resource file, or a macbinary file containing a mac resource file. */
1237
/* Unlike ftmac I'm not going to look at a `FOND'. I don't really see */
1238
/* the point, especially since there may be multiple `FOND' resources. */
1239
/* Instead I'll just look for `sfnt' and `POST' resources, ordered as */
1240
/* they occur in the file. */
1242
/* Note that multiple `POST' resources do not mean multiple postscript */
1243
/* fonts; they all get jammed together to make what is essentially a */
1246
/* We aren't interested in `NFNT' or `FONT' bitmap resources. */
1248
/* As soon as we get an `sfnt' load it into memory and pass it off to */
1251
/* If we have a (set of) `POST' resources, massage them into a (memory) */
1252
/* pfb file and pass that to FT_Open_Face. (As with ftmac.c I'm not */
1253
/* going to try to save the kerning info. After all that lives in the */
1254
/* `FOND' which isn't in the file containing the `POST' resources so */
1255
/* we don't really have access to it. */
1258
/* Finalizer for a memory stream; gets called by FT_Done_Face(). */
1259
/* It frees the memory it uses. */
1262
memory_stream_close( FT_Stream stream )
1264
FT_Memory memory = stream->memory;
1267
FT_FREE( stream->base );
1275
/* Create a new memory stream from a buffer and a size. */
1278
new_memory_stream( FT_Library library,
1281
FT_Stream_CloseFunc close,
1282
FT_Stream *astream )
1290
return FT_Err_Invalid_Library_Handle;
1293
return FT_Err_Invalid_Argument;
1296
memory = library->memory;
1297
if ( FT_NEW( stream ) )
1300
FT_Stream_OpenMemory( stream, base, size );
1302
stream->close = close;
1311
/* Create a new FT_Face given a buffer and a driver name. */
1313
FT_LOCAL_DEF( FT_Error )
1314
open_face_from_buffer( FT_Library library,
1318
const char* driver_name,
1323
FT_Stream stream = NULL;
1324
FT_Memory memory = library->memory;
1327
error = new_memory_stream( library,
1330
memory_stream_close,
1338
args.flags = FT_OPEN_STREAM;
1339
args.stream = stream;
1342
args.flags = args.flags | FT_OPEN_DRIVER;
1343
args.driver = FT_Get_Module( library, driver_name );
1347
/* At this point, face_index has served its purpose; */
1348
/* whoever calls this function has already used it to */
1349
/* locate the correct font data. We should not propagate */
1350
/* this index to FT_Open_Face() (unless it is negative). */
1352
if ( face_index > 0 )
1356
error = FT_Open_Face( library, &args, face_index, aface );
1358
if ( error == FT_Err_Ok )
1359
(*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
1362
FT_Stream_Free( stream, 0 );
1365
FT_Stream_Close( stream );
1374
/* Look up `TYP1' or `CID ' table from sfnt table directory. */
1375
/* `offset' and `length' must exclude the binary header in tables. */
1377
/* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
1378
/* format too. Here, since we can't expect that the TrueType font */
1379
/* driver is loaded unconditially, we must parse the font by */
1380
/* ourselves. We are only interested in the name of the table and */
1384
ft_lookup_PS_in_sfnt_stream( FT_Stream stream,
1388
FT_Bool* is_sfnt_cid )
1391
FT_UShort numTables;
1392
FT_Long pstable_index;
1399
*is_sfnt_cid = FALSE;
1401
/* TODO: support for sfnt-wrapped PS/CID in TTC format */
1403
/* version check for 'typ1' (should be ignored?) */
1404
if ( FT_READ_ULONG( tag ) )
1406
if ( tag != TTAG_typ1 )
1407
return FT_Err_Unknown_File_Format;
1409
if ( FT_READ_USHORT( numTables ) )
1411
if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */
1415
*is_sfnt_cid = FALSE;
1417
for ( i = 0; i < numTables; i++ )
1419
if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) ||
1420
FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
1423
if ( tag == TTAG_CID )
1428
*is_sfnt_cid = TRUE;
1429
if ( face_index < 0 )
1432
else if ( tag == TTAG_TYP1 )
1437
*is_sfnt_cid = FALSE;
1438
if ( face_index < 0 )
1441
if ( face_index >= 0 && pstable_index == face_index )
1444
return FT_Err_Table_Missing;
1448
FT_LOCAL_DEF( FT_Error )
1449
open_face_PS_from_sfnt_stream( FT_Library library,
1453
FT_Parameter *params,
1457
FT_Memory memory = library->memory;
1458
FT_ULong offset, length;
1460
FT_Bool is_sfnt_cid;
1463
FT_UNUSED( num_params );
1464
FT_UNUSED( params );
1467
pos = FT_Stream_Pos( stream );
1469
error = ft_lookup_PS_in_sfnt_stream( stream,
1477
if ( FT_Stream_Seek( stream, pos + offset ) )
1480
if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
1483
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
1487
error = open_face_from_buffer( library,
1490
face_index < 0 ? face_index : 0,
1491
is_sfnt_cid ? "cid" : "type1",
1498
if ( error == FT_Err_Unknown_File_Format )
1500
error1 = FT_Stream_Seek( stream, pos );
1510
#if !defined( FT_MACINTOSH ) || defined( DARWIN_NO_CARBON )
1512
/* The resource header says we've got resource_cnt `POST' (type1) */
1513
/* resources in this file. They all need to be coalesced into */
1514
/* one lump which gets passed on to the type1 driver. */
1515
/* Here can be only one PostScript font in a file so face_index */
1516
/* must be 0 (or -1). */
1519
Mac_Read_POST_Resource( FT_Library library,
1522
FT_Long resource_cnt,
1526
FT_Error error = FT_Err_Cannot_Open_Resource;
1527
FT_Memory memory = library->memory;
1531
FT_Long pfb_len, pfb_pos, pfb_lenpos;
1535
if ( face_index == -1 )
1537
if ( face_index != 0 )
1540
/* Find the length of all the POST resources, concatenated. Assume */
1541
/* worst case (each resource in its own section). */
1543
for ( i = 0; i < resource_cnt; ++i )
1545
error = FT_Stream_Seek( stream, offsets[i] );
1548
if ( FT_READ_LONG( temp ) )
1550
pfb_len += temp + 6;
1553
if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
1557
pfb_data[1] = 1; /* Ascii section */
1558
pfb_data[2] = 0; /* 4-byte length, fill in later */
1567
for ( i = 0; i < resource_cnt; ++i )
1569
error = FT_Stream_Seek( stream, offsets[i] );
1572
if ( FT_READ_LONG( rlen ) )
1574
if ( FT_READ_USHORT( flags ) )
1576
FT_TRACE3(( "POST fragment[%d]: offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n",
1577
i, offsets[i], rlen, flags ));
1579
/* postpone the check of rlen longer than buffer until FT_Stream_Read() */
1580
if ( ( flags >> 8 ) == 0 ) /* Comment, should not be loaded */
1583
/* the flags are part of the resource, so rlen >= 2. */
1584
/* but some fonts declare rlen = 0 for empty fragment */
1590
if ( ( flags >> 8 ) == type )
1594
if ( pfb_lenpos + 3 > pfb_len + 2 )
1596
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
1597
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
1598
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
1599
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
1601
if ( ( flags >> 8 ) == 5 ) /* End of font mark */
1604
if ( pfb_pos + 6 > pfb_len + 2 )
1606
pfb_data[pfb_pos++] = 0x80;
1611
pfb_data[pfb_pos++] = (FT_Byte)type;
1612
pfb_lenpos = pfb_pos;
1613
pfb_data[pfb_pos++] = 0; /* 4-byte length, fill in later */
1614
pfb_data[pfb_pos++] = 0;
1615
pfb_data[pfb_pos++] = 0;
1616
pfb_data[pfb_pos++] = 0;
1619
error = FT_Err_Cannot_Open_Resource;
1620
if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
1623
error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
1629
if ( pfb_pos + 2 > pfb_len + 2 )
1631
pfb_data[pfb_pos++] = 0x80;
1632
pfb_data[pfb_pos++] = 3;
1634
if ( pfb_lenpos + 3 > pfb_len + 2 )
1636
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
1637
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
1638
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
1639
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
1641
return open_face_from_buffer( library,
1649
FT_FREE( pfb_data );
1656
/* The resource header says we've got resource_cnt `sfnt' */
1657
/* (TrueType/OpenType) resources in this file. Look through */
1658
/* them for the one indicated by face_index, load it into mem, */
1659
/* pass it on the the truetype driver and return it. */
1662
Mac_Read_sfnt_Resource( FT_Library library,
1665
FT_Long resource_cnt,
1669
FT_Memory memory = library->memory;
1672
FT_Long flag_offset;
1675
FT_Long face_index_in_resource = 0;
1678
if ( face_index == -1 )
1680
if ( face_index >= resource_cnt )
1681
return FT_Err_Cannot_Open_Resource;
1683
flag_offset = offsets[face_index];
1684
error = FT_Stream_Seek( stream, flag_offset );
1688
if ( FT_READ_LONG( rlen ) )
1691
return FT_Err_Cannot_Open_Resource;
1693
error = open_face_PS_from_sfnt_stream( library,
1701
/* rewind sfnt stream before open_face_PS_from_sfnt_stream() */
1702
if ( FT_Stream_Seek( stream, flag_offset + 4 ) )
1705
if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) )
1707
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
1711
is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
1712
error = open_face_from_buffer( library,
1715
face_index_in_resource,
1716
is_cff ? "cff" : "truetype",
1724
/* Check for a valid resource fork header, or a valid dfont */
1725
/* header. In a resource fork the first 16 bytes are repeated */
1726
/* at the location specified by bytes 4-7. In a dfont bytes */
1727
/* 4-7 point to 16 bytes of zeroes instead. */
1730
IsMacResource( FT_Library library,
1732
FT_Long resource_offset,
1736
FT_Memory memory = library->memory;
1738
FT_Long map_offset, rdara_pos;
1739
FT_Long *data_offsets;
1743
error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
1744
&map_offset, &rdara_pos );
1748
error = FT_Raccess_Get_DataOffsets( library, stream,
1749
map_offset, rdara_pos,
1751
&data_offsets, &count );
1754
error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
1755
face_index, aface );
1756
FT_FREE( data_offsets );
1757
/* POST exists in an LWFN providing a single face */
1759
(*aface)->num_faces = 1;
1763
error = FT_Raccess_Get_DataOffsets( library, stream,
1764
map_offset, rdara_pos,
1766
&data_offsets, &count );
1769
FT_Long face_index_internal = face_index % count;
1772
error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
1773
face_index_internal, aface );
1774
FT_FREE( data_offsets );
1776
(*aface)->num_faces = count;
1783
/* Check for a valid macbinary header, and if we find one */
1784
/* check that the (flattened) resource fork in it is valid. */
1787
IsMacBinary( FT_Library library,
1792
unsigned char header[128];
1794
FT_Long dlen, offset;
1797
if ( NULL == stream )
1798
return FT_Err_Invalid_Stream_Operation;
1800
error = FT_Stream_Seek( stream, 0 );
1804
error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
1808
if ( header[ 0] != 0 ||
1814
header[2 + header[1]] != 0 )
1815
return FT_Err_Unknown_File_Format;
1817
dlen = ( header[0x53] << 24 ) |
1818
( header[0x54] << 16 ) |
1819
( header[0x55] << 8 ) |
1822
rlen = ( header[0x57] << 24 ) |
1823
( header[0x58] << 16 ) |
1824
( header[0x59] << 8 ) |
1827
offset = 128 + ( ( dlen + 127 ) & ~127 );
1829
return IsMacResource( library, stream, offset, face_index, aface );
1837
load_face_in_embedded_rfork( FT_Library library,
1841
const FT_Open_Args *args )
1845
#define FT_COMPONENT trace_raccess
1847
FT_Memory memory = library->memory;
1848
FT_Error error = FT_Err_Unknown_File_Format;
1851
char * file_names[FT_RACCESS_N_RULES];
1852
FT_Long offsets[FT_RACCESS_N_RULES];
1853
FT_Error errors[FT_RACCESS_N_RULES];
1854
FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */
1857
FT_Stream stream2 = 0;
1860
FT_Raccess_Guess( library, stream,
1861
args->pathname, file_names, offsets, errors );
1863
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
1865
is_darwin_vfs = raccess_rule_by_darwin_vfs( i );
1866
if ( is_darwin_vfs && vfs_rfork_has_no_font )
1868
FT_TRACE3(( "Skip rule %d: darwin vfs resource fork"
1869
" is already checked and"
1870
" no font is found\n", i ));
1876
FT_TRACE3(( "Error[%d] has occurred in rule %d\n", errors[i], i ));
1880
args2.flags = FT_OPEN_PATHNAME;
1881
args2.pathname = file_names[i] ? file_names[i] : args->pathname;
1883
FT_TRACE3(( "Try rule %d: %s (offset=%d) ...",
1884
i, args2.pathname, offsets[i] ));
1886
error = FT_Stream_New( library, &args2, &stream2 );
1887
if ( is_darwin_vfs && error == FT_Err_Cannot_Open_Stream )
1888
vfs_rfork_has_no_font = TRUE;
1892
FT_TRACE3(( "failed\n" ));
1896
error = IsMacResource( library, stream2, offsets[i],
1897
face_index, aface );
1898
FT_Stream_Free( stream2, 0 );
1900
FT_TRACE3(( "%s\n", error ? "failed": "successful" ));
1904
else if ( is_darwin_vfs )
1905
vfs_rfork_has_no_font = TRUE;
1908
for (i = 0; i < FT_RACCESS_N_RULES; i++)
1910
if ( file_names[i] )
1911
FT_FREE( file_names[i] );
1914
/* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */
1916
error = FT_Err_Unknown_File_Format;
1921
#define FT_COMPONENT trace_objs
1926
/* Check for some macintosh formats without Carbon framework. */
1927
/* Is this a macbinary file? If so look at the resource fork. */
1928
/* Is this a mac dfont file? */
1929
/* Is this an old style resource fork? (in data) */
1930
/* Else call load_face_in_embedded_rfork to try extra rules */
1931
/* (defined in `ftrfork.c'). */
1934
load_mac_face( FT_Library library,
1938
const FT_Open_Args *args )
1944
error = IsMacBinary( library, stream, face_index, aface );
1945
if ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format )
1949
#define FT_COMPONENT trace_raccess
1951
FT_TRACE3(( "Try as dfont: %s ...", args->pathname ));
1953
error = IsMacResource( library, stream, 0, face_index, aface );
1955
FT_TRACE3(( "%s\n", error ? "failed" : "successful" ));
1958
#define FT_COMPONENT trace_objs
1962
if ( ( FT_ERROR_BASE( error ) == FT_Err_Unknown_File_Format ||
1963
FT_ERROR_BASE( error ) == FT_Err_Invalid_Stream_Operation ) &&
1964
( args->flags & FT_OPEN_PATHNAME ) )
1965
error = load_face_in_embedded_rfork( library, stream,
1966
face_index, aface, args );
1971
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
1974
/* documentation is in freetype.h */
1976
FT_EXPORT_DEF( FT_Error )
1977
FT_Open_Face( FT_Library library,
1978
const FT_Open_Args* args,
1985
FT_Stream stream = NULL;
1986
FT_Face face = NULL;
1987
FT_ListNode node = NULL;
1988
FT_Bool external_stream;
1993
/* test for valid `library' delayed to */
1994
/* FT_Stream_New() */
1996
if ( ( !aface && face_index >= 0 ) || !args )
1997
return FT_Err_Invalid_Argument;
1999
external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
2002
/* create input stream */
2003
error = FT_Stream_New( library, args, &stream );
2007
memory = library->memory;
2009
/* If the font driver is specified in the `args' structure, use */
2010
/* it. Otherwise, we scan the list of registered drivers. */
2011
if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver )
2013
driver = FT_DRIVER( args->driver );
2015
/* not all modules are drivers, so check... */
2016
if ( FT_MODULE_IS_DRIVER( driver ) )
2018
FT_Int num_params = 0;
2019
FT_Parameter* params = 0;
2022
if ( args->flags & FT_OPEN_PARAMS )
2024
num_params = args->num_params;
2025
params = args->params;
2028
error = open_face( driver, stream, face_index,
2029
num_params, params, &face );
2034
error = FT_Err_Invalid_Handle;
2036
FT_Stream_Free( stream, external_stream );
2041
/* check each font driver for an appropriate format */
2042
cur = library->modules;
2043
limit = cur + library->num_modules;
2046
for ( ; cur < limit; cur++ )
2048
/* not all modules are font drivers, so check... */
2049
if ( FT_MODULE_IS_DRIVER( cur[0] ) )
2051
FT_Int num_params = 0;
2052
FT_Parameter* params = 0;
2055
driver = FT_DRIVER( cur[0] );
2057
if ( args->flags & FT_OPEN_PARAMS )
2059
num_params = args->num_params;
2060
params = args->params;
2063
error = open_face( driver, stream, face_index,
2064
num_params, params, &face );
2068
#ifdef FT_CONFIG_OPTION_MAC_FONTS
2069
if ( ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 &&
2070
FT_ERROR_BASE( error ) == FT_Err_Table_Missing )
2072
/* TrueType but essential tables are missing */
2073
if ( FT_Stream_Seek( stream, 0 ) )
2076
error = open_face_PS_from_sfnt_stream( library,
2084
FT_Stream_Free( stream, external_stream );
2090
if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
2096
/* If we are on the mac, and we get an FT_Err_Invalid_Stream_Operation */
2097
/* it may be because we have an empty data fork, so we need to check */
2098
/* the resource fork. */
2099
if ( FT_ERROR_BASE( error ) != FT_Err_Cannot_Open_Stream &&
2100
FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format &&
2101
FT_ERROR_BASE( error ) != FT_Err_Invalid_Stream_Operation )
2104
#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
2105
error = load_mac_face( library, stream, face_index, aface, args );
2108
/* We don't want to go to Success here. We've already done that. */
2109
/* On the other hand, if we succeeded we still need to close this */
2110
/* stream (we opened a different stream which extracted the */
2111
/* interesting information out of this stream here. That stream */
2112
/* will still be open and the face will point to it). */
2113
FT_Stream_Free( stream, external_stream );
2117
if ( FT_ERROR_BASE( error ) != FT_Err_Unknown_File_Format )
2119
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
2121
/* no driver is able to handle this format */
2122
error = FT_Err_Unknown_File_Format;
2125
FT_Stream_Free( stream, external_stream );
2130
FT_TRACE4(( "FT_Open_Face: New face object, adding to list\n" ));
2132
/* set the FT_FACE_FLAG_EXTERNAL_STREAM bit for FT_Done_Face */
2133
if ( external_stream )
2134
face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
2136
/* add the face object to its driver's list */
2137
if ( FT_NEW( node ) )
2141
/* don't assume driver is the same as face->driver, so use */
2142
/* face->driver instead. */
2143
FT_List_Add( &face->driver->faces_list, node );
2145
/* now allocate a glyph slot object for the face */
2146
FT_TRACE4(( "FT_Open_Face: Creating glyph slot\n" ));
2148
if ( face_index >= 0 )
2150
error = FT_New_GlyphSlot( face, NULL );
2154
/* finally, allocate a size object for the face */
2159
FT_TRACE4(( "FT_Open_Face: Creating size object\n" ));
2161
error = FT_New_Size( face, &size );
2171
if ( FT_IS_SCALABLE( face ) )
2173
if ( face->height < 0 )
2174
face->height = (FT_Short)-face->height;
2176
if ( !FT_HAS_VERTICAL( face ) )
2177
face->max_advance_height = (FT_Short)face->height;
2180
if ( FT_HAS_FIXED_SIZES( face ) )
2185
for ( i = 0; i < face->num_fixed_sizes; i++ )
2187
FT_Bitmap_Size* bsize = face->available_sizes + i;
2190
if ( bsize->height < 0 )
2191
bsize->height = (FT_Short)-bsize->height;
2192
if ( bsize->x_ppem < 0 )
2193
bsize->x_ppem = (FT_Short)-bsize->x_ppem;
2194
if ( bsize->y_ppem < 0 )
2195
bsize->y_ppem = -bsize->y_ppem;
2199
/* initialize internal face data */
2201
FT_Face_Internal internal = face->internal;
2204
internal->transform_matrix.xx = 0x10000L;
2205
internal->transform_matrix.xy = 0;
2206
internal->transform_matrix.yx = 0;
2207
internal->transform_matrix.yy = 0x10000L;
2209
internal->transform_delta.x = 0;
2210
internal->transform_delta.y = 0;
2212
internal->refcount = 1;
2218
FT_Done_Face( face );
2223
FT_Done_Face( face );
2226
FT_TRACE4(( "FT_Open_Face: Return %d\n", error ));
2232
/* documentation is in freetype.h */
2234
FT_EXPORT_DEF( FT_Error )
2235
FT_Attach_File( FT_Face face,
2236
const char* filepathname )
2241
/* test for valid `face' delayed to FT_Attach_Stream() */
2243
if ( !filepathname )
2244
return FT_Err_Invalid_Argument;
2247
open.flags = FT_OPEN_PATHNAME;
2248
open.pathname = (char*)filepathname;
2250
return FT_Attach_Stream( face, &open );
2254
/* documentation is in freetype.h */
2256
FT_EXPORT_DEF( FT_Error )
2257
FT_Attach_Stream( FT_Face face,
2258
FT_Open_Args* parameters )
2264
FT_Driver_Class clazz;
2267
/* test for valid `parameters' delayed to FT_Stream_New() */
2270
return FT_Err_Invalid_Face_Handle;
2272
driver = face->driver;
2274
return FT_Err_Invalid_Driver_Handle;
2276
error = FT_Stream_New( driver->root.library, parameters, &stream );
2280
/* we implement FT_Attach_Stream in each driver through the */
2281
/* `attach_file' interface */
2283
error = FT_Err_Unimplemented_Feature;
2284
clazz = driver->clazz;
2285
if ( clazz->attach_file )
2286
error = clazz->attach_file( face, stream );
2288
/* close the attached stream */
2289
FT_Stream_Free( stream,
2290
(FT_Bool)( parameters->stream &&
2291
( parameters->flags & FT_OPEN_STREAM ) ) );
2298
/* documentation is in freetype.h */
2300
FT_EXPORT_DEF( FT_Error )
2301
FT_Reference_Face( FT_Face face )
2303
face->internal->refcount++;
2309
/* documentation is in freetype.h */
2311
FT_EXPORT_DEF( FT_Error )
2312
FT_Done_Face( FT_Face face )
2320
error = FT_Err_Invalid_Face_Handle;
2321
if ( face && face->driver )
2323
face->internal->refcount--;
2324
if ( face->internal->refcount > 0 )
2328
driver = face->driver;
2329
memory = driver->root.memory;
2331
/* find face in driver's list */
2332
node = FT_List_Find( &driver->faces_list, face );
2335
/* remove face object from the driver's list */
2336
FT_List_Remove( &driver->faces_list, node );
2339
/* now destroy the object proper */
2340
destroy_face( memory, face, driver );
2350
/* documentation is in ftobjs.h */
2352
FT_EXPORT_DEF( FT_Error )
2353
FT_New_Size( FT_Face face,
2359
FT_Driver_Class clazz;
2362
FT_ListNode node = 0;
2366
return FT_Err_Invalid_Face_Handle;
2369
return FT_Err_Invalid_Size_Handle;
2371
if ( !face->driver )
2372
return FT_Err_Invalid_Driver_Handle;
2376
driver = face->driver;
2377
clazz = driver->clazz;
2378
memory = face->memory;
2380
/* Allocate new size object and perform basic initialisation */
2381
if ( FT_ALLOC( size, clazz->size_object_size ) || FT_NEW( node ) )
2386
/* for now, do not use any internal fields in size objects */
2389
if ( clazz->init_size )
2390
error = clazz->init_size( size );
2392
/* in case of success, add to the face's list */
2397
FT_List_Add( &face->sizes_list, node );
2411
/* documentation is in ftobjs.h */
2413
FT_EXPORT_DEF( FT_Error )
2414
FT_Done_Size( FT_Size size )
2424
return FT_Err_Invalid_Size_Handle;
2428
return FT_Err_Invalid_Face_Handle;
2430
driver = face->driver;
2432
return FT_Err_Invalid_Driver_Handle;
2434
memory = driver->root.memory;
2437
node = FT_List_Find( &face->sizes_list, size );
2440
FT_List_Remove( &face->sizes_list, node );
2443
if ( face->size == size )
2446
if ( face->sizes_list.head )
2447
face->size = (FT_Size)(face->sizes_list.head->data);
2450
destroy_size( memory, size, driver );
2453
error = FT_Err_Invalid_Size_Handle;
2459
/* documentation is in ftobjs.h */
2461
FT_BASE_DEF( FT_Error )
2462
FT_Match_Size( FT_Face face,
2463
FT_Size_Request req,
2464
FT_Bool ignore_width,
2465
FT_ULong* size_index )
2471
if ( !FT_HAS_FIXED_SIZES( face ) )
2472
return FT_Err_Invalid_Face_Handle;
2474
/* FT_Bitmap_Size doesn't provide enough info... */
2475
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
2476
return FT_Err_Unimplemented_Feature;
2478
w = FT_REQUEST_WIDTH ( req );
2479
h = FT_REQUEST_HEIGHT( req );
2481
if ( req->width && !req->height )
2483
else if ( !req->width && req->height )
2486
w = FT_PIX_ROUND( w );
2487
h = FT_PIX_ROUND( h );
2489
for ( i = 0; i < face->num_fixed_sizes; i++ )
2491
FT_Bitmap_Size* bsize = face->available_sizes + i;
2494
if ( h != FT_PIX_ROUND( bsize->y_ppem ) )
2497
if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width )
2500
*size_index = (FT_ULong)i;
2506
return FT_Err_Invalid_Pixel_Size;
2510
/* documentation is in ftobjs.h */
2513
ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics,
2516
FT_Pos height = metrics->height;
2519
/* compensate for glyph with bbox above/below the baseline */
2520
if ( metrics->horiBearingY < 0 )
2522
if ( height < metrics->horiBearingY )
2523
height = metrics->horiBearingY;
2525
else if ( metrics->horiBearingY > 0 )
2526
height -= metrics->horiBearingY;
2528
/* the factor 1.2 is a heuristical value */
2530
advance = height * 12 / 10;
2532
metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2;
2533
metrics->vertBearingY = ( advance - height ) / 2;
2534
metrics->vertAdvance = advance;
2539
ft_recompute_scaled_metrics( FT_Face face,
2540
FT_Size_Metrics* metrics )
2542
/* Compute root ascender, descender, test height, and max_advance */
2544
#ifdef GRID_FIT_METRICS
2545
metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender,
2546
metrics->y_scale ) );
2548
metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender,
2549
metrics->y_scale ) );
2551
metrics->height = FT_PIX_ROUND( FT_MulFix( face->height,
2552
metrics->y_scale ) );
2554
metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width,
2555
metrics->x_scale ) );
2556
#else /* !GRID_FIT_METRICS */
2557
metrics->ascender = FT_MulFix( face->ascender,
2560
metrics->descender = FT_MulFix( face->descender,
2563
metrics->height = FT_MulFix( face->height,
2566
metrics->max_advance = FT_MulFix( face->max_advance_width,
2568
#endif /* !GRID_FIT_METRICS */
2573
FT_Select_Metrics( FT_Face face,
2574
FT_ULong strike_index )
2576
FT_Size_Metrics* metrics;
2577
FT_Bitmap_Size* bsize;
2580
metrics = &face->size->metrics;
2581
bsize = face->available_sizes + strike_index;
2583
metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 );
2584
metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 );
2586
if ( FT_IS_SCALABLE( face ) )
2588
metrics->x_scale = FT_DivFix( bsize->x_ppem,
2589
face->units_per_EM );
2590
metrics->y_scale = FT_DivFix( bsize->y_ppem,
2591
face->units_per_EM );
2593
ft_recompute_scaled_metrics( face, metrics );
2597
metrics->x_scale = 1L << 16;
2598
metrics->y_scale = 1L << 16;
2599
metrics->ascender = bsize->y_ppem;
2600
metrics->descender = 0;
2601
metrics->height = bsize->height << 6;
2602
metrics->max_advance = bsize->x_ppem;
2608
FT_Request_Metrics( FT_Face face,
2609
FT_Size_Request req )
2611
FT_Size_Metrics* metrics;
2614
metrics = &face->size->metrics;
2616
if ( FT_IS_SCALABLE( face ) )
2618
FT_Long w = 0, h = 0, scaled_w = 0, scaled_h = 0;
2621
switch ( req->type )
2623
case FT_SIZE_REQUEST_TYPE_NOMINAL:
2624
w = h = face->units_per_EM;
2627
case FT_SIZE_REQUEST_TYPE_REAL_DIM:
2628
w = h = face->ascender - face->descender;
2631
case FT_SIZE_REQUEST_TYPE_BBOX:
2632
w = face->bbox.xMax - face->bbox.xMin;
2633
h = face->bbox.yMax - face->bbox.yMin;
2636
case FT_SIZE_REQUEST_TYPE_CELL:
2637
w = face->max_advance_width;
2638
h = face->ascender - face->descender;
2641
case FT_SIZE_REQUEST_TYPE_SCALES:
2642
metrics->x_scale = (FT_Fixed)req->width;
2643
metrics->y_scale = (FT_Fixed)req->height;
2644
if ( !metrics->x_scale )
2645
metrics->x_scale = metrics->y_scale;
2646
else if ( !metrics->y_scale )
2647
metrics->y_scale = metrics->x_scale;
2648
goto Calculate_Ppem;
2650
case FT_SIZE_REQUEST_TYPE_MAX:
2654
/* to be on the safe side */
2661
scaled_w = FT_REQUEST_WIDTH ( req );
2662
scaled_h = FT_REQUEST_HEIGHT( req );
2664
/* determine scales */
2667
metrics->x_scale = FT_DivFix( scaled_w, w );
2671
metrics->y_scale = FT_DivFix( scaled_h, h );
2673
if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
2675
if ( metrics->y_scale > metrics->x_scale )
2676
metrics->y_scale = metrics->x_scale;
2678
metrics->x_scale = metrics->y_scale;
2683
metrics->y_scale = metrics->x_scale;
2684
scaled_h = FT_MulDiv( scaled_w, h, w );
2689
metrics->x_scale = metrics->y_scale = FT_DivFix( scaled_h, h );
2690
scaled_w = FT_MulDiv( scaled_h, w, h );
2694
/* calculate the ppems */
2695
if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
2697
scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale );
2698
scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
2701
metrics->x_ppem = (FT_UShort)( ( scaled_w + 32 ) >> 6 );
2702
metrics->y_ppem = (FT_UShort)( ( scaled_h + 32 ) >> 6 );
2704
ft_recompute_scaled_metrics( face, metrics );
2709
metrics->x_scale = 1L << 16;
2710
metrics->y_scale = 1L << 16;
2715
/* documentation is in freetype.h */
2717
FT_EXPORT_DEF( FT_Error )
2718
FT_Select_Size( FT_Face face,
2719
FT_Int strike_index )
2721
FT_Driver_Class clazz;
2724
if ( !face || !FT_HAS_FIXED_SIZES( face ) )
2725
return FT_Err_Invalid_Face_Handle;
2727
if ( strike_index < 0 || strike_index >= face->num_fixed_sizes )
2728
return FT_Err_Invalid_Argument;
2730
clazz = face->driver->clazz;
2732
if ( clazz->select_size )
2733
return clazz->select_size( face->size, (FT_ULong)strike_index );
2735
FT_Select_Metrics( face, (FT_ULong)strike_index );
2741
/* documentation is in freetype.h */
2743
FT_EXPORT_DEF( FT_Error )
2744
FT_Request_Size( FT_Face face,
2745
FT_Size_Request req )
2747
FT_Driver_Class clazz;
2748
FT_ULong strike_index;
2752
return FT_Err_Invalid_Face_Handle;
2754
if ( !req || req->width < 0 || req->height < 0 ||
2755
req->type >= FT_SIZE_REQUEST_TYPE_MAX )
2756
return FT_Err_Invalid_Argument;
2758
clazz = face->driver->clazz;
2760
if ( clazz->request_size )
2761
return clazz->request_size( face->size, req );
2764
* The reason that a driver doesn't have `request_size' defined is
2765
* either that the scaling here suffices or that the supported formats
2766
* are bitmap-only and size matching is not implemented.
2768
* In the latter case, a simple size matching is done.
2770
if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) )
2775
error = FT_Match_Size( face, req, 0, &strike_index );
2779
FT_TRACE3(( "FT_Request_Size: bitmap strike %lu matched\n",
2782
return FT_Select_Size( face, (FT_Int)strike_index );
2785
FT_Request_Metrics( face, req );
2791
/* documentation is in freetype.h */
2793
FT_EXPORT_DEF( FT_Error )
2794
FT_Set_Char_Size( FT_Face face,
2795
FT_F26Dot6 char_width,
2796
FT_F26Dot6 char_height,
2797
FT_UInt horz_resolution,
2798
FT_UInt vert_resolution )
2800
FT_Size_RequestRec req;
2804
char_width = char_height;
2805
else if ( !char_height )
2806
char_height = char_width;
2808
if ( !horz_resolution )
2809
horz_resolution = vert_resolution;
2810
else if ( !vert_resolution )
2811
vert_resolution = horz_resolution;
2813
if ( char_width < 1 * 64 )
2814
char_width = 1 * 64;
2815
if ( char_height < 1 * 64 )
2816
char_height = 1 * 64;
2818
if ( !horz_resolution )
2819
horz_resolution = vert_resolution = 72;
2821
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
2822
req.width = char_width;
2823
req.height = char_height;
2824
req.horiResolution = horz_resolution;
2825
req.vertResolution = vert_resolution;
2827
return FT_Request_Size( face, &req );
2831
/* documentation is in freetype.h */
2833
FT_EXPORT_DEF( FT_Error )
2834
FT_Set_Pixel_Sizes( FT_Face face,
2835
FT_UInt pixel_width,
2836
FT_UInt pixel_height )
2838
FT_Size_RequestRec req;
2841
if ( pixel_width == 0 )
2842
pixel_width = pixel_height;
2843
else if ( pixel_height == 0 )
2844
pixel_height = pixel_width;
2846
if ( pixel_width < 1 )
2848
if ( pixel_height < 1 )
2851
/* use `>=' to avoid potential compiler warning on 16bit platforms */
2852
if ( pixel_width >= 0xFFFFU )
2853
pixel_width = 0xFFFFU;
2854
if ( pixel_height >= 0xFFFFU )
2855
pixel_height = 0xFFFFU;
2857
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
2858
req.width = pixel_width << 6;
2859
req.height = pixel_height << 6;
2860
req.horiResolution = 0;
2861
req.vertResolution = 0;
2863
return FT_Request_Size( face, &req );
2867
/* documentation is in freetype.h */
2869
FT_EXPORT_DEF( FT_Error )
2870
FT_Get_Kerning( FT_Face face,
2872
FT_UInt right_glyph,
2874
FT_Vector *akerning )
2876
FT_Error error = FT_Err_Ok;
2881
return FT_Err_Invalid_Face_Handle;
2884
return FT_Err_Invalid_Argument;
2886
driver = face->driver;
2891
if ( driver->clazz->get_kerning )
2893
error = driver->clazz->get_kerning( face,
2899
if ( kern_mode != FT_KERNING_UNSCALED )
2901
akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale );
2902
akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale );
2904
if ( kern_mode != FT_KERNING_UNFITTED )
2906
/* we scale down kerning values for small ppem values */
2907
/* to avoid that rounding makes them too big. */
2908
/* `25' has been determined heuristically. */
2909
if ( face->size->metrics.x_ppem < 25 )
2910
akerning->x = FT_MulDiv( akerning->x,
2911
face->size->metrics.x_ppem, 25 );
2912
if ( face->size->metrics.y_ppem < 25 )
2913
akerning->y = FT_MulDiv( akerning->y,
2914
face->size->metrics.y_ppem, 25 );
2916
akerning->x = FT_PIX_ROUND( akerning->x );
2917
akerning->y = FT_PIX_ROUND( akerning->y );
2927
/* documentation is in freetype.h */
2929
FT_EXPORT_DEF( FT_Error )
2930
FT_Get_Track_Kerning( FT_Face face,
2931
FT_Fixed point_size,
2933
FT_Fixed* akerning )
2935
FT_Service_Kerning service;
2936
FT_Error error = FT_Err_Ok;
2940
return FT_Err_Invalid_Face_Handle;
2943
return FT_Err_Invalid_Argument;
2945
FT_FACE_FIND_SERVICE( face, service, KERNING );
2947
return FT_Err_Unimplemented_Feature;
2949
error = service->get_track( face,
2958
/* documentation is in freetype.h */
2960
FT_EXPORT_DEF( FT_Error )
2961
FT_Select_Charmap( FT_Face face,
2962
FT_Encoding encoding )
2969
return FT_Err_Invalid_Face_Handle;
2971
if ( encoding == FT_ENCODING_NONE )
2972
return FT_Err_Invalid_Argument;
2974
/* FT_ENCODING_UNICODE is special. We try to find the `best' Unicode */
2975
/* charmap available, i.e., one with UCS-4 characters, if possible. */
2977
/* This is done by find_unicode_charmap() above, to share code. */
2978
if ( encoding == FT_ENCODING_UNICODE )
2979
return find_unicode_charmap( face );
2981
cur = face->charmaps;
2983
return FT_Err_Invalid_CharMap_Handle;
2985
limit = cur + face->num_charmaps;
2987
for ( ; cur < limit; cur++ )
2989
if ( cur[0]->encoding == encoding )
2991
#ifdef FT_MAX_CHARMAP_CACHEABLE
2992
if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
2994
FT_ERROR(( "FT_Select_Charmap: requested charmap is found (%d), "
2995
"but in too late position to cache\n",
2996
cur - face->charmaps ));
3000
face->charmap = cur[0];
3005
return FT_Err_Invalid_Argument;
3009
/* documentation is in freetype.h */
3011
FT_EXPORT_DEF( FT_Error )
3012
FT_Set_Charmap( FT_Face face,
3013
FT_CharMap charmap )
3020
return FT_Err_Invalid_Face_Handle;
3022
cur = face->charmaps;
3024
return FT_Err_Invalid_CharMap_Handle;
3025
if ( FT_Get_CMap_Format( charmap ) == 14 )
3026
return FT_Err_Invalid_Argument;
3028
limit = cur + face->num_charmaps;
3030
for ( ; cur < limit; cur++ )
3032
if ( cur[0] == charmap )
3034
#ifdef FT_MAX_CHARMAP_CACHEABLE
3035
if ( cur - face->charmaps > FT_MAX_CHARMAP_CACHEABLE )
3037
FT_ERROR(( "FT_Set_Charmap: requested charmap is found (%d), "
3038
"but in too late position to cache\n",
3039
cur - face->charmaps ));
3043
face->charmap = cur[0];
3047
return FT_Err_Invalid_Argument;
3051
/* documentation is in freetype.h */
3053
FT_EXPORT_DEF( FT_Int )
3054
FT_Get_Charmap_Index( FT_CharMap charmap )
3059
if ( !charmap || !charmap->face )
3062
for ( i = 0; i < charmap->face->num_charmaps; i++ )
3063
if ( charmap->face->charmaps[i] == charmap )
3066
FT_ASSERT( i < charmap->face->num_charmaps );
3068
#ifdef FT_MAX_CHARMAP_CACHEABLE
3069
if ( i > FT_MAX_CHARMAP_CACHEABLE )
3071
FT_ERROR(( "FT_Get_Charmap_Index: requested charmap is found (%d), "
3072
"but in too late position to cache\n",
3082
ft_cmap_done_internal( FT_CMap cmap )
3084
FT_CMap_Class clazz = cmap->clazz;
3085
FT_Face face = cmap->charmap.face;
3086
FT_Memory memory = FT_FACE_MEMORY(face);
3090
clazz->done( cmap );
3097
FT_CMap_Done( FT_CMap cmap )
3101
FT_Face face = cmap->charmap.face;
3102
FT_Memory memory = FT_FACE_MEMORY( face );
3107
for ( i = 0; i < face->num_charmaps; i++ )
3109
if ( (FT_CMap)face->charmaps[i] == cmap )
3111
FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1];
3114
if ( FT_RENEW_ARRAY( face->charmaps,
3116
face->num_charmaps - 1 ) )
3119
/* remove it from our list of charmaps */
3120
for ( j = i + 1; j < face->num_charmaps; j++ )
3122
if ( j == face->num_charmaps - 1 )
3123
face->charmaps[j - 1] = last_charmap;
3125
face->charmaps[j - 1] = face->charmaps[j];
3128
face->num_charmaps--;
3130
if ( (FT_CMap)face->charmap == cmap )
3131
face->charmap = NULL;
3133
ft_cmap_done_internal( cmap );
3142
FT_BASE_DEF( FT_Error )
3143
FT_CMap_New( FT_CMap_Class clazz,
3144
FT_Pointer init_data,
3148
FT_Error error = FT_Err_Ok;
3154
if ( clazz == NULL || charmap == NULL || charmap->face == NULL )
3155
return FT_Err_Invalid_Argument;
3157
face = charmap->face;
3158
memory = FT_FACE_MEMORY( face );
3160
if ( !FT_ALLOC( cmap, clazz->size ) )
3162
cmap->charmap = *charmap;
3163
cmap->clazz = clazz;
3167
error = clazz->init( cmap, init_data );
3172
/* add it to our list of charmaps */
3173
if ( FT_RENEW_ARRAY( face->charmaps,
3175
face->num_charmaps + 1 ) )
3178
face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
3188
ft_cmap_done_internal( cmap );
3194
/* documentation is in freetype.h */
3196
FT_EXPORT_DEF( FT_UInt )
3197
FT_Get_Char_Index( FT_Face face,
3203
if ( face && face->charmap )
3205
FT_CMap cmap = FT_CMAP( face->charmap );
3208
if ( charcode > 0xFFFFFFFFUL )
3210
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3211
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3213
result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
3219
/* documentation is in freetype.h */
3221
FT_EXPORT_DEF( FT_ULong )
3222
FT_Get_First_Char( FT_Face face,
3225
FT_ULong result = 0;
3229
if ( face && face->charmap && face->num_glyphs )
3231
gindex = FT_Get_Char_Index( face, 0 );
3232
if ( gindex == 0 || gindex >= (FT_UInt)face->num_glyphs )
3233
result = FT_Get_Next_Char( face, 0, &gindex );
3243
/* documentation is in freetype.h */
3245
FT_EXPORT_DEF( FT_ULong )
3246
FT_Get_Next_Char( FT_Face face,
3250
FT_ULong result = 0;
3254
if ( face && face->charmap && face->num_glyphs )
3256
FT_UInt32 code = (FT_UInt32)charcode;
3257
FT_CMap cmap = FT_CMAP( face->charmap );
3261
gindex = cmap->clazz->char_next( cmap, &code );
3262
} while ( gindex >= (FT_UInt)face->num_glyphs );
3264
result = ( gindex == 0 ) ? 0 : code;
3274
/* documentation is in freetype.h */
3276
FT_EXPORT_DEF( FT_UInt )
3277
FT_Face_GetCharVariantIndex( FT_Face face,
3279
FT_ULong variantSelector )
3284
if ( face && face->charmap &&
3285
face->charmap->encoding == FT_ENCODING_UNICODE )
3287
FT_CharMap charmap = find_variant_selector_charmap( face );
3288
FT_CMap ucmap = FT_CMAP( face->charmap );
3291
if ( charmap != NULL )
3293
FT_CMap vcmap = FT_CMAP( charmap );
3296
if ( charcode > 0xFFFFFFFFUL )
3298
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3299
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3301
if ( variantSelector > 0xFFFFFFFFUL )
3303
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3304
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3307
result = vcmap->clazz->char_var_index( vcmap, ucmap,
3308
(FT_UInt32)charcode,
3309
(FT_UInt32)variantSelector );
3317
/* documentation is in freetype.h */
3319
FT_EXPORT_DEF( FT_Int )
3320
FT_Face_GetCharVariantIsDefault( FT_Face face,
3322
FT_ULong variantSelector )
3329
FT_CharMap charmap = find_variant_selector_charmap( face );
3332
if ( charmap != NULL )
3334
FT_CMap vcmap = FT_CMAP( charmap );
3337
if ( charcode > 0xFFFFFFFFUL )
3339
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3340
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3342
if ( variantSelector > 0xFFFFFFFFUL )
3344
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3345
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3348
result = vcmap->clazz->char_var_default( vcmap,
3349
(FT_UInt32)charcode,
3350
(FT_UInt32)variantSelector );
3358
/* documentation is in freetype.h */
3360
FT_EXPORT_DEF( FT_UInt32* )
3361
FT_Face_GetVariantSelectors( FT_Face face )
3363
FT_UInt32 *result = NULL;
3368
FT_CharMap charmap = find_variant_selector_charmap( face );
3371
if ( charmap != NULL )
3373
FT_CMap vcmap = FT_CMAP( charmap );
3374
FT_Memory memory = FT_FACE_MEMORY( face );
3377
result = vcmap->clazz->variant_list( vcmap, memory );
3385
/* documentation is in freetype.h */
3387
FT_EXPORT_DEF( FT_UInt32* )
3388
FT_Face_GetVariantsOfChar( FT_Face face,
3391
FT_UInt32 *result = NULL;
3396
FT_CharMap charmap = find_variant_selector_charmap( face );
3399
if ( charmap != NULL )
3401
FT_CMap vcmap = FT_CMAP( charmap );
3402
FT_Memory memory = FT_FACE_MEMORY( face );
3405
if ( charcode > 0xFFFFFFFFUL )
3407
FT_TRACE1(( "FT_Get_Char_Index: too large charcode" ));
3408
FT_TRACE1(( " 0x%x is truncated\n", charcode ));
3411
result = vcmap->clazz->charvariant_list( vcmap, memory,
3412
(FT_UInt32)charcode );
3419
/* documentation is in freetype.h */
3421
FT_EXPORT_DEF( FT_UInt32* )
3422
FT_Face_GetCharsOfVariant( FT_Face face,
3423
FT_ULong variantSelector )
3425
FT_UInt32 *result = NULL;
3430
FT_CharMap charmap = find_variant_selector_charmap( face );
3433
if ( charmap != NULL )
3435
FT_CMap vcmap = FT_CMAP( charmap );
3436
FT_Memory memory = FT_FACE_MEMORY( face );
3439
if ( variantSelector > 0xFFFFFFFFUL )
3441
FT_TRACE1(( "FT_Get_Char_Index: too large variantSelector" ));
3442
FT_TRACE1(( " 0x%x is truncated\n", variantSelector ));
3445
result = vcmap->clazz->variantchar_list( vcmap, memory,
3446
(FT_UInt32)variantSelector );
3454
/* documentation is in freetype.h */
3456
FT_EXPORT_DEF( FT_UInt )
3457
FT_Get_Name_Index( FT_Face face,
3458
FT_String* glyph_name )
3463
if ( face && FT_HAS_GLYPH_NAMES( face ) )
3465
FT_Service_GlyphDict service;
3468
FT_FACE_LOOKUP_SERVICE( face,
3472
if ( service && service->name_index )
3473
result = service->name_index( face, glyph_name );
3480
/* documentation is in freetype.h */
3482
FT_EXPORT_DEF( FT_Error )
3483
FT_Get_Glyph_Name( FT_Face face,
3484
FT_UInt glyph_index,
3486
FT_UInt buffer_max )
3488
FT_Error error = FT_Err_Invalid_Argument;
3491
/* clean up buffer */
3492
if ( buffer && buffer_max > 0 )
3493
((FT_Byte*)buffer)[0] = 0;
3496
(FT_Long)glyph_index <= face->num_glyphs &&
3497
FT_HAS_GLYPH_NAMES( face ) )
3499
FT_Service_GlyphDict service;
3502
FT_FACE_LOOKUP_SERVICE( face,
3506
if ( service && service->get_name )
3507
error = service->get_name( face, glyph_index, buffer, buffer_max );
3514
/* documentation is in freetype.h */
3516
FT_EXPORT_DEF( const char* )
3517
FT_Get_Postscript_Name( FT_Face face )
3519
const char* result = NULL;
3527
FT_Service_PsFontName service;
3530
FT_FACE_LOOKUP_SERVICE( face,
3532
POSTSCRIPT_FONT_NAME );
3534
if ( service && service->get_ps_font_name )
3535
result = service->get_ps_font_name( face );
3543
/* documentation is in tttables.h */
3545
FT_EXPORT_DEF( void* )
3546
FT_Get_Sfnt_Table( FT_Face face,
3550
FT_Service_SFNT_Table service;
3553
if ( face && FT_IS_SFNT( face ) )
3555
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3556
if ( service != NULL )
3557
table = service->get_table( face, tag );
3564
/* documentation is in tttables.h */
3566
FT_EXPORT_DEF( FT_Error )
3567
FT_Load_Sfnt_Table( FT_Face face,
3573
FT_Service_SFNT_Table service;
3576
if ( !face || !FT_IS_SFNT( face ) )
3577
return FT_Err_Invalid_Face_Handle;
3579
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3580
if ( service == NULL )
3581
return FT_Err_Unimplemented_Feature;
3583
return service->load_table( face, tag, offset, buffer, length );
3587
/* documentation is in tttables.h */
3589
FT_EXPORT_DEF( FT_Error )
3590
FT_Sfnt_Table_Info( FT_Face face,
3591
FT_UInt table_index,
3595
FT_Service_SFNT_Table service;
3599
if ( !face || !FT_IS_SFNT( face ) )
3600
return FT_Err_Invalid_Face_Handle;
3602
FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
3603
if ( service == NULL )
3604
return FT_Err_Unimplemented_Feature;
3606
return service->table_info( face, table_index, tag, &offset, length );
3610
/* documentation is in tttables.h */
3612
FT_EXPORT_DEF( FT_ULong )
3613
FT_Get_CMap_Language_ID( FT_CharMap charmap )
3615
FT_Service_TTCMaps service;
3617
TT_CMapInfo cmap_info;
3620
if ( !charmap || !charmap->face )
3623
face = charmap->face;
3624
FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
3625
if ( service == NULL )
3627
if ( service->get_cmap_info( charmap, &cmap_info ))
3630
return cmap_info.language;
3634
/* documentation is in tttables.h */
3636
FT_EXPORT_DEF( FT_Long )
3637
FT_Get_CMap_Format( FT_CharMap charmap )
3639
FT_Service_TTCMaps service;
3641
TT_CMapInfo cmap_info;
3644
if ( !charmap || !charmap->face )
3647
face = charmap->face;
3648
FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
3649
if ( service == NULL )
3651
if ( service->get_cmap_info( charmap, &cmap_info ))
3654
return cmap_info.format;
3658
/* documentation is in ftsizes.h */
3660
FT_EXPORT_DEF( FT_Error )
3661
FT_Activate_Size( FT_Size size )
3667
return FT_Err_Invalid_Argument;
3670
if ( face == NULL || face->driver == NULL )
3671
return FT_Err_Invalid_Argument;
3673
/* we don't need anything more complex than that; all size objects */
3674
/* are already listed by the face */
3681
/*************************************************************************/
3682
/*************************************************************************/
3683
/*************************************************************************/
3686
/**** R E N D E R E R S ****/
3689
/*************************************************************************/
3690
/*************************************************************************/
3691
/*************************************************************************/
3693
/* lookup a renderer by glyph format in the library's list */
3694
FT_BASE_DEF( FT_Renderer )
3695
FT_Lookup_Renderer( FT_Library library,
3696
FT_Glyph_Format format,
3700
FT_Renderer result = 0;
3706
cur = library->renderers.head;
3711
cur = (*node)->next;
3717
FT_Renderer renderer = FT_RENDERER( cur->data );
3720
if ( renderer->glyph_format == format )
3737
ft_lookup_glyph_renderer( FT_GlyphSlot slot )
3739
FT_Face face = slot->face;
3740
FT_Library library = FT_FACE_LIBRARY( face );
3741
FT_Renderer result = library->cur_renderer;
3744
if ( !result || result->glyph_format != slot->format )
3745
result = FT_Lookup_Renderer( library, slot->format, 0 );
3752
ft_set_current_renderer( FT_Library library )
3754
FT_Renderer renderer;
3757
renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 );
3758
library->cur_renderer = renderer;
3763
ft_add_renderer( FT_Module module )
3765
FT_Library library = module->library;
3766
FT_Memory memory = library->memory;
3768
FT_ListNode node = NULL;
3771
if ( FT_NEW( node ) )
3775
FT_Renderer render = FT_RENDERER( module );
3776
FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz;
3779
render->clazz = clazz;
3780
render->glyph_format = clazz->glyph_format;
3782
/* allocate raster object if needed */
3783
if ( clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
3784
clazz->raster_class->raster_new )
3786
error = clazz->raster_class->raster_new( memory, &render->raster );
3790
render->raster_render = clazz->raster_class->raster_render;
3791
render->render = clazz->render_glyph;
3795
node->data = module;
3796
FT_List_Add( &library->renderers, node );
3798
ft_set_current_renderer( library );
3811
ft_remove_renderer( FT_Module module )
3813
FT_Library library = module->library;
3814
FT_Memory memory = library->memory;
3818
node = FT_List_Find( &library->renderers, module );
3821
FT_Renderer render = FT_RENDERER( module );
3824
/* release raster object, if any */
3825
if ( render->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
3827
render->clazz->raster_class->raster_done( render->raster );
3829
/* remove from list */
3830
FT_List_Remove( &library->renderers, node );
3833
ft_set_current_renderer( library );
3838
/* documentation is in ftrender.h */
3840
FT_EXPORT_DEF( FT_Renderer )
3841
FT_Get_Renderer( FT_Library library,
3842
FT_Glyph_Format format )
3844
/* test for valid `library' delayed to FT_Lookup_Renderer() */
3846
return FT_Lookup_Renderer( library, format, 0 );
3850
/* documentation is in ftrender.h */
3852
FT_EXPORT_DEF( FT_Error )
3853
FT_Set_Renderer( FT_Library library,
3854
FT_Renderer renderer,
3856
FT_Parameter* parameters )
3859
FT_Error error = FT_Err_Ok;
3863
return FT_Err_Invalid_Library_Handle;
3866
return FT_Err_Invalid_Argument;
3868
node = FT_List_Find( &library->renderers, renderer );
3871
error = FT_Err_Invalid_Argument;
3875
FT_List_Up( &library->renderers, node );
3877
if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
3878
library->cur_renderer = renderer;
3880
if ( num_params > 0 )
3882
FT_Renderer_SetModeFunc set_mode = renderer->clazz->set_mode;
3885
for ( ; num_params > 0; num_params-- )
3887
error = set_mode( renderer, parameters->tag, parameters->data );
3898
FT_BASE_DEF( FT_Error )
3899
FT_Render_Glyph_Internal( FT_Library library,
3901
FT_Render_Mode render_mode )
3903
FT_Error error = FT_Err_Ok;
3904
FT_Renderer renderer;
3907
/* if it is already a bitmap, no need to do anything */
3908
switch ( slot->format )
3910
case FT_GLYPH_FORMAT_BITMAP: /* already a bitmap, don't do anything */
3915
FT_ListNode node = 0;
3919
/* small shortcut for the very common case */
3920
if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
3922
renderer = library->cur_renderer;
3923
node = library->renderers.head;
3926
renderer = FT_Lookup_Renderer( library, slot->format, &node );
3928
error = FT_Err_Unimplemented_Feature;
3931
error = renderer->render( renderer, slot, render_mode, NULL );
3933
FT_ERROR_BASE( error ) != FT_Err_Cannot_Render_Glyph )
3936
/* FT_Err_Cannot_Render_Glyph is returned if the render mode */
3937
/* is unsupported by the current renderer for this glyph image */
3940
/* now, look for another renderer that supports the same */
3942
renderer = FT_Lookup_Renderer( library, slot->format, &node );
3946
/* if we changed the current renderer for the glyph image format */
3947
/* we need to select it as the next current one */
3948
if ( !error && update && renderer )
3949
FT_Set_Renderer( library, renderer, 0, 0 );
3957
/* documentation is in freetype.h */
3959
FT_EXPORT_DEF( FT_Error )
3960
FT_Render_Glyph( FT_GlyphSlot slot,
3961
FT_Render_Mode render_mode )
3966
if ( !slot || !slot->face )
3967
return FT_Err_Invalid_Argument;
3969
library = FT_FACE_LIBRARY( slot->face );
3971
return FT_Render_Glyph_Internal( library, slot, render_mode );
3975
/*************************************************************************/
3976
/*************************************************************************/
3977
/*************************************************************************/
3980
/**** M O D U L E S ****/
3983
/*************************************************************************/
3984
/*************************************************************************/
3985
/*************************************************************************/
3988
/*************************************************************************/
3991
/* Destroy_Module */
3994
/* Destroys a given module object. For drivers, this also destroys */
3995
/* all child faces. */
3998
/* module :: A handle to the target driver object. */
4001
/* The driver _must_ be LOCKED! */
4004
Destroy_Module( FT_Module module )
4006
FT_Memory memory = module->memory;
4007
FT_Module_Class* clazz = module->clazz;
4008
FT_Library library = module->library;
4011
/* finalize client-data - before anything else */
4012
if ( module->generic.finalizer )
4013
module->generic.finalizer( module );
4015
if ( library && library->auto_hinter == module )
4016
library->auto_hinter = 0;
4018
/* if the module is a renderer */
4019
if ( FT_MODULE_IS_RENDERER( module ) )
4020
ft_remove_renderer( module );
4022
/* if the module is a font driver, add some steps */
4023
if ( FT_MODULE_IS_DRIVER( module ) )
4024
Destroy_Driver( FT_DRIVER( module ) );
4026
/* finalize the module object */
4027
if ( clazz->module_done )
4028
clazz->module_done( module );
4035
/* documentation is in ftmodapi.h */
4037
FT_EXPORT_DEF( FT_Error )
4038
FT_Add_Module( FT_Library library,
4039
const FT_Module_Class* clazz )
4047
#define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \
4051
return FT_Err_Invalid_Library_Handle;
4054
return FT_Err_Invalid_Argument;
4056
/* check freetype version */
4057
if ( clazz->module_requires > FREETYPE_VER_FIXED )
4058
return FT_Err_Invalid_Version;
4060
/* look for a module with the same name in the library's table */
4061
for ( nn = 0; nn < library->num_modules; nn++ )
4063
module = library->modules[nn];
4064
if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 )
4066
/* this installed module has the same name, compare their versions */
4067
if ( clazz->module_version <= module->clazz->module_version )
4068
return FT_Err_Lower_Module_Version;
4070
/* remove the module from our list, then exit the loop to replace */
4071
/* it by our new version.. */
4072
FT_Remove_Module( library, module );
4077
memory = library->memory;
4080
if ( library->num_modules >= FT_MAX_MODULES )
4082
error = FT_Err_Too_Many_Drivers;
4086
/* allocate module object */
4087
if ( FT_ALLOC( module, clazz->module_size ) )
4090
/* base initialization */
4091
module->library = library;
4092
module->memory = memory;
4093
module->clazz = (FT_Module_Class*)clazz;
4095
/* check whether the module is a renderer - this must be performed */
4096
/* before the normal module initialization */
4097
if ( FT_MODULE_IS_RENDERER( module ) )
4099
/* add to the renderers list */
4100
error = ft_add_renderer( module );
4105
/* is the module a auto-hinter? */
4106
if ( FT_MODULE_IS_HINTER( module ) )
4107
library->auto_hinter = module;
4109
/* if the module is a font driver */
4110
if ( FT_MODULE_IS_DRIVER( module ) )
4112
/* allocate glyph loader if needed */
4113
FT_Driver driver = FT_DRIVER( module );
4116
driver->clazz = (FT_Driver_Class)module->clazz;
4117
if ( FT_DRIVER_USES_OUTLINES( driver ) )
4119
error = FT_GlyphLoader_New( memory, &driver->glyph_loader );
4125
if ( clazz->module_init )
4127
error = clazz->module_init( module );
4132
/* add module to the library's table */
4133
library->modules[library->num_modules++] = module;
4139
if ( FT_MODULE_IS_DRIVER( module ) )
4141
FT_Driver driver = FT_DRIVER( module );
4144
if ( FT_DRIVER_USES_OUTLINES( driver ) )
4145
FT_GlyphLoader_Done( driver->glyph_loader );
4148
if ( FT_MODULE_IS_RENDERER( module ) )
4150
FT_Renderer renderer = FT_RENDERER( module );
4153
if ( renderer->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
4155
renderer->clazz->raster_class->raster_done( renderer->raster );
4163
/* documentation is in ftmodapi.h */
4165
FT_EXPORT_DEF( FT_Module )
4166
FT_Get_Module( FT_Library library,
4167
const char* module_name )
4169
FT_Module result = 0;
4174
if ( !library || !module_name )
4177
cur = library->modules;
4178
limit = cur + library->num_modules;
4180
for ( ; cur < limit; cur++ )
4181
if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 )
4191
/* documentation is in ftobjs.h */
4193
FT_BASE_DEF( const void* )
4194
FT_Get_Module_Interface( FT_Library library,
4195
const char* mod_name )
4200
/* test for valid `library' delayed to FT_Get_Module() */
4202
module = FT_Get_Module( library, mod_name );
4204
return module ? module->clazz->module_interface : 0;
4208
FT_BASE_DEF( FT_Pointer )
4209
ft_module_get_service( FT_Module module,
4210
const char* service_id )
4212
FT_Pointer result = NULL;
4216
FT_ASSERT( module->clazz && module->clazz->get_interface );
4218
/* first, look for the service in the module
4220
if ( module->clazz->get_interface )
4221
result = module->clazz->get_interface( module, service_id );
4223
if ( result == NULL )
4225
/* we didn't find it, look in all other modules then
4227
FT_Library library = module->library;
4228
FT_Module* cur = library->modules;
4229
FT_Module* limit = cur + library->num_modules;
4231
for ( ; cur < limit; cur++ )
4233
if ( cur[0] != module )
4235
FT_ASSERT( cur[0]->clazz );
4237
if ( cur[0]->clazz->get_interface )
4239
result = cur[0]->clazz->get_interface( cur[0], service_id );
4240
if ( result != NULL )
4252
/* documentation is in ftmodapi.h */
4254
FT_EXPORT_DEF( FT_Error )
4255
FT_Remove_Module( FT_Library library,
4258
/* try to find the module from the table, then remove it from there */
4261
return FT_Err_Invalid_Library_Handle;
4265
FT_Module* cur = library->modules;
4266
FT_Module* limit = cur + library->num_modules;
4269
for ( ; cur < limit; cur++ )
4271
if ( cur[0] == module )
4273
/* remove it from the table */
4274
library->num_modules--;
4276
while ( cur < limit )
4283
/* destroy the module */
4284
Destroy_Module( module );
4290
return FT_Err_Invalid_Driver_Handle;
4294
/*************************************************************************/
4295
/*************************************************************************/
4296
/*************************************************************************/
4299
/**** L I B R A R Y ****/
4302
/*************************************************************************/
4303
/*************************************************************************/
4304
/*************************************************************************/
4307
/* documentation is in ftmodapi.h */
4309
FT_EXPORT_DEF( FT_Error )
4310
FT_Reference_Library( FT_Library library )
4312
library->refcount++;
4318
/* documentation is in ftmodapi.h */
4320
FT_EXPORT_DEF( FT_Error )
4321
FT_New_Library( FT_Memory memory,
4322
FT_Library *alibrary )
4324
FT_Library library = NULL;
4329
return FT_Err_Invalid_Argument;
4331
#ifdef FT_DEBUG_LEVEL_ERROR
4332
/* init debugging support */
4336
/* first of all, allocate the library object */
4337
if ( FT_NEW( library ) )
4340
library->memory = memory;
4342
#ifdef FT_CONFIG_OPTION_PIC
4343
/* initialize position independent code containers */
4344
error = ft_pic_container_init( library );
4349
/* allocate the render pool */
4350
library->raster_pool_size = FT_RENDER_POOL_SIZE;
4351
#if FT_RENDER_POOL_SIZE > 0
4352
if ( FT_ALLOC( library->raster_pool, FT_RENDER_POOL_SIZE ) )
4356
library->version_major = FREETYPE_MAJOR;
4357
library->version_minor = FREETYPE_MINOR;
4358
library->version_patch = FREETYPE_PATCH;
4360
library->refcount = 1;
4363
*alibrary = library;
4368
#ifdef FT_CONFIG_OPTION_PIC
4369
ft_pic_container_destroy( library );
4376
/* documentation is in freetype.h */
4378
FT_EXPORT_DEF( void )
4379
FT_Library_Version( FT_Library library,
4391
major = library->version_major;
4392
minor = library->version_minor;
4393
patch = library->version_patch;
4407
/* documentation is in ftmodapi.h */
4409
FT_EXPORT_DEF( FT_Error )
4410
FT_Done_Library( FT_Library library )
4416
return FT_Err_Invalid_Library_Handle;
4418
library->refcount--;
4419
if ( library->refcount > 0 )
4422
memory = library->memory;
4424
/* Discard client-data */
4425
if ( library->generic.finalizer )
4426
library->generic.finalizer( library );
4429
* Close all faces in the library. If we don't do this, we can have
4430
* some subtle memory leaks.
4434
* - the cff font driver uses the pshinter module in cff_size_done
4435
* - if the pshinter module is destroyed before the cff font driver,
4436
* opened FT_Face objects managed by the driver are not properly
4437
* destroyed, resulting in a memory leak
4439
* Some faces are dependent on other faces, like Type42 faces that
4440
* depend on TrueType faces synthesized internally.
4442
* The order of drivers should be specified in driver_name[].
4446
const char* driver_name[] = { "type42", NULL };
4450
m < sizeof ( driver_name ) / sizeof ( driver_name[0] );
4453
for ( n = 0; n < library->num_modules; n++ )
4455
FT_Module module = library->modules[n];
4456
const char* module_name = module->clazz->module_name;
4460
if ( driver_name[m] &&
4461
ft_strcmp( module_name, driver_name[m] ) != 0 )
4464
if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 )
4467
FT_TRACE7(( "FT_Done_Library: close faces for %s\n", module_name ));
4469
faces = &FT_DRIVER( module )->faces_list;
4470
while ( faces->head )
4472
FT_Done_Face( FT_FACE( faces->head->data ) );
4474
FT_TRACE0(( "FT_Done_Library: failed to free some faces\n" ));
4480
/* Close all other modules in the library */
4482
/* XXX Modules are removed in the reversed order so that */
4483
/* type42 module is removed before truetype module. This */
4484
/* avoids double free in some occasions. It is a hack. */
4485
while ( library->num_modules > 0 )
4486
FT_Remove_Module( library,
4487
library->modules[library->num_modules - 1] );
4493
for ( n = 0; n < library->num_modules; n++ )
4495
FT_Module module = library->modules[n];
4500
Destroy_Module( module );
4501
library->modules[n] = 0;
4507
/* Destroy raster objects */
4508
FT_FREE( library->raster_pool );
4509
library->raster_pool_size = 0;
4511
#ifdef FT_CONFIG_OPTION_PIC
4512
/* Destroy pic container contents */
4513
ft_pic_container_destroy( library );
4523
/* documentation is in ftmodapi.h */
4525
FT_EXPORT_DEF( void )
4526
FT_Set_Debug_Hook( FT_Library library,
4528
FT_DebugHook_Func debug_hook )
4530
if ( library && debug_hook &&
4532
( sizeof ( library->debug_hooks ) / sizeof ( void* ) ) )
4533
library->debug_hooks[hook_index] = debug_hook;
4537
/* documentation is in ftmodapi.h */
4539
FT_EXPORT_DEF( FT_TrueTypeEngineType )
4540
FT_Get_TrueType_Engine_Type( FT_Library library )
4542
FT_TrueTypeEngineType result = FT_TRUETYPE_ENGINE_TYPE_NONE;
4547
FT_Module module = FT_Get_Module( library, "truetype" );
4552
FT_Service_TrueTypeEngine service;
4555
service = (FT_Service_TrueTypeEngine)
4556
ft_module_get_service( module,
4557
FT_SERVICE_ID_TRUETYPE_ENGINE );
4559
result = service->engine_type;
4567
#ifdef FT_CONFIG_OPTION_OLD_INTERNALS
4569
FT_BASE_DEF( FT_Error )
4570
ft_stub_set_char_sizes( FT_Size size,
4576
FT_Size_RequestRec req;
4577
FT_Driver driver = size->face->driver;
4580
if ( driver->clazz->request_size )
4582
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
4584
req.height = height;
4586
if ( horz_res == 0 )
4587
horz_res = vert_res;
4589
if ( vert_res == 0 )
4590
vert_res = horz_res;
4592
if ( horz_res == 0 )
4593
horz_res = vert_res = 72;
4595
req.horiResolution = horz_res;
4596
req.vertResolution = vert_res;
4598
return driver->clazz->request_size( size, &req );
4605
FT_BASE_DEF( FT_Error )
4606
ft_stub_set_pixel_sizes( FT_Size size,
4610
FT_Size_RequestRec req;
4611
FT_Driver driver = size->face->driver;
4614
if ( driver->clazz->request_size )
4616
req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
4617
req.width = width << 6;
4618
req.height = height << 6;
4619
req.horiResolution = 0;
4620
req.vertResolution = 0;
4622
return driver->clazz->request_size( size, &req );
4628
#endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
4631
/* documentation is in freetype.h */
4633
FT_EXPORT_DEF( FT_Error )
4634
FT_Get_SubGlyph_Info( FT_GlyphSlot glyph,
4640
FT_Matrix *p_transform )
4642
FT_Error error = FT_Err_Invalid_Argument;
4647
glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
4648
sub_index < glyph->num_subglyphs )
4650
FT_SubGlyph subg = glyph->subglyphs + sub_index;
4653
*p_index = subg->index;
4654
*p_flags = subg->flags;
4655
*p_arg1 = subg->arg1;
4656
*p_arg2 = subg->arg2;
4657
*p_transform = subg->transform;