47#ifdef FT_CONFIG_OPTION_MAC_FONTS
52#ifdef FT_DEBUG_LEVEL_TRACE
56#if defined( _MSC_VER )
61#pragma warning( push )
62#pragma warning( disable : 4244 )
69#define MD5_u32plus FT_MD5_u32plus
70#define MD5_CTX FT_MD5_CTX
71#define MD5_Init FT_MD5_Init
72#define MD5_Update FT_MD5_Update
73#define MD5_Final FT_MD5_Final
79#if defined( _MSC_VER )
86 static const char*
const pixel_modes[] =
94 "vertical LCD 8-bit bitmap",
95 "BGRA 32-bit color image bitmap",
102#define GRID_FIT_METRICS
107 ft_open_face_internal( FT_Library library,
108 const FT_Open_Args* args,
111 FT_Bool test_mac_fonts );
114 FT_BASE_DEF( FT_Pointer )
115 ft_service_list_lookup( FT_ServiceDesc service_descriptors,
116 const char* service_id )
118 FT_Pointer result = NULL;
119 FT_ServiceDesc desc = service_descriptors;
122 if ( desc && service_id )
124 for ( ; desc->serv_id != NULL; desc++ )
126 if ( ft_strcmp( desc->serv_id, service_id ) == 0 )
128 result = (FT_Pointer)desc->serv_data;
139 ft_validator_init( FT_Validator valid,
141 const FT_Byte* limit,
142 FT_ValidationLevel level )
145 valid->limit = limit;
146 valid->level = level;
147 valid->error = FT_Err_Ok;
151 FT_BASE_DEF( FT_Int )
152 ft_validator_run( FT_Validator valid )
162 ft_validator_error( FT_Validator valid,
168 volatile ft_jmp_buf* jump_buffer = &valid->jump_buffer;
171 valid->error = error;
175 ft_longjmp( *(ft_jmp_buf*) jump_buffer, 1 );
194 FT_BASE_DEF( FT_Error )
195 FT_Stream_New( FT_Library library,
196 const FT_Open_Args* args,
201 FT_Stream stream = NULL;
208 return FT_THROW( Invalid_Library_Handle );
211 return FT_THROW( Invalid_Argument );
213 memory = library->memory;
215 ( FT_OPEN_MEMORY | FT_OPEN_STREAM | FT_OPEN_PATHNAME );
217 if ( mode == FT_OPEN_MEMORY )
220 if ( FT_NEW( stream ) )
223 FT_Stream_OpenMemory( stream,
224 (
const FT_Byte*)args->memory_base,
225 (FT_ULong)args->memory_size );
226 stream->memory = memory;
229#ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT
231 else if ( mode == FT_OPEN_PATHNAME )
234 if ( FT_NEW( stream ) )
237 stream->memory = memory;
238 error = FT_Stream_Open( stream, args->pathname );
242 else if ( ( mode == FT_OPEN_STREAM ) && args->stream )
248 stream = args->stream;
249 stream->memory = memory;
257 error = FT_THROW( Invalid_Argument );
258 if ( ( args->flags & FT_OPEN_STREAM ) && args->stream )
259 FT_Stream_Close( args->stream );
271 FT_Stream_Free( FT_Stream stream,
276 FT_Memory memory = stream->memory;
279 FT_Stream_Close( stream );
294#define FT_COMPONENT objs
311 ft_glyphslot_init( FT_GlyphSlot slot )
313 FT_Driver driver = slot->face->driver;
314 FT_Driver_Class clazz = driver->clazz;
315 FT_Memory memory = driver->root.memory;
316 FT_Error error = FT_Err_Ok;
317 FT_Slot_Internal internal = NULL;
320 slot->library = driver->root.library;
322 if ( FT_NEW( internal ) )
325 slot->internal = internal;
327 if ( FT_DRIVER_USES_OUTLINES( driver ) )
328 error = FT_GlyphLoader_New( memory, &internal->loader );
330 if ( !error && clazz->init_slot )
331 error = clazz->init_slot( slot );
333#ifdef FT_CONFIG_OPTION_SVG
335 if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
337 FT_SVG_Document document = NULL;
340 if ( FT_NEW( document ) )
342 slot->other = document;
352 ft_glyphslot_free_bitmap( FT_GlyphSlot slot )
354 if ( slot->internal && ( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) )
356 FT_Memory memory = FT_FACE_MEMORY( slot->face );
359 FT_FREE( slot->bitmap.buffer );
360 slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP;
366 slot->bitmap.buffer = NULL;
373 FT_BASE_DEF( FT_Bool )
374 ft_glyphslot_preset_bitmap( FT_GlyphSlot slot,
376 const FT_Vector* origin )
378 FT_Outline* outline = &slot->outline;
379 FT_Bitmap* bitmap = &slot->bitmap;
381 FT_Pixel_Mode pixel_mode;
386 FT_Pos x_left, y_top;
387 FT_Pos width, height, pitch;
390 if ( slot->format == FT_GLYPH_FORMAT_SVG )
393 SVG_Service svg_service;
396 module = FT_Get_Module( slot->library, "ot-svg" );
397 svg_service = (SVG_Service)module->clazz->module_interface;
399 return (FT_Bool)svg_service->preset_slot( module, slot, FALSE );
401 else if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
412 FT_Outline_Get_CBox( outline, &cbox );
415 pbox.xMin = ( cbox.xMin >> 6 ) + ( x_shift >> 6 );
416 pbox.yMin = ( cbox.yMin >> 6 ) + ( y_shift >> 6 );
417 pbox.xMax = ( cbox.xMax >> 6 ) + ( x_shift >> 6 );
418 pbox.yMax = ( cbox.yMax >> 6 ) + ( y_shift >> 6 );
421 cbox.xMin = ( cbox.xMin & 63 ) + ( x_shift & 63 );
422 cbox.yMin = ( cbox.yMin & 63 ) + ( y_shift & 63 );
423 cbox.xMax = ( cbox.xMax & 63 ) + ( x_shift & 63 );
424 cbox.yMax = ( cbox.yMax & 63 ) + ( y_shift & 63 );
428 case FT_RENDER_MODE_MONO:
429 pixel_mode = FT_PIXEL_MODE_MONO;
437 pbox.xMin += ( cbox.xMin + 31 ) >> 6;
438 pbox.xMax += ( cbox.xMax + 32 ) >> 6;
443 if ( pbox.xMin == pbox.xMax )
445 if ( ( ( cbox.xMin + 31 ) & 63 ) - 31 +
446 ( ( cbox.xMax + 32 ) & 63 ) - 32 < 0 )
454 pbox.yMin += ( cbox.yMin + 31 ) >> 6;
455 pbox.yMax += ( cbox.yMax + 32 ) >> 6;
457 if ( pbox.yMin == pbox.yMax )
459 if ( ( ( cbox.yMin + 31 ) & 63 ) - 31 +
460 ( ( cbox.yMax + 32 ) & 63 ) - 32 < 0 )
471 case FT_RENDER_MODE_LCD:
472 pixel_mode = FT_PIXEL_MODE_LCD;
473 ft_lcd_padding( &cbox, slot, mode );
476 case FT_RENDER_MODE_LCD_V:
477 pixel_mode = FT_PIXEL_MODE_LCD_V;
478 ft_lcd_padding( &cbox, slot, mode );
481 case FT_RENDER_MODE_NORMAL:
482 case FT_RENDER_MODE_LIGHT:
484 pixel_mode = FT_PIXEL_MODE_GRAY;
486 pbox.xMin += cbox.xMin >> 6;
487 pbox.yMin += cbox.yMin >> 6;
488 pbox.xMax += ( cbox.xMax + 63 ) >> 6;
489 pbox.yMax += ( cbox.yMax + 63 ) >> 6;
495 width = pbox.xMax - pbox.xMin;
496 height = pbox.yMax - pbox.yMin;
498 switch ( pixel_mode )
500 case FT_PIXEL_MODE_MONO:
501 pitch = ( ( width + 15 ) >> 4 ) << 1;
504 case FT_PIXEL_MODE_LCD:
506 pitch = FT_PAD_CEIL( width, 4 );
509 case FT_PIXEL_MODE_LCD_V:
513 case FT_PIXEL_MODE_GRAY:
518 slot->bitmap_left = (FT_Int)x_left;
519 slot->bitmap_top = (FT_Int)y_top;
521 bitmap->pixel_mode = (
unsigned char)pixel_mode;
522 bitmap->num_grays = 256;
523 bitmap->width = (
unsigned int)width;
524 bitmap->rows = (
unsigned int)height;
525 bitmap->pitch = pitch;
527 if ( pbox.xMin < -0x8000 || pbox.xMax > 0x7FFF ||
528 pbox.yMin < -0x8000 || pbox.yMax > 0x7FFF )
530 FT_TRACE3((
"ft_glyphslot_preset_bitmap: [%ld %ld %ld %ld]\n",
531 pbox.xMin, pbox.yMin, pbox.xMax, pbox.yMax ));
540 ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
543 ft_glyphslot_free_bitmap( slot );
545 slot->bitmap.buffer = buffer;
547 FT_ASSERT( (slot->internal->flags & FT_GLYPH_OWN_BITMAP) == 0 );
551 FT_BASE_DEF( FT_Error )
552 ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
555 FT_Memory memory = FT_FACE_MEMORY( slot->face );
559 if ( slot->internal->flags & FT_GLYPH_OWN_BITMAP )
560 FT_FREE( slot->bitmap.buffer );
562 slot->internal->flags |= FT_GLYPH_OWN_BITMAP;
564 FT_MEM_ALLOC( slot->bitmap.buffer, size );
570 ft_glyphslot_clear( FT_GlyphSlot slot )
573 ft_glyphslot_free_bitmap( slot );
576 slot->glyph_index = 0;
578 FT_ZERO( &slot->metrics );
579 FT_ZERO( &slot->outline );
581 slot->bitmap.width = 0;
582 slot->bitmap.rows = 0;
583 slot->bitmap.pitch = 0;
584 slot->bitmap.pixel_mode = 0;
587 slot->bitmap_left = 0;
588 slot->bitmap_top = 0;
589 slot->num_subglyphs = 0;
590 slot->subglyphs = NULL;
591 slot->control_data = NULL;
592 slot->control_len = 0;
594#ifndef FT_CONFIG_OPTION_SVG
597 if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) )
601 if ( slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
603 FT_Memory memory = slot->face->memory;
604 FT_SVG_Document doc = (FT_SVG_Document)slot->other;
607 FT_FREE( doc->svg_document );
608 slot->internal->flags &= ~FT_GLYPH_OWN_GZIP_SVG;
613 slot->format = FT_GLYPH_FORMAT_NONE;
615 slot->linearHoriAdvance = 0;
616 slot->linearVertAdvance = 0;
625 ft_glyphslot_done( FT_GlyphSlot slot )
627 FT_Driver driver = slot->face->driver;
628 FT_Driver_Class clazz = driver->clazz;
629 FT_Memory memory = driver->root.memory;
631#ifdef FT_CONFIG_OPTION_SVG
632 if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
636 if ( slot->internal && slot->internal->flags & FT_GLYPH_OWN_GZIP_SVG )
638 FT_SVG_Document doc = (FT_SVG_Document)slot->other;
641 FT_FREE( doc->svg_document );
643 slot->internal->flags &= ~FT_GLYPH_OWN_GZIP_SVG;
646 FT_FREE( slot->other );
650 if ( clazz->done_slot )
651 clazz->done_slot( slot );
654 ft_glyphslot_free_bitmap( slot );
657 if ( slot->internal )
660 if ( FT_DRIVER_USES_OUTLINES( driver ) )
662 FT_GlyphLoader_Done( slot->internal->loader );
663 slot->internal->loader = NULL;
666 FT_FREE( slot->internal );
673 FT_BASE_DEF( FT_Error )
674 FT_New_GlyphSlot( FT_Face face,
675 FT_GlyphSlot *aslot )
679 FT_Driver_Class clazz;
681 FT_GlyphSlot slot = NULL;
685 return FT_THROW( Invalid_Face_Handle );
688 return FT_THROW( Invalid_Argument );
690 driver = face->driver;
691 clazz = driver->clazz;
692 memory = driver->root.memory;
694 FT_TRACE4((
"FT_New_GlyphSlot: Creating new slot object\n" ));
695 if ( !FT_ALLOC( slot, clazz->slot_object_size ) )
699 error = ft_glyphslot_init( slot );
702 ft_glyphslot_done( slot );
707 slot->next = face->glyph;
718 FT_TRACE4((
"FT_New_GlyphSlot: Return 0x%x\n", error ));
727 FT_Done_GlyphSlot( FT_GlyphSlot slot )
731 FT_Driver driver = slot->face->driver;
732 FT_Memory memory = driver->root.memory;
739 cur = slot->face->glyph;
746 slot->face->glyph = cur->next;
748 prev->next = cur->next;
751 if ( slot->generic.finalizer )
752 slot->generic.finalizer( slot );
754 ft_glyphslot_done( slot );
767 FT_EXPORT_DEF(
void )
768 FT_Set_Transform( FT_Face face,
772 FT_Face_Internal internal;
778 internal = face->internal;
780 internal->transform_flags = 0;
784 internal->transform_matrix.xx = 0x10000L;
785 internal->transform_matrix.xy = 0;
786 internal->transform_matrix.yx = 0;
787 internal->transform_matrix.yy = 0x10000L;
789 matrix = &internal->transform_matrix;
792 internal->transform_matrix = *matrix;
795 if ( ( matrix->xy | matrix->yx ) ||
796 matrix->xx != 0x10000L ||
797 matrix->yy != 0x10000L )
798 internal->transform_flags |= 1;
802 internal->transform_delta.x = 0;
803 internal->transform_delta.y = 0;
805 delta = &internal->transform_delta;
808 internal->transform_delta = *delta;
811 if ( delta->x | delta->y )
812 internal->transform_flags |= 2;
818 FT_EXPORT_DEF(
void )
819 FT_Get_Transform( FT_Face face,
823 FT_Face_Internal internal;
829 internal = face->internal;
832 *matrix = internal->transform_matrix;
835 *delta = internal->transform_delta;
840 ft_lookup_glyph_renderer( FT_GlyphSlot slot );
843#ifdef GRID_FIT_METRICS
845 ft_glyphslot_grid_fit_metrics( FT_GlyphSlot slot,
848 FT_Glyph_Metrics* metrics = &slot->metrics;
849 FT_Pos right, bottom;
854 metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
855 metrics->horiBearingY = FT_PIX_CEIL_LONG( metrics->horiBearingY );
857 right = FT_PIX_CEIL_LONG( ADD_LONG( metrics->vertBearingX,
859 bottom = FT_PIX_CEIL_LONG( ADD_LONG( metrics->vertBearingY,
862 metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
863 metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
865 metrics->width = SUB_LONG( right,
866 metrics->vertBearingX );
867 metrics->height = SUB_LONG( bottom,
868 metrics->vertBearingY );
872 metrics->vertBearingX = FT_PIX_FLOOR( metrics->vertBearingX );
873 metrics->vertBearingY = FT_PIX_FLOOR( metrics->vertBearingY );
875 right = FT_PIX_CEIL_LONG( ADD_LONG( metrics->horiBearingX,
877 bottom = FT_PIX_FLOOR( SUB_LONG( metrics->horiBearingY,
880 metrics->horiBearingX = FT_PIX_FLOOR( metrics->horiBearingX );
881 metrics->horiBearingY = FT_PIX_CEIL_LONG( metrics->horiBearingY );
883 metrics->width = SUB_LONG( right,
884 metrics->horiBearingX );
885 metrics->height = SUB_LONG( metrics->horiBearingY,
889 metrics->horiAdvance = FT_PIX_ROUND_LONG( metrics->horiAdvance );
890 metrics->vertAdvance = FT_PIX_ROUND_LONG( metrics->vertAdvance );
897 FT_EXPORT_DEF( FT_Error )
898 FT_Load_Glyph( FT_Face face,
900 FT_Int32 load_flags )
906 FT_Bool autohint = FALSE;
910 if ( !face || !face->size || !face->glyph )
911 return FT_THROW( Invalid_Face_Handle );
917 ft_glyphslot_clear( slot );
919 driver = face->driver;
920 library = driver->root.library;
921 hinter = library->auto_hinter;
924 if ( face->size->metrics.x_ppem == 0 ||
925 face->size->metrics.y_ppem == 0 )
926 load_flags |= FT_LOAD_NO_SCALE;
930 if ( load_flags & FT_LOAD_NO_RECURSE )
931 load_flags |= FT_LOAD_NO_SCALE |
932 FT_LOAD_IGNORE_TRANSFORM;
934 if ( load_flags & FT_LOAD_NO_SCALE )
936 load_flags |= FT_LOAD_NO_HINTING |
939 load_flags &= ~FT_LOAD_RENDER;
942 if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
943 load_flags &= ~FT_LOAD_RENDER;
968 !( load_flags & FT_LOAD_NO_HINTING ) &&
969 !( load_flags & FT_LOAD_NO_AUTOHINT ) &&
970 FT_IS_SCALABLE( face ) &&
971 !FT_IS_TRICKY( face ) &&
972 ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) ||
973 ( face->internal->transform_matrix.yx == 0 &&
974 face->internal->transform_matrix.xx != 0 ) ||
975 ( face->internal->transform_matrix.xx == 0 &&
976 face->internal->transform_matrix.yx != 0 ) ) )
978 if ( ( load_flags & FT_LOAD_FORCE_AUTOHINT ) ||
979 !FT_DRIVER_HAS_HINTER( driver ) )
983 FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
984 FT_Bool is_light_type1;
985 TT_Face ttface = (TT_Face)face;
991 ft_strstr( FT_Get_Font_Format( face ),
"Type 1" ) != NULL &&
992 ((PS_Driver)driver)->hinting_engine == FT_HINTING_ADOBE;
1000 if ( ( mode == FT_RENDER_MODE_LIGHT &&
1001 ( !FT_DRIVER_HINTS_LIGHTLY( driver ) &&
1002 !is_light_type1 ) ) ||
1003 ( FT_IS_SFNT( face ) &&
1004 ttface->num_locations &&
1005 ttface->font_program_size == 0 &&
1006 ttface->cvt_program_size <= 7 ) )
1013 FT_AutoHinter_Interface hinting;
1020 if ( ( load_flags & FT_LOAD_NO_SVG ) == 0 &&
1021 FT_HAS_SVG( face ) )
1023 error = driver->clazz->load_glyph( slot, face->size,
1025 load_flags | FT_LOAD_SVG_ONLY );
1027 if ( !error && slot->format == FT_GLYPH_FORMAT_SVG )
1032 if ( FT_HAS_FIXED_SIZES( face ) &&
1033 ( load_flags & FT_LOAD_NO_BITMAP ) == 0 )
1035 error = driver->clazz->load_glyph( slot, face->size,
1037 load_flags | FT_LOAD_SBITS_ONLY );
1039 if ( !error && slot->format == FT_GLYPH_FORMAT_BITMAP )
1044 FT_Face_Internal internal = face->internal;
1045 FT_Int transform_flags = internal->transform_flags;
1050 internal->transform_flags = 0;
1053 hinting = (FT_AutoHinter_Interface)hinter->clazz->module_interface;
1055 error = hinting->load_glyph( (FT_AutoHinter)hinter,
1057 glyph_index, load_flags );
1059 internal->transform_flags = transform_flags;
1064 error = driver->clazz->load_glyph( slot,
1071 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
1074 error = FT_Outline_Check( &slot->outline );
1078#ifdef GRID_FIT_METRICS
1079 if ( !( load_flags & FT_LOAD_NO_HINTING ) )
1080 ft_glyphslot_grid_fit_metrics(
1082 FT_BOOL( load_flags & FT_LOAD_VERTICAL_LAYOUT ) );
1089 if ( load_flags & FT_LOAD_VERTICAL_LAYOUT )
1091 slot->advance.x = 0;
1092 slot->advance.y = slot->metrics.vertAdvance;
1096 slot->advance.x = slot->metrics.horiAdvance;
1097 slot->advance.y = 0;
1101 if ( ( load_flags & FT_LOAD_LINEAR_DESIGN ) == 0 &&
1102 FT_IS_SCALABLE( face ) )
1104 FT_Size_Metrics* metrics = &face->size->metrics;
1108 slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
1109 metrics->x_scale, 64 );
1111 slot->linearVertAdvance = FT_MulDiv( slot->linearVertAdvance,
1112 metrics->y_scale, 64 );
1115 if ( ( load_flags & FT_LOAD_IGNORE_TRANSFORM ) == 0 )
1117 FT_Face_Internal internal = face->internal;
1121 if ( internal->transform_flags )
1124 FT_Renderer renderer = ft_lookup_glyph_renderer( slot );
1128 error = renderer->clazz->transform_glyph(
1130 &internal->transform_matrix,
1131 &internal->transform_delta );
1132 else if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
1135 if ( internal->transform_flags & 1 )
1136 FT_Outline_Transform( &slot->outline,
1137 &internal->transform_matrix );
1139 if ( internal->transform_flags & 2 )
1140 FT_Outline_Translate( &slot->outline,
1141 internal->transform_delta.x,
1142 internal->transform_delta.y );
1146 FT_Vector_Transform( &slot->advance, &internal->transform_matrix );
1150 slot->glyph_index = glyph_index;
1151 slot->internal->load_flags = load_flags;
1155 ( load_flags & FT_LOAD_NO_SCALE ) == 0 &&
1156 slot->format != FT_GLYPH_FORMAT_BITMAP &&
1157 slot->format != FT_GLYPH_FORMAT_COMPOSITE )
1159 FT_Render_Mode mode = FT_LOAD_TARGET_MODE( load_flags );
1162 if ( mode == FT_RENDER_MODE_NORMAL &&
1163 load_flags & FT_LOAD_MONOCHROME )
1164 mode = FT_RENDER_MODE_MONO;
1166 if ( load_flags & FT_LOAD_RENDER )
1167 error = FT_Render_Glyph( slot, mode );
1169 ft_glyphslot_preset_bitmap( slot, mode, NULL );
1172#ifdef FT_DEBUG_LEVEL_TRACE
1173 FT_TRACE5((
"FT_Load_Glyph: index %u, flags 0x%x\n",
1174 glyph_index, load_flags ));
1175 FT_TRACE5((
" bitmap %ux%u %s, %s (mode %d)\n",
1178 slot->outline.points ?
1179 slot->bitmap.buffer ?
"rendered"
1182 slot->internal->flags & FT_GLYPH_OWN_BITMAP ?
"owned"
1184 pixel_modes[slot->bitmap.pixel_mode],
1185 slot->bitmap.pixel_mode ));
1186 FT_TRACE5((
"\n" ));
1187 FT_TRACE5((
" x advance: %f\n", (
double)slot->advance.x / 64 ));
1188 FT_TRACE5((
" y advance: %f\n", (
double)slot->advance.y / 64 ));
1189 FT_TRACE5((
" linear x advance: %f\n",
1190 (
double)slot->linearHoriAdvance / 65536 ));
1191 FT_TRACE5((
" linear y advance: %f\n",
1192 (
double)slot->linearVertAdvance / 65536 ));
1195 FT_Glyph_Metrics* metrics = &slot->metrics;
1198 FT_TRACE5((
" metrics:\n" ));
1199 FT_TRACE5((
" width: %f\n", (
double)metrics->width / 64 ));
1200 FT_TRACE5((
" height: %f\n", (
double)metrics->height / 64 ));
1201 FT_TRACE5((
"\n" ));
1202 FT_TRACE5((
" horiBearingX: %f\n",
1203 (
double)metrics->horiBearingX / 64 ));
1204 FT_TRACE5((
" horiBearingY: %f\n",
1205 (
double)metrics->horiBearingY / 64 ));
1206 FT_TRACE5((
" horiAdvance: %f\n",
1207 (
double)metrics->horiAdvance / 64 ));
1208 FT_TRACE5((
"\n" ));
1209 FT_TRACE5((
" vertBearingX: %f\n",
1210 (
double)metrics->vertBearingX / 64 ));
1211 FT_TRACE5((
" vertBearingY: %f\n",
1212 (
double)metrics->vertBearingY / 64 ));
1213 FT_TRACE5((
" vertAdvance: %f\n",
1214 (
double)metrics->vertAdvance / 64 ));
1225 FT_EXPORT_DEF( FT_Error )
1226 FT_Load_Char( FT_Face face,
1228 FT_Int32 load_flags )
1230 FT_UInt glyph_index;
1234 return FT_THROW( Invalid_Face_Handle );
1236 glyph_index = (FT_UInt)char_code;
1237 if ( face->charmap )
1238 glyph_index = FT_Get_Char_Index( face, char_code );
1240 return FT_Load_Glyph( face, glyph_index, load_flags );
1246 destroy_size( FT_Memory memory,
1250 FT_Size size = (FT_Size)size_;
1251 FT_Driver driver = (FT_Driver)driver_;
1255 if ( driver->clazz->done_size )
1256 driver->clazz->done_size( size );
1259 if ( size->generic.finalizer )
1260 size->generic.finalizer( size );
1262 FT_FREE( size->internal );
1268 ft_cmap_done_internal( FT_CMap cmap );
1272 destroy_charmaps( FT_Face face,
1281 for ( n = 0; n < face->num_charmaps; n++ )
1283 FT_CMap cmap = FT_CMAP( face->charmaps[n] );
1286 ft_cmap_done_internal( cmap );
1288 face->charmaps[n] = NULL;
1291 FT_FREE( face->charmaps );
1292 face->num_charmaps = 0;
1298 destroy_face( FT_Memory memory,
1302 FT_Face face = (FT_Face)face_;
1303 FT_Driver driver = (FT_Driver)driver_;
1304 FT_Driver_Class clazz = driver->clazz;
1308 if ( face->autohint.finalizer )
1309 face->autohint.finalizer( face->autohint.data );
1313 while ( face->glyph )
1314 FT_Done_GlyphSlot( face->glyph );
1317 FT_List_Finalize( &face->sizes_list,
1324 destroy_charmaps( face, memory );
1327 if ( clazz->done_face )
1328 clazz->done_face( face );
1333 ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0 );
1335 face->stream = NULL;
1338 if ( face->generic.finalizer )
1339 face->generic.finalizer( face );
1342 if ( face->internal )
1344 FT_FREE( face->internal );
1351 Destroy_Driver( FT_Driver driver )
1353 FT_List_Finalize( &driver->faces_list,
1355 driver->root.memory,
1362 FT_BASE_DEF( FT_Error )
1363 find_unicode_charmap( FT_Face face )
1372 first = face->charmaps;
1375 return FT_THROW( Invalid_CharMap_Handle );
1405 cur = first + face->num_charmaps;
1407 for ( ; --cur >= first; )
1409 if ( cur[0]->encoding == FT_ENCODING_UNICODE )
1413 if ( ( cur[0]->platform_id == TT_PLATFORM_MICROSOFT &&
1414 cur[0]->encoding_id == TT_MS_ID_UCS_4 ) ||
1415 ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
1416 cur[0]->encoding_id == TT_APPLE_ID_UNICODE_32 ) )
1418 face->charmap = cur[0];
1426 cur = first + face->num_charmaps;
1428 for ( ; --cur >= first; )
1430 if ( cur[0]->encoding == FT_ENCODING_UNICODE )
1432 face->charmap = cur[0];
1437 return FT_THROW( Invalid_CharMap_Handle );
1451 find_variant_selector_charmap( FT_Face face )
1461 first = face->charmaps;
1466 end = first + face->num_charmaps;
1468 for ( cur = first; cur < end; cur++ )
1470 if ( cur[0]->platform_id == TT_PLATFORM_APPLE_UNICODE &&
1471 cur[0]->encoding_id == TT_APPLE_ID_VARIANT_SELECTOR &&
1472 FT_Get_CMap_Format( cur[0] ) == 14 )
1489 open_face( FT_Driver driver,
1491 FT_Bool *anexternal_stream,
1494 FT_Parameter* params,
1498 FT_Driver_Class clazz;
1499 FT_Face face = NULL;
1500 FT_Face_Internal internal = NULL;
1502 FT_Error error, error2;
1505 clazz = driver->clazz;
1506 memory = driver->root.memory;
1509 if ( FT_ALLOC( face, clazz->face_object_size ) )
1512 face->driver = driver;
1513 face->memory = memory;
1514 face->stream = *astream;
1517 if ( *anexternal_stream )
1518 face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM;
1520 if ( FT_NEW( internal ) )
1523 face->internal = internal;
1525#ifdef FT_CONFIG_OPTION_INCREMENTAL
1530 face->internal->incremental_interface = NULL;
1531 for ( i = 0; i < num_params && !face->internal->incremental_interface;
1533 if ( params[i].tag == FT_PARAM_TAG_INCREMENTAL )
1534 face->internal->incremental_interface =
1535 (FT_Incremental_Interface)params[i].data;
1539 face->internal->random_seed = -1;
1541 if ( clazz->init_face )
1542 error = clazz->init_face( *astream,
1548 *astream = face->stream;
1549 *anexternal_stream =
1550 ( face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) != 0;
1555 error2 = find_unicode_charmap( face );
1561 if ( error2 && FT_ERR_NEQ( error2, Invalid_CharMap_Handle ) )
1572 destroy_charmaps( face, memory );
1573 if ( clazz->done_face )
1574 clazz->done_face( face );
1575 FT_FREE( internal );
1591 FT_EXPORT_DEF( FT_Error )
1592 FT_New_Face( FT_Library library,
1593 const char* pathname,
1602 return FT_THROW( Invalid_Argument );
1604 args.flags = FT_OPEN_PATHNAME;
1605 args.pathname = (
char*)pathname;
1608 return ft_open_face_internal( library, &args, face_index, aface, 1 );
1616 FT_EXPORT_DEF( FT_Error )
1617 FT_New_Memory_Face( FT_Library library,
1618 const FT_Byte* file_base,
1628 return FT_THROW( Invalid_Argument );
1630 args.flags = FT_OPEN_MEMORY;
1631 args.memory_base = file_base;
1632 args.memory_size = file_size;
1635 return ft_open_face_internal( library, &args, face_index, aface, 1 );
1639#ifdef FT_CONFIG_OPTION_MAC_FONTS
1672 memory_stream_close( FT_Stream stream )
1674 FT_Memory memory = (FT_Memory)stream->descriptor.pointer;
1677 FT_FREE( stream->base );
1679 stream->close = NULL;
1687 new_memory_stream( FT_Library library,
1690 FT_Stream_CloseFunc close,
1691 FT_Stream *astream )
1695 FT_Stream stream = NULL;
1699 return FT_THROW( Invalid_Library_Handle );
1702 return FT_THROW( Invalid_Argument );
1705 memory = library->memory;
1706 if ( FT_NEW( stream ) )
1709 FT_Stream_OpenMemory( stream, base, size );
1711 stream->descriptor.pointer = memory;
1712 stream->close = close;
1723 FT_LOCAL_DEF( FT_Error )
1724 open_face_from_buffer( FT_Library library,
1728 const char* driver_name,
1733 FT_Memory memory = library->memory;
1741 args.driver = FT_Get_Module( library, driver_name );
1745 return FT_THROW( Missing_Module );
1748 args.flags = args.flags | FT_OPEN_DRIVER;
1752 error = new_memory_stream( library,
1755 memory_stream_close,
1763 args.flags |= FT_OPEN_STREAM;
1771 if ( face_index > 0 )
1772 face_index &= 0x7FFF0000L;
1775 return ft_open_face_internal( library, &args, face_index, aface, 0 );
1789 ft_lookup_PS_in_sfnt_stream( FT_Stream stream,
1793 FT_Bool* is_sfnt_cid )
1796 FT_UShort numTables;
1797 FT_Long pstable_index;
1804 *is_sfnt_cid = FALSE;
1809 if ( FT_READ_ULONG( tag ) )
1811 if ( tag != TTAG_typ1 )
1812 return FT_THROW( Unknown_File_Format );
1814 if ( FT_READ_USHORT( numTables ) )
1816 if ( FT_STREAM_SKIP( 2 * 3 ) )
1820 *is_sfnt_cid = FALSE;
1822 for ( i = 0; i < numTables; i++ )
1824 if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) ||
1825 FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
1828 if ( tag == TTAG_CID )
1833 *is_sfnt_cid = TRUE;
1834 if ( face_index < 0 )
1837 else if ( tag == TTAG_TYP1 )
1842 *is_sfnt_cid = FALSE;
1843 if ( face_index < 0 )
1846 if ( face_index >= 0 && pstable_index == face_index )
1850 return FT_THROW( Table_Missing );
1854 FT_LOCAL_DEF( FT_Error )
1855 open_face_PS_from_sfnt_stream( FT_Library library,
1859 FT_Parameter *params,
1863 FT_Memory memory = library->memory;
1864 FT_ULong offset, length;
1866 FT_Bool is_sfnt_cid;
1867 FT_Byte* sfnt_ps = NULL;
1869 FT_UNUSED( num_params );
1870 FT_UNUSED( params );
1874 if ( face_index > 0 )
1875 face_index &= 0xFFFFL;
1877 pos = FT_STREAM_POS();
1879 error = ft_lookup_PS_in_sfnt_stream( stream,
1887 if ( offset > stream->size )
1889 FT_TRACE2((
"open_face_PS_from_sfnt_stream: invalid table offset\n" ));
1890 error = FT_THROW( Invalid_Table );
1893 else if ( length > stream->size - offset )
1895 FT_TRACE2((
"open_face_PS_from_sfnt_stream: invalid table length\n" ));
1896 error = FT_THROW( Invalid_Table );
1900 error = FT_Stream_Seek( stream, pos + offset );
1904 if ( FT_QALLOC( sfnt_ps, (FT_Long)length ) )
1907 error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
1914 error = open_face_from_buffer( library,
1917 FT_MIN( face_index, 0 ),
1918 is_sfnt_cid ?
"t1cid" :
"type1",
1925 if ( FT_ERR_EQ( error, Unknown_File_Format ) )
1927 error1 = FT_Stream_Seek( stream, pos );
1946 Mac_Read_POST_Resource( FT_Library library,
1949 FT_Long resource_cnt,
1953 FT_Error error = FT_ERR( Cannot_Open_Resource );
1954 FT_Memory memory = library->memory;
1956 FT_Byte* pfb_data = NULL;
1959 FT_ULong pfb_len, pfb_pos, pfb_lenpos;
1960 FT_ULong rlen, temp;
1963 if ( face_index == -1 )
1965 if ( face_index != 0 )
1971 for ( i = 0; i < resource_cnt; i++ )
1973 error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
1976 if ( FT_READ_ULONG( temp ) )
1982 FT_TRACE4((
" POST fragment #%d: length=0x%08lx"
1983 " total pfb_len=0x%08lx\n",
1984 i, temp, pfb_len + temp + 6 ));
1986 if ( FT_MAC_RFORK_MAX_LEN < temp ||
1987 FT_MAC_RFORK_MAX_LEN - temp < pfb_len + 6 )
1989 FT_TRACE2((
" MacOS resource length cannot exceed"
1991 FT_MAC_RFORK_MAX_LEN ));
1993 error = FT_THROW( Invalid_Offset );
1997 pfb_len += temp + 6;
2000 FT_TRACE2((
" total buffer size to concatenate"
2001 " %ld POST fragments: 0x%08lx\n",
2002 resource_cnt, pfb_len + 2 ));
2004 if ( pfb_len + 2 < 6 )
2006 FT_TRACE2((
" too long fragment length makes"
2007 " pfb_len confused: pfb_len=0x%08lx\n",
2010 error = FT_THROW( Array_Too_Large );
2014 if ( FT_QALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
2029 for ( i = 0; i < resource_cnt; i++ )
2031 error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
2034 if ( FT_READ_ULONG( rlen ) )
2040 if ( 0x7FFFFFFFUL < rlen )
2042 error = FT_THROW( Invalid_Offset );
2046 if ( FT_READ_USHORT( flags ) )
2049 FT_TRACE3((
"POST fragment[%d]:"
2050 " offsets=0x%08lx, rlen=0x%08lx, flags=0x%04x\n",
2051 i, offsets[i], rlen, flags ));
2053 error = FT_ERR( Array_Too_Large );
2058 if ( ( flags >> 8 ) == 0 )
2060 FT_TRACE3((
" Skip POST fragment #%d because it is a comment\n",
2072 if ( ( flags >> 8 ) == type )
2076 FT_TRACE3((
" Write POST fragment #%d header (4-byte) to buffer"
2078 i, (
void*)pfb_data, pfb_lenpos ));
2080 if ( pfb_lenpos + 3 > pfb_len + 2 )
2083 pfb_data[pfb_lenpos ] = (FT_Byte)( len );
2084 pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
2085 pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
2086 pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
2088 if ( ( flags >> 8 ) == 5 )
2091 FT_TRACE3((
" Write POST fragment #%d header (6-byte) to buffer"
2093 i, (
void*)pfb_data, pfb_pos ));
2095 if ( pfb_pos + 6 > pfb_len + 2 )
2098 pfb_data[pfb_pos++] = 0x80;
2103 pfb_data[pfb_pos++] = (FT_Byte)type;
2104 pfb_lenpos = pfb_pos;
2105 pfb_data[pfb_pos++] = 0;
2106 pfb_data[pfb_pos++] = 0;
2107 pfb_data[pfb_pos++] = 0;
2108 pfb_data[pfb_pos++] = 0;
2111 if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
2114 FT_TRACE3((
" Load POST fragment #%d (%lu byte) to buffer"
2116 i, rlen, (
void*)pfb_data, pfb_pos ));
2118 error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
2125 error = FT_ERR( Array_Too_Large );
2127 if ( pfb_pos + 2 > pfb_len + 2 )
2129 pfb_data[pfb_pos++] = 0x80;
2130 pfb_data[pfb_pos++] = 3;
2132 if ( pfb_lenpos + 3 > pfb_len + 2 )
2134 pfb_data[pfb_lenpos ] = (FT_Byte)( len );
2135 pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
2136 pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
2137 pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
2139 return open_face_from_buffer( library,
2147 if ( FT_ERR_EQ( error, Array_Too_Large ) )
2148 FT_TRACE2((
" Abort due to too-short buffer to store"
2149 " all POST fragments\n" ));
2150 else if ( FT_ERR_EQ( error, Invalid_Offset ) )
2151 FT_TRACE2((
" Abort due to invalid offset in a POST fragment\n" ));
2154 error = FT_ERR( Cannot_Open_Resource );
2155 FT_FREE( pfb_data );
2168 Mac_Read_sfnt_Resource( FT_Library library,
2171 FT_Long resource_cnt,
2175 FT_Memory memory = library->memory;
2176 FT_Byte* sfnt_data = NULL;
2178 FT_ULong flag_offset;
2181 FT_Long face_index_in_resource = 0;
2184 if ( face_index < 0 )
2185 face_index = -face_index - 1;
2186 if ( face_index >= resource_cnt )
2187 return FT_THROW( Cannot_Open_Resource );
2189 flag_offset = (FT_ULong)offsets[face_index];
2190 error = FT_Stream_Seek( stream, flag_offset );
2194 if ( FT_READ_ULONG( rlen ) )
2197 return FT_THROW( Cannot_Open_Resource );
2198 if ( rlen > FT_MAC_RFORK_MAX_LEN )
2199 return FT_THROW( Invalid_Offset );
2201 error = open_face_PS_from_sfnt_stream( library,
2210 error = FT_Stream_Seek( stream, flag_offset + 4 );
2214 if ( FT_QALLOC( sfnt_data, rlen ) )
2216 error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen );
2219 FT_FREE( sfnt_data );
2223 is_cff = rlen > 4 && !ft_memcmp( sfnt_data,
"OTTO", 4 );
2224 error = open_face_from_buffer( library,
2227 face_index_in_resource,
2228 is_cff ?
"cff" :
"truetype",
2242 IsMacResource( FT_Library library,
2244 FT_Long resource_offset,
2248 FT_Memory memory = library->memory;
2250 FT_Long map_offset, rdata_pos;
2251 FT_Long *data_offsets;
2255 error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
2256 &map_offset, &rdata_pos );
2261 error = FT_Raccess_Get_DataOffsets( library, stream,
2262 map_offset, rdata_pos,
2264 &data_offsets, &count );
2267 error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
2268 face_index, aface );
2269 FT_FREE( data_offsets );
2272 (*aface)->num_faces = 1;
2278 error = FT_Raccess_Get_DataOffsets( library, stream,
2279 map_offset, rdata_pos,
2281 &data_offsets, &count );
2284 FT_Long face_index_internal = face_index % count;
2287 error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
2288 face_index_internal, aface );
2289 FT_FREE( data_offsets );
2292 (*aface)->num_faces = count;
2293 (*aface)->face_index = face_index_internal;
2305 IsMacBinary( FT_Library library,
2310 unsigned char header[128];
2312 FT_Long dlen, offset;
2316 return FT_THROW( Invalid_Stream_Operation );
2318 error = FT_Stream_Seek( stream, 0 );
2322 error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
2326 if ( header[ 0] != 0 ||
2332 header[2 + header[1]] != 0 ||
2333 header[0x53] > 0x7F )
2334 return FT_THROW( Unknown_File_Format );
2336 dlen = ( header[0x53] << 24 ) |
2337 ( header[0x54] << 16 ) |
2338 ( header[0x55] << 8 ) |
2341 rlen = ( header[0x57] << 24 ) |
2342 ( header[0x58] << 16 ) |
2343 ( header[0x59] << 8 ) |
2346 offset = 128 + ( ( dlen + 127 ) & ~127 );
2348 return IsMacResource( library, stream, offset, face_index, aface );
2356 load_face_in_embedded_rfork( FT_Library library,
2360 const FT_Open_Args *args )
2364#define FT_COMPONENT raccess
2366 FT_Memory memory = library->memory;
2367 FT_Error error = FT_ERR( Unknown_File_Format );
2370 char* file_names[FT_RACCESS_N_RULES];
2371 FT_Long offsets[FT_RACCESS_N_RULES];
2372 FT_Error errors[FT_RACCESS_N_RULES];
2373 FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE;
2376 FT_Stream stream2 = NULL;
2379 FT_Raccess_Guess( library, stream,
2380 args->pathname, file_names, offsets, errors );
2382 for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
2384 is_darwin_vfs = ft_raccess_rule_by_darwin_vfs( library, i );
2385 if ( is_darwin_vfs && vfs_rfork_has_no_font )
2387 FT_TRACE3((
"Skip rule %u: darwin vfs resource fork"
2388 " is already checked and"
2389 " no font is found\n",
2396 FT_TRACE3((
"Error 0x%x has occurred in rule %u\n",
2401 args2.flags = FT_OPEN_PATHNAME;
2402 args2.pathname = file_names[i] ? file_names[i] : args->pathname;
2404 FT_TRACE3((
"Try rule %u: %s (offset=%ld) ...",
2405 i, args2.pathname, offsets[i] ));
2407 error = FT_Stream_New( library, &args2, &stream2 );
2408 if ( is_darwin_vfs && FT_ERR_EQ( error, Cannot_Open_Stream ) )
2409 vfs_rfork_has_no_font = TRUE;
2413 FT_TRACE3((
"failed\n" ));
2417 error = IsMacResource( library, stream2, offsets[i],
2418 face_index, aface );
2419 FT_Stream_Free( stream2, 0 );
2421 FT_TRACE3((
"%s\n", error ?
"failed":
"successful" ));
2425 else if ( is_darwin_vfs )
2426 vfs_rfork_has_no_font = TRUE;
2429 for (i = 0; i < FT_RACCESS_N_RULES; i++)
2431 if ( file_names[i] )
2432 FT_FREE( file_names[i] );
2437 error = FT_ERR( Unknown_File_Format );
2442#define FT_COMPONENT objs
2455 load_mac_face( FT_Library library,
2459 const FT_Open_Args *args )
2465 error = IsMacBinary( library, stream, face_index, aface );
2466 if ( FT_ERR_EQ( error, Unknown_File_Format ) )
2470#define FT_COMPONENT raccess
2472#ifdef FT_DEBUG_LEVEL_TRACE
2473 FT_TRACE3((
"Try as dfont: " ));
2474 if ( !( args->flags & FT_OPEN_MEMORY ) )
2475 FT_TRACE3((
"%s ...", args->pathname ));
2478 error = IsMacResource( library, stream, 0, face_index, aface );
2480 FT_TRACE3((
"%s\n", error ?
"failed" :
"successful" ));
2483#define FT_COMPONENT objs
2487 if ( ( FT_ERR_EQ( error, Unknown_File_Format ) ||
2488 FT_ERR_EQ( error, Invalid_Stream_Operation ) ) &&
2489 ( args->flags & FT_OPEN_PATHNAME ) )
2490 error = load_face_in_embedded_rfork( library, stream,
2491 face_index, aface, args );
2501 FT_EXPORT_DEF( FT_Error )
2502 FT_Open_Face( FT_Library library,
2503 const FT_Open_Args* args,
2507 return ft_open_face_internal( library, args, face_index, aface, 1 );
2512 ft_open_face_internal( FT_Library library,
2513 const FT_Open_Args* args,
2516 FT_Bool test_mac_fonts )
2519 FT_Driver driver = NULL;
2520 FT_Memory memory = NULL;
2521 FT_Stream stream = NULL;
2522 FT_Face face = NULL;
2523 FT_ListNode node = NULL;
2524 FT_Bool external_stream;
2528#ifndef FT_CONFIG_OPTION_MAC_FONTS
2529 FT_UNUSED( test_mac_fonts );
2534 if ( face_index > 0 )
2535 face_index &= 0x7FFFFFFFL;
2538 face_index = -face_index;
2539 face_index &= 0x7FFFFFFFL;
2540 face_index = -face_index;
2543#ifdef FT_DEBUG_LEVEL_TRACE
2544 FT_TRACE3((
"FT_Open_Face: " ));
2545 if ( face_index < 0 )
2546 FT_TRACE3((
"Requesting number of faces and named instances\n"));
2549 FT_TRACE3((
"Requesting face %ld", face_index & 0xFFFFL ));
2550 if ( face_index & 0x7FFF0000L )
2551 FT_TRACE3((
", named instance %ld", face_index >> 16 ));
2552 FT_TRACE3((
"\n" ));
2559 return FT_THROW( Invalid_Argument );
2561 external_stream = FT_BOOL( ( args->flags & FT_OPEN_STREAM ) &&
2565 error = FT_Stream_New( library, args, &stream );
2571 if ( !aface && face_index >= 0 )
2573 error = FT_THROW( Invalid_Argument );
2577 memory = library->memory;
2581 if ( ( args->flags & FT_OPEN_DRIVER ) && args->driver )
2583 driver = FT_DRIVER( args->driver );
2586 if ( FT_MODULE_IS_DRIVER( driver ) )
2588 FT_Int num_params = 0;
2589 FT_Parameter* params = NULL;
2592 if ( args->flags & FT_OPEN_PARAMS )
2594 num_params = args->num_params;
2595 params = args->params;
2598 error = open_face( driver, &stream, &external_stream, face_index,
2599 num_params, params, &face );
2604 error = FT_THROW( Invalid_Handle );
2606 FT_Stream_Free( stream, external_stream );
2611 error = FT_ERR( Missing_Module );
2614 cur = library->modules;
2615 limit = cur + library->num_modules;
2617 for ( ; cur < limit; cur++ )
2620 if ( FT_MODULE_IS_DRIVER( cur[0] ) )
2622 FT_Int num_params = 0;
2623 FT_Parameter* params = NULL;
2626 driver = FT_DRIVER( cur[0] );
2628 if ( args->flags & FT_OPEN_PARAMS )
2630 num_params = args->num_params;
2631 params = args->params;
2634 error = open_face( driver, &stream, &external_stream, face_index,
2635 num_params, params, &face );
2639#ifdef FT_CONFIG_OPTION_MAC_FONTS
2640 if ( test_mac_fonts &&
2641 ft_strcmp( cur[0]->clazz->module_name,
"truetype" ) == 0 &&
2642 FT_ERR_EQ( error, Table_Missing ) )
2645 error = FT_Stream_Seek( stream, 0 );
2649 error = open_face_PS_from_sfnt_stream( library,
2657 FT_Stream_Free( stream, external_stream );
2663 if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
2672 if ( FT_ERR_NEQ( error, Cannot_Open_Stream ) &&
2673 FT_ERR_NEQ( error, Unknown_File_Format ) &&
2674 FT_ERR_NEQ( error, Invalid_Stream_Operation ) )
2677#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
2678 if ( test_mac_fonts )
2680 error = load_mac_face( library, stream, face_index, aface, args );
2689 FT_Stream_Free( stream, external_stream );
2694 if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
2699 error = FT_THROW( Unknown_File_Format );
2702 FT_Stream_Free( stream, external_stream );
2707 FT_TRACE4((
"FT_Open_Face: New face object, adding to list\n" ));
2710 if ( FT_QNEW( node ) )
2716 FT_List_Add( &face->driver->faces_list, node );
2719 FT_TRACE4((
"FT_Open_Face: Creating glyph slot\n" ));
2721 if ( face_index >= 0 )
2723 error = FT_New_GlyphSlot( face, NULL );
2732 FT_TRACE4((
"FT_Open_Face: Creating size object\n" ));
2734 error = FT_New_Size( face, &size );
2744 if ( FT_IS_SCALABLE( face ) )
2746 if ( face->height < 0 )
2747 face->height = (FT_Short)-face->height;
2749 if ( !FT_HAS_VERTICAL( face ) )
2750 face->max_advance_height = (FT_Short)face->height;
2753 if ( FT_HAS_FIXED_SIZES( face ) )
2758 for ( i = 0; i < face->num_fixed_sizes; i++ )
2760 FT_Bitmap_Size* bsize = face->available_sizes + i;
2763 if ( bsize->height < 0 )
2764 bsize->height = -bsize->height;
2765 if ( bsize->x_ppem < 0 )
2766 bsize->x_ppem = -bsize->x_ppem;
2767 if ( bsize->y_ppem < 0 )
2768 bsize->y_ppem = -bsize->y_ppem;
2771 if ( bsize->height < 0 || bsize->x_ppem < 0 || bsize->y_ppem < 0 )
2773 FT_TRACE0((
"FT_Open_Face:"
2774 " Invalid bitmap dimensions for strike %d,"
2775 " now disabled\n", i ));
2787 FT_Face_Internal internal = face->internal;
2790 internal->transform_matrix.xx = 0x10000L;
2791 internal->transform_matrix.xy = 0;
2792 internal->transform_matrix.yx = 0;
2793 internal->transform_matrix.yy = 0x10000L;
2795 internal->transform_delta.x = 0;
2796 internal->transform_delta.y = 0;
2798 internal->refcount = 1;
2800 internal->no_stem_darkening = -1;
2802#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
2804 internal->lcd_filter_func = NULL;
2811 FT_Done_Face( face );
2817 FT_Done_Face( face );
2819 destroy_face( memory, face, driver );
2822#ifdef FT_DEBUG_LEVEL_TRACE
2823 if ( !error && face_index < 0 )
2825 FT_TRACE3((
"FT_Open_Face: The font has %ld face%s\n",
2827 face->num_faces == 1 ?
"" :
"s" ));
2828 FT_TRACE3((
" and %ld named instance%s for face %ld\n",
2829 face->style_flags >> 16,
2830 ( face->style_flags >> 16 ) == 1 ?
"" :
"s",
2835 FT_TRACE4((
"FT_Open_Face: Return 0x%x\n", error ));
2843 FT_EXPORT_DEF( FT_Error )
2844 FT_Attach_File( FT_Face face,
2845 const char* filepathname )
2852 if ( !filepathname )
2853 return FT_THROW( Invalid_Argument );
2856 open.flags = FT_OPEN_PATHNAME;
2857 open.pathname = (
char*)filepathname;
2859 return FT_Attach_Stream( face, &open );
2865 FT_EXPORT_DEF( FT_Error )
2866 FT_Attach_Stream( FT_Face face,
2873 FT_Driver_Class clazz;
2879 return FT_THROW( Invalid_Face_Handle );
2881 driver = face->driver;
2883 return FT_THROW( Invalid_Driver_Handle );
2885 error = FT_Stream_New( driver->root.library,
parameters, &stream );
2892 error = FT_ERR( Unimplemented_Feature );
2893 clazz = driver->clazz;
2894 if ( clazz->attach_file )
2895 error = clazz->attach_file( face, stream );
2898 FT_Stream_Free( stream,
2909 FT_EXPORT_DEF( FT_Error )
2910 FT_Reference_Face( FT_Face face )
2913 return FT_THROW( Invalid_Face_Handle );
2915 face->internal->refcount++;
2923 FT_EXPORT_DEF( FT_Error )
2924 FT_Done_Face( FT_Face face )
2932 error = FT_ERR( Invalid_Face_Handle );
2933 if ( face && face->driver )
2935 face->internal->refcount--;
2936 if ( face->internal->refcount > 0 )
2940 driver = face->driver;
2941 memory = driver->root.memory;
2944 node = FT_List_Find( &driver->faces_list, face );
2948 FT_List_Remove( &driver->faces_list, node );
2952 destroy_face( memory, face, driver );
2964 FT_EXPORT_DEF( FT_Error )
2965 FT_New_Size( FT_Face face,
2971 FT_Driver_Class clazz;
2973 FT_Size size = NULL;
2974 FT_ListNode node = NULL;
2976 FT_Size_Internal internal = NULL;
2980 return FT_THROW( Invalid_Face_Handle );
2983 return FT_THROW( Invalid_Argument );
2985 if ( !face->driver )
2986 return FT_THROW( Invalid_Driver_Handle );
2990 driver = face->driver;
2991 clazz = driver->clazz;
2992 memory = face->memory;
2995 if ( FT_ALLOC( size, clazz->size_object_size ) || FT_QNEW( node ) )
3000 if ( FT_NEW( internal ) )
3003 size->internal = internal;
3005 if ( clazz->init_size )
3006 error = clazz->init_size( size );
3013 FT_List_Add( &face->sizes_list, node );
3021 FT_FREE( size->internal );
3031 FT_EXPORT_DEF( FT_Error )
3032 FT_Done_Size( FT_Size size )
3042 return FT_THROW( Invalid_Size_Handle );
3046 return FT_THROW( Invalid_Face_Handle );
3048 driver = face->driver;
3050 return FT_THROW( Invalid_Driver_Handle );
3052 memory = driver->root.memory;
3055 node = FT_List_Find( &face->sizes_list, size );
3058 FT_List_Remove( &face->sizes_list, node );
3061 if ( face->size == size )
3064 if ( face->sizes_list.head )
3065 face->size = (FT_Size)(face->sizes_list.head->data);
3068 destroy_size( memory, size, driver );
3071 error = FT_THROW( Invalid_Size_Handle );
3079 FT_BASE_DEF( FT_Error )
3080 FT_Match_Size( FT_Face face,
3081 FT_Size_Request req,
3082 FT_Bool ignore_width,
3083 FT_ULong* size_index )
3089 if ( !FT_HAS_FIXED_SIZES( face ) )
3090 return FT_THROW( Invalid_Face_Handle );
3093 if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
3094 return FT_THROW( Unimplemented_Feature );
3096 w = FT_REQUEST_WIDTH ( req );
3097 h = FT_REQUEST_HEIGHT( req );
3099 if ( req->width && !req->height )
3101 else if ( !req->width && req->height )
3104 w = FT_PIX_ROUND( w );
3105 h = FT_PIX_ROUND( h );
3108 return FT_THROW( Invalid_Pixel_Size );
3110 for ( i = 0; i < face->num_fixed_sizes; i++ )
3112 FT_Bitmap_Size* bsize = face->available_sizes + i;
3115 if ( h != FT_PIX_ROUND( bsize->y_ppem ) )
3118 if ( w == FT_PIX_ROUND( bsize->x_ppem ) || ignore_width )
3120 FT_TRACE3((
"FT_Match_Size: bitmap strike %d matches\n", i ));
3123 *size_index = (FT_ULong)i;
3129 FT_TRACE3((
"FT_Match_Size: no matching bitmap strike\n" ));
3131 return FT_THROW( Invalid_Pixel_Size );
3138 ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics,
3141 FT_Pos height = metrics->height;
3145 if ( metrics->horiBearingY < 0 )
3147 if ( height < metrics->horiBearingY )
3148 height = metrics->horiBearingY;
3150 else if ( metrics->horiBearingY > 0 )
3151 height -= metrics->horiBearingY;
3155 advance = height * 12 / 10;
3157 metrics->vertBearingX = metrics->horiBearingX - metrics->horiAdvance / 2;
3158 metrics->vertBearingY = ( advance - height ) / 2;
3159 metrics->vertAdvance = advance;
3164 ft_recompute_scaled_metrics( FT_Face face,
3165 FT_Size_Metrics* metrics )
3169#ifdef GRID_FIT_METRICS
3170 metrics->ascender = FT_PIX_CEIL( FT_MulFix( face->ascender,
3171 metrics->y_scale ) );
3173 metrics->descender = FT_PIX_FLOOR( FT_MulFix( face->descender,
3174 metrics->y_scale ) );
3176 metrics->height = FT_PIX_ROUND( FT_MulFix( face->height,
3177 metrics->y_scale ) );
3179 metrics->max_advance = FT_PIX_ROUND( FT_MulFix( face->max_advance_width,
3180 metrics->x_scale ) );
3182 metrics->ascender = FT_MulFix( face->ascender,
3185 metrics->descender = FT_MulFix( face->descender,
3188 metrics->height = FT_MulFix( face->height,
3191 metrics->max_advance = FT_MulFix( face->max_advance_width,
3198 FT_Select_Metrics( FT_Face face,
3199 FT_ULong strike_index )
3201 FT_Size_Metrics* metrics;
3202 FT_Bitmap_Size* bsize;
3205 metrics = &face->size->metrics;
3206 bsize = face->available_sizes + strike_index;
3208 metrics->x_ppem = (FT_UShort)( ( bsize->x_ppem + 32 ) >> 6 );
3209 metrics->y_ppem = (FT_UShort)( ( bsize->y_ppem + 32 ) >> 6 );
3211 if ( FT_IS_SCALABLE( face ) )
3213 metrics->x_scale = FT_DivFix( bsize->x_ppem,
3214 face->units_per_EM );
3215 metrics->y_scale = FT_DivFix( bsize->y_ppem,
3216 face->units_per_EM );
3218 ft_recompute_scaled_metrics( face, metrics );
3222 metrics->x_scale = 1L << 16;
3223 metrics->y_scale = 1L << 16;
3224 metrics->ascender = bsize->y_ppem;
3225 metrics->descender = 0;
3226 metrics->height = bsize->height << 6;
3227 metrics->max_advance = bsize->x_ppem;
3232 FT_BASE_DEF( FT_Error )
3233 FT_Request_Metrics( FT_Face face,
3234 FT_Size_Request req )
3236 FT_Error error = FT_Err_Ok;
3238 FT_Size_Metrics* metrics;
3241 metrics = &face->size->metrics;
3243 if ( FT_IS_SCALABLE( face ) )
3245 FT_Long w = 0, h = 0, scaled_w = 0, scaled_h = 0;
3248 switch ( req->type )
3250 case FT_SIZE_REQUEST_TYPE_NOMINAL:
3251 w = h = face->units_per_EM;
3254 case FT_SIZE_REQUEST_TYPE_REAL_DIM:
3255 w = h = face->ascender - face->descender;
3258 case FT_SIZE_REQUEST_TYPE_BBOX:
3259 w = face->bbox.xMax - face->bbox.xMin;
3260 h = face->bbox.yMax - face->bbox.yMin;
3263 case FT_SIZE_REQUEST_TYPE_CELL:
3264 w = face->max_advance_width;
3265 h = face->ascender - face->descender;
3268 case FT_SIZE_REQUEST_TYPE_SCALES:
3269 metrics->x_scale = (FT_Fixed)req->width;
3270 metrics->y_scale = (FT_Fixed)req->height;
3271 if ( !metrics->x_scale )
3272 metrics->x_scale = metrics->y_scale;
3273 else if ( !metrics->y_scale )
3274 metrics->y_scale = metrics->x_scale;
3275 goto Calculate_Ppem;
3277 case FT_SIZE_REQUEST_TYPE_MAX:
3288 scaled_w = FT_REQUEST_WIDTH ( req );
3289 scaled_h = FT_REQUEST_HEIGHT( req );
3292 if ( req->height || !req->width )
3296 FT_ERROR((
"FT_Request_Metrics: Divide by zero\n" ));
3297 error = FT_ERR( Divide_By_Zero );
3301 metrics->y_scale = FT_DivFix( scaled_h, h );
3308 FT_ERROR((
"FT_Request_Metrics: Divide by zero\n" ));
3309 error = FT_ERR( Divide_By_Zero );
3313 metrics->x_scale = FT_DivFix( scaled_w, w );
3317 metrics->x_scale = metrics->y_scale;
3318 scaled_w = FT_MulDiv( scaled_h, w, h );
3323 metrics->y_scale = metrics->x_scale;
3324 scaled_h = FT_MulDiv( scaled_w, h, w );
3327 if ( req->type == FT_SIZE_REQUEST_TYPE_CELL )
3329 if ( metrics->y_scale > metrics->x_scale )
3330 metrics->y_scale = metrics->x_scale;
3332 metrics->x_scale = metrics->y_scale;
3337 if ( req->type != FT_SIZE_REQUEST_TYPE_NOMINAL )
3339 scaled_w = FT_MulFix( face->units_per_EM, metrics->x_scale );
3340 scaled_h = FT_MulFix( face->units_per_EM, metrics->y_scale );
3343 scaled_w = ( scaled_w + 32 ) >> 6;
3344 scaled_h = ( scaled_h + 32 ) >> 6;
3345 if ( scaled_w > (FT_Long)FT_USHORT_MAX ||
3346 scaled_h > (FT_Long)FT_USHORT_MAX )
3348 FT_ERROR((
"FT_Request_Metrics: Resulting ppem size too large\n" ));
3349 error = FT_ERR( Invalid_Pixel_Size );
3353 metrics->x_ppem = (FT_UShort)scaled_w;
3354 metrics->y_ppem = (FT_UShort)scaled_h;
3356 ft_recompute_scaled_metrics( face, metrics );
3361 metrics->x_scale = 1L << 16;
3362 metrics->y_scale = 1L << 16;
3372 FT_EXPORT_DEF( FT_Error )
3373 FT_Select_Size( FT_Face face,
3374 FT_Int strike_index )
3376 FT_Error error = FT_Err_Ok;
3377 FT_Driver_Class clazz;
3380 if ( !face || !FT_HAS_FIXED_SIZES( face ) )
3381 return FT_THROW( Invalid_Face_Handle );
3383 if ( strike_index < 0 || strike_index >= face->num_fixed_sizes )
3384 return FT_THROW( Invalid_Argument );
3386 clazz = face->driver->clazz;
3388 if ( clazz->select_size )
3390 error = clazz->select_size( face->size, (FT_ULong)strike_index );
3392 FT_TRACE5((
"FT_Select_Size (%s driver):\n",
3393 face->driver->root.clazz->module_name ));
3397 FT_Select_Metrics( face, (FT_ULong)strike_index );
3399 FT_TRACE5((
"FT_Select_Size:\n" ));
3402#ifdef FT_DEBUG_LEVEL_TRACE
3404 FT_Size_Metrics* metrics = &face->size->metrics;
3407 FT_TRACE5((
" x scale: %ld (%f)\n",
3408 metrics->x_scale, (
double)metrics->x_scale / 65536 ));
3409 FT_TRACE5((
" y scale: %ld (%f)\n",
3410 metrics->y_scale, (
double)metrics->y_scale / 65536 ));
3411 FT_TRACE5((
" ascender: %f\n",
3412 (
double)metrics->ascender / 64 ));
3413 FT_TRACE5((
" descender: %f\n",
3414 (
double)metrics->descender / 64 ));
3415 FT_TRACE5((
" height: %f\n",
3416 (
double)metrics->height / 64 ));
3417 FT_TRACE5((
" max advance: %f\n",
3418 (
double)metrics->max_advance / 64 ));
3419 FT_TRACE5((
" x ppem: %d\n", metrics->x_ppem ));
3420 FT_TRACE5((
" y ppem: %d\n", metrics->y_ppem ));
3430 FT_EXPORT_DEF( FT_Error )
3431 FT_Request_Size( FT_Face face,
3432 FT_Size_Request req )
3435 FT_Driver_Class clazz;
3436 FT_ULong strike_index;
3440 return FT_THROW( Invalid_Face_Handle );
3443 return FT_THROW( Invalid_Size_Handle );
3445 if ( !req || req->width < 0 || req->height < 0 ||
3446 req->type >= FT_SIZE_REQUEST_TYPE_MAX )
3447 return FT_THROW( Invalid_Argument );
3451 face->size->internal->autohint_metrics.x_scale = 0;
3453 clazz = face->driver->clazz;
3455 if ( clazz->request_size )
3457 error = clazz->request_size( face->size, req );
3459 FT_TRACE5((
"FT_Request_Size (%s driver):\n",
3460 face->driver->root.clazz->module_name ));
3462 else if ( !FT_IS_SCALABLE( face ) && FT_HAS_FIXED_SIZES( face ) )
3471 error = FT_Match_Size( face, req, 0, &strike_index );
3475 return FT_Select_Size( face, (FT_Int)strike_index );
3479 error = FT_Request_Metrics( face, req );
3483 FT_TRACE5((
"FT_Request_Size:\n" ));
3486#ifdef FT_DEBUG_LEVEL_TRACE
3488 FT_Size_Metrics* metrics = &face->size->metrics;
3491 FT_TRACE5((
" x scale: %ld (%f)\n",
3492 metrics->x_scale, (
double)metrics->x_scale / 65536 ));
3493 FT_TRACE5((
" y scale: %ld (%f)\n",
3494 metrics->y_scale, (
double)metrics->y_scale / 65536 ));
3495 FT_TRACE5((
" ascender: %f\n",
3496 (
double)metrics->ascender / 64 ));
3497 FT_TRACE5((
" descender: %f\n",
3498 (
double)metrics->descender / 64 ));
3499 FT_TRACE5((
" height: %f\n",
3500 (
double)metrics->height / 64 ));
3501 FT_TRACE5((
" max advance: %f\n",
3502 (
double)metrics->max_advance / 64 ));
3503 FT_TRACE5((
" x ppem: %d\n", metrics->x_ppem ));
3504 FT_TRACE5((
" y ppem: %d\n", metrics->y_ppem ));
3515 FT_EXPORT_DEF( FT_Error )
3516 FT_Set_Char_Size( FT_Face face,
3517 FT_F26Dot6 char_width,
3518 FT_F26Dot6 char_height,
3519 FT_UInt horz_resolution,
3520 FT_UInt vert_resolution )
3522 FT_Size_RequestRec req;
3528 char_width = char_height;
3529 else if ( !char_height )
3530 char_height = char_width;
3532 if ( !horz_resolution )
3533 horz_resolution = vert_resolution;
3534 else if ( !vert_resolution )
3535 vert_resolution = horz_resolution;
3537 if ( char_width < 1 * 64 )
3538 char_width = 1 * 64;
3539 if ( char_height < 1 * 64 )
3540 char_height = 1 * 64;
3542 if ( !horz_resolution )
3543 horz_resolution = vert_resolution = 72;
3545 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
3546 req.width = char_width;
3547 req.height = char_height;
3548 req.horiResolution = horz_resolution;
3549 req.vertResolution = vert_resolution;
3551 return FT_Request_Size( face, &req );
3557 FT_EXPORT_DEF( FT_Error )
3558 FT_Set_Pixel_Sizes( FT_Face face,
3559 FT_UInt pixel_width,
3560 FT_UInt pixel_height )
3562 FT_Size_RequestRec req;
3567 if ( pixel_width == 0 )
3568 pixel_width = pixel_height;
3569 else if ( pixel_height == 0 )
3570 pixel_height = pixel_width;
3572 if ( pixel_width < 1 )
3574 if ( pixel_height < 1 )
3578 if ( pixel_width >= 0xFFFFU )
3579 pixel_width = 0xFFFFU;
3580 if ( pixel_height >= 0xFFFFU )
3581 pixel_height = 0xFFFFU;
3583 req.type = FT_SIZE_REQUEST_TYPE_NOMINAL;
3584 req.width = (FT_Long)( pixel_width << 6 );
3585 req.height = (FT_Long)( pixel_height << 6 );
3586 req.horiResolution = 0;
3587 req.vertResolution = 0;
3589 return FT_Request_Size( face, &req );
3595 FT_EXPORT_DEF( FT_Error )
3596 FT_Get_Kerning( FT_Face face,
3598 FT_UInt right_glyph,
3600 FT_Vector *akerning )
3602 FT_Error error = FT_Err_Ok;
3607 return FT_THROW( Invalid_Face_Handle );
3610 return FT_THROW( Invalid_Argument );
3612 driver = face->driver;
3617 if ( driver->clazz->get_kerning )
3619 error = driver->clazz->get_kerning( face,
3625 if ( kern_mode != FT_KERNING_UNSCALED )
3627 akerning->x = FT_MulFix( akerning->x, face->size->metrics.x_scale );
3628 akerning->y = FT_MulFix( akerning->y, face->size->metrics.y_scale );
3630 if ( kern_mode != FT_KERNING_UNFITTED )
3632 FT_Pos orig_x = akerning->x;
3633 FT_Pos orig_y = akerning->y;
3639 if ( face->size->metrics.x_ppem < 25 )
3640 akerning->x = FT_MulDiv( orig_x,
3641 face->size->metrics.x_ppem, 25 );
3642 if ( face->size->metrics.y_ppem < 25 )
3643 akerning->y = FT_MulDiv( orig_y,
3644 face->size->metrics.y_ppem, 25 );
3646 akerning->x = FT_PIX_ROUND( akerning->x );
3647 akerning->y = FT_PIX_ROUND( akerning->y );
3649#ifdef FT_DEBUG_LEVEL_TRACE
3651 FT_Pos orig_x_rounded = FT_PIX_ROUND( orig_x );
3652 FT_Pos orig_y_rounded = FT_PIX_ROUND( orig_y );
3655 if ( akerning->x != orig_x_rounded ||
3656 akerning->y != orig_y_rounded )
3657 FT_TRACE5((
"FT_Get_Kerning: horizontal kerning"
3658 " (%ld, %ld) scaled down to (%ld, %ld) pixels\n",
3659 orig_x_rounded / 64, orig_y_rounded / 64,
3660 akerning->x / 64, akerning->y / 64 ));
3674 FT_EXPORT_DEF( FT_Error )
3675 FT_Get_Track_Kerning( FT_Face face,
3676 FT_Fixed point_size,
3678 FT_Fixed* akerning )
3680 FT_Service_Kerning service;
3681 FT_Error error = FT_Err_Ok;
3685 return FT_THROW( Invalid_Face_Handle );
3688 return FT_THROW( Invalid_Argument );
3690 FT_FACE_FIND_SERVICE( face, service, KERNING );
3692 return FT_THROW( Unimplemented_Feature );
3694 error = service->get_track( face,
3705 FT_EXPORT_DEF( FT_Error )
3706 FT_Select_Charmap( FT_Face face,
3707 FT_Encoding encoding )
3714 return FT_THROW( Invalid_Face_Handle );
3717 if ( encoding == FT_ENCODING_NONE && !face->num_charmaps )
3718 return FT_THROW( Invalid_Argument );
3724 if ( encoding == FT_ENCODING_UNICODE )
3725 return find_unicode_charmap( face );
3727 cur = face->charmaps;
3729 return FT_THROW( Invalid_CharMap_Handle );
3731 limit = cur + face->num_charmaps;
3733 for ( ; cur < limit; cur++ )
3735 if ( cur[0]->encoding == encoding )
3737 face->charmap = cur[0];
3742 return FT_THROW( Invalid_Argument );
3748 FT_EXPORT_DEF( FT_Error )
3749 FT_Set_Charmap( FT_Face face,
3750 FT_CharMap charmap )
3757 return FT_THROW( Invalid_Face_Handle );
3759 cur = face->charmaps;
3760 if ( !cur || !charmap )
3761 return FT_THROW( Invalid_CharMap_Handle );
3763 limit = cur + face->num_charmaps;
3765 for ( ; cur < limit; cur++ )
3767 if ( cur[0] == charmap &&
3768 FT_Get_CMap_Format ( charmap ) != 14 )
3770 face->charmap = cur[0];
3775 return FT_THROW( Invalid_Argument );
3781 FT_EXPORT_DEF( FT_Int )
3782 FT_Get_Charmap_Index( FT_CharMap charmap )
3787 if ( !charmap || !charmap->face )
3790 for ( i = 0; i < charmap->face->num_charmaps; i++ )
3791 if ( charmap->face->charmaps[i] == charmap )
3794 FT_ASSERT( i < charmap->face->num_charmaps );
3801 ft_cmap_done_internal( FT_CMap cmap )
3803 FT_CMap_Class clazz = cmap->clazz;
3804 FT_Face face = cmap->charmap.face;
3805 FT_Memory memory = FT_FACE_MEMORY( face );
3809 clazz->done( cmap );
3816 FT_CMap_Done( FT_CMap cmap )
3820 FT_Face face = cmap->charmap.face;
3821 FT_Memory memory = FT_FACE_MEMORY( face );
3826 for ( i = 0; i < face->num_charmaps; i++ )
3828 if ( (FT_CMap)face->charmaps[i] == cmap )
3830 FT_CharMap last_charmap = face->charmaps[face->num_charmaps - 1];
3833 if ( FT_QRENEW_ARRAY( face->charmaps,
3835 face->num_charmaps - 1 ) )
3839 for ( j = i + 1; j < face->num_charmaps; j++ )
3841 if ( j == face->num_charmaps - 1 )
3842 face->charmaps[j - 1] = last_charmap;
3844 face->charmaps[j - 1] = face->charmaps[j];
3847 face->num_charmaps--;
3849 if ( (FT_CMap)face->charmap == cmap )
3850 face->charmap = NULL;
3852 ft_cmap_done_internal( cmap );
3861 FT_BASE_DEF( FT_Error )
3862 FT_CMap_New( FT_CMap_Class clazz,
3863 FT_Pointer init_data,
3870 FT_CMap cmap = NULL;
3873 if ( !clazz || !charmap || !charmap->face )
3874 return FT_THROW( Invalid_Argument );
3876 face = charmap->face;
3877 memory = FT_FACE_MEMORY( face );
3879 if ( !FT_ALLOC( cmap, clazz->size ) )
3881 cmap->charmap = *charmap;
3882 cmap->clazz = clazz;
3886 error = clazz->init( cmap, init_data );
3892 if ( FT_QRENEW_ARRAY( face->charmaps,
3894 face->num_charmaps + 1 ) )
3897 face->charmaps[face->num_charmaps++] = (FT_CharMap)cmap;
3907 ft_cmap_done_internal( cmap );
3915 FT_EXPORT_DEF( FT_UInt )
3916 FT_Get_Char_Index( FT_Face face,
3922 if ( face && face->charmap )
3924 FT_CMap cmap = FT_CMAP( face->charmap );
3927 if ( charcode > 0xFFFFFFFFUL )
3929 FT_TRACE1((
"FT_Get_Char_Index: too large charcode" ));
3930 FT_TRACE1((
" 0x%lx is truncated\n", charcode ));
3933 result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
3934 if ( result >= (FT_UInt)face->num_glyphs )
3944 FT_EXPORT_DEF( FT_ULong )
3945 FT_Get_First_Char( FT_Face face,
3948 FT_ULong result = 0;
3953 if ( face && face->charmap && face->num_glyphs )
3955 gindex = FT_Get_Char_Index( face, 0 );
3957 result = FT_Get_Next_Char( face, 0, &gindex );
3969 FT_EXPORT_DEF( FT_ULong )
3970 FT_Get_Next_Char( FT_Face face,
3974 FT_ULong result = 0;
3978 if ( face && face->charmap && face->num_glyphs )
3980 FT_UInt32
code = (FT_UInt32)charcode;
3981 FT_CMap cmap = FT_CMAP( face->charmap );
3986 gindex = cmap->clazz->char_next( cmap, &
code );
3988 }
while ( gindex >= (FT_UInt)face->num_glyphs );
3990 result = ( gindex == 0 ) ? 0 :
code;
4002 FT_EXPORT_DEF( FT_Error )
4003 FT_Face_Properties( FT_Face face,
4004 FT_UInt num_properties,
4005 FT_Parameter* properties )
4007 FT_Error error = FT_Err_Ok;
4010 if ( num_properties > 0 && !properties )
4012 error = FT_THROW( Invalid_Argument );
4016 for ( ; num_properties > 0; num_properties-- )
4018 if ( properties->tag == FT_PARAM_TAG_STEM_DARKENING )
4020 if ( properties->data )
4022 if ( *( (FT_Bool*)properties->data ) == TRUE )
4023 face->internal->no_stem_darkening = FALSE;
4025 face->internal->no_stem_darkening = TRUE;
4030 face->internal->no_stem_darkening = -1;
4033 else if ( properties->tag == FT_PARAM_TAG_LCD_FILTER_WEIGHTS )
4035#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
4036 if ( properties->data )
4038 ft_memcpy( face->internal->lcd_weights,
4040 FT_LCD_FILTER_FIVE_TAPS );
4041 face->internal->lcd_filter_func = ft_lcd_filter_fir;
4044 error = FT_THROW( Unimplemented_Feature );
4048 else if ( properties->tag == FT_PARAM_TAG_RANDOM_SEED )
4050 if ( properties->data )
4052 face->internal->random_seed = *( (FT_Int32*)properties->data );
4053 if ( face->internal->random_seed < 0 )
4054 face->internal->random_seed = 0;
4059 face->internal->random_seed = -1;
4064 error = FT_THROW( Invalid_Argument );
4081 FT_EXPORT_DEF( FT_UInt )
4082 FT_Face_GetCharVariantIndex( FT_Face face,
4084 FT_ULong variantSelector )
4091 face->charmap->encoding == FT_ENCODING_UNICODE )
4093 FT_CharMap charmap = find_variant_selector_charmap( face );
4094 FT_CMap ucmap = FT_CMAP( face->charmap );
4099 FT_CMap vcmap = FT_CMAP( charmap );
4102 if ( charcode > 0xFFFFFFFFUL )
4104 FT_TRACE1((
"FT_Face_GetCharVariantIndex:"
4105 " too large charcode" ));
4106 FT_TRACE1((
" 0x%lx is truncated\n", charcode ));
4108 if ( variantSelector > 0xFFFFFFFFUL )
4110 FT_TRACE1((
"FT_Face_GetCharVariantIndex:"
4111 " too large variantSelector" ));
4112 FT_TRACE1((
" 0x%lx is truncated\n", variantSelector ));
4115 result = vcmap->clazz->char_var_index( vcmap, ucmap,
4116 (FT_UInt32)charcode,
4117 (FT_UInt32)variantSelector );
4127 FT_EXPORT_DEF( FT_Int )
4128 FT_Face_GetCharVariantIsDefault( FT_Face face,
4130 FT_ULong variantSelector )
4137 FT_CharMap charmap = find_variant_selector_charmap( face );
4142 FT_CMap vcmap = FT_CMAP( charmap );
4145 if ( charcode > 0xFFFFFFFFUL )
4147 FT_TRACE1((
"FT_Face_GetCharVariantIsDefault:"
4148 " too large charcode" ));
4149 FT_TRACE1((
" 0x%lx is truncated\n", charcode ));
4151 if ( variantSelector > 0xFFFFFFFFUL )
4153 FT_TRACE1((
"FT_Face_GetCharVariantIsDefault:"
4154 " too large variantSelector" ));
4155 FT_TRACE1((
" 0x%lx is truncated\n", variantSelector ));
4158 result = vcmap->clazz->char_var_default( vcmap,
4159 (FT_UInt32)charcode,
4160 (FT_UInt32)variantSelector );
4170 FT_EXPORT_DEF( FT_UInt32* )
4171 FT_Face_GetVariantSelectors( FT_Face face )
4173 FT_UInt32 *result = NULL;
4178 FT_CharMap charmap = find_variant_selector_charmap( face );
4183 FT_CMap vcmap = FT_CMAP( charmap );
4184 FT_Memory memory = FT_FACE_MEMORY( face );
4187 result = vcmap->clazz->variant_list( vcmap, memory );
4197 FT_EXPORT_DEF( FT_UInt32* )
4198 FT_Face_GetVariantsOfChar( FT_Face face,
4201 FT_UInt32 *result = NULL;
4206 FT_CharMap charmap = find_variant_selector_charmap( face );
4211 FT_CMap vcmap = FT_CMAP( charmap );
4212 FT_Memory memory = FT_FACE_MEMORY( face );
4215 if ( charcode > 0xFFFFFFFFUL )
4217 FT_TRACE1((
"FT_Face_GetVariantsOfChar: too large charcode" ));
4218 FT_TRACE1((
" 0x%lx is truncated\n", charcode ));
4221 result = vcmap->clazz->charvariant_list( vcmap, memory,
4222 (FT_UInt32)charcode );
4231 FT_EXPORT_DEF( FT_UInt32* )
4232 FT_Face_GetCharsOfVariant( FT_Face face,
4233 FT_ULong variantSelector )
4235 FT_UInt32 *result = NULL;
4240 FT_CharMap charmap = find_variant_selector_charmap( face );
4245 FT_CMap vcmap = FT_CMAP( charmap );
4246 FT_Memory memory = FT_FACE_MEMORY( face );
4249 if ( variantSelector > 0xFFFFFFFFUL )
4251 FT_TRACE1((
"FT_Get_Char_Index: too large variantSelector" ));
4252 FT_TRACE1((
" 0x%lx is truncated\n", variantSelector ));
4255 result = vcmap->clazz->variantchar_list( vcmap, memory,
4256 (FT_UInt32)variantSelector );
4266 FT_EXPORT_DEF( FT_UInt )
4267 FT_Get_Name_Index( FT_Face face,
4268 const FT_String* glyph_name )
4274 FT_HAS_GLYPH_NAMES( face ) &&
4277 FT_Service_GlyphDict service;
4280 FT_FACE_LOOKUP_SERVICE( face,
4284 if ( service && service->name_index )
4285 result = service->name_index( face, glyph_name );
4294 FT_EXPORT_DEF( FT_Error )
4295 FT_Get_Glyph_Name( FT_Face face,
4296 FT_UInt glyph_index,
4298 FT_UInt buffer_max )
4301 FT_Service_GlyphDict service;
4305 return FT_THROW( Invalid_Face_Handle );
4307 if ( !buffer || buffer_max == 0 )
4308 return FT_THROW( Invalid_Argument );
4311 ((FT_Byte*)buffer)[0] =
'\0';
4313 if ( (FT_Long)glyph_index >= face->num_glyphs )
4314 return FT_THROW( Invalid_Glyph_Index );
4316 if ( !FT_HAS_GLYPH_NAMES( face ) )
4317 return FT_THROW( Invalid_Argument );
4319 FT_FACE_LOOKUP_SERVICE( face, service, GLYPH_DICT );
4320 if ( service && service->get_name )
4321 error = service->get_name( face, glyph_index, buffer, buffer_max );
4323 error = FT_THROW( Invalid_Argument );
4331 FT_EXPORT_DEF(
const char* )
4332 FT_Get_Postscript_Name( FT_Face face )
4334 const char* result = NULL;
4342 FT_Service_PsFontName service;
4345 FT_FACE_LOOKUP_SERVICE( face,
4347 POSTSCRIPT_FONT_NAME );
4349 if ( service && service->get_ps_font_name )
4350 result = service->get_ps_font_name( face );
4360 FT_EXPORT_DEF(
void* )
4361 FT_Get_Sfnt_Table( FT_Face face,
4365 FT_Service_SFNT_Table service;
4368 if ( face && FT_IS_SFNT( face ) )
4370 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
4372 table = service->get_table( face, tag );
4381 FT_EXPORT_DEF( FT_Error )
4382 FT_Load_Sfnt_Table( FT_Face face,
4388 FT_Service_SFNT_Table service;
4391 if ( !face || !FT_IS_SFNT( face ) )
4392 return FT_THROW( Invalid_Face_Handle );
4394 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
4396 return FT_THROW( Unimplemented_Feature );
4398 return service->load_table( face, tag, offset, buffer, length );
4404 FT_EXPORT_DEF( FT_Error )
4405 FT_Sfnt_Table_Info( FT_Face face,
4406 FT_UInt table_index,
4410 FT_Service_SFNT_Table service;
4416 if ( !face || !FT_IS_SFNT( face ) )
4417 return FT_THROW( Invalid_Face_Handle );
4419 FT_FACE_FIND_SERVICE( face, service, SFNT_TABLE );
4421 return FT_THROW( Unimplemented_Feature );
4423 return service->table_info( face, table_index, tag, &offset, length );
4429 FT_EXPORT_DEF( FT_ULong )
4430 FT_Get_CMap_Language_ID( FT_CharMap charmap )
4432 FT_Service_TTCMaps service;
4434 TT_CMapInfo cmap_info;
4437 if ( !charmap || !charmap->face )
4440 face = charmap->face;
4441 FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
4444 if ( service->get_cmap_info( charmap, &cmap_info ))
4447 return cmap_info.language;
4453 FT_EXPORT_DEF( FT_Long )
4454 FT_Get_CMap_Format( FT_CharMap charmap )
4456 FT_Service_TTCMaps service;
4458 TT_CMapInfo cmap_info;
4461 if ( !charmap || !charmap->face )
4464 face = charmap->face;
4465 FT_FACE_FIND_SERVICE( face, service, TT_CMAP );
4468 if ( service->get_cmap_info( charmap, &cmap_info ))
4471 return cmap_info.format;
4477 FT_EXPORT_DEF( FT_Error )
4478 FT_Activate_Size( FT_Size size )
4484 return FT_THROW( Invalid_Size_Handle );
4487 if ( !face || !face->driver )
4488 return FT_THROW( Invalid_Face_Handle );
4511 FT_BASE_DEF( FT_Renderer )
4512 FT_Lookup_Renderer( FT_Library library,
4513 FT_Glyph_Format format,
4517 FT_Renderer result = NULL;
4523 cur = library->renderers.head;
4528 cur = (*node)->next;
4534 FT_Renderer renderer = FT_RENDERER( cur->data );
4537 if ( renderer->glyph_format == format )
4554 ft_lookup_glyph_renderer( FT_GlyphSlot slot )
4556 FT_Face face = slot->face;
4557 FT_Library library = FT_FACE_LIBRARY( face );
4558 FT_Renderer result = library->cur_renderer;
4561 if ( !result || result->glyph_format != slot->format )
4562 result = FT_Lookup_Renderer( library, slot->format, 0 );
4569 ft_set_current_renderer( FT_Library library )
4571 FT_Renderer renderer;
4574 renderer = FT_Lookup_Renderer( library, FT_GLYPH_FORMAT_OUTLINE, 0 );
4575 library->cur_renderer = renderer;
4580 ft_add_renderer( FT_Module module )
4582 FT_Library library =
module->library;
4583 FT_Memory memory = library->memory;
4585 FT_ListNode node = NULL;
4588 if ( FT_QNEW( node ) )
4592 FT_Renderer render = FT_RENDERER( module );
4593 FT_Renderer_Class* clazz = (FT_Renderer_Class*)module->clazz;
4596 render->clazz = clazz;
4597 render->glyph_format = clazz->glyph_format;
4600 if ( clazz->raster_class && clazz->raster_class->raster_new )
4602 error = clazz->raster_class->raster_new( memory, &render->raster );
4606 render->raster_render = clazz->raster_class->raster_render;
4607 render->render = clazz->render_glyph;
4610#ifdef FT_CONFIG_OPTION_SVG
4611 if ( clazz->glyph_format == FT_GLYPH_FORMAT_SVG )
4612 render->render = clazz->render_glyph;
4616 node->data =
module;
4617 FT_List_Add( &library->renderers, node );
4619 ft_set_current_renderer( library );
4632 ft_remove_renderer( FT_Module module )
4639 library =
module->library;
4643 memory = library->memory;
4645 node = FT_List_Find( &library->renderers, module );
4648 FT_Renderer render = FT_RENDERER( module );
4652 if ( render->raster )
4653 render->clazz->raster_class->raster_done( render->raster );
4656 FT_List_Remove( &library->renderers, node );
4659 ft_set_current_renderer( library );
4666 FT_EXPORT_DEF( FT_Renderer )
4667 FT_Get_Renderer( FT_Library library,
4668 FT_Glyph_Format format )
4672 return FT_Lookup_Renderer( library, format, 0 );
4678 FT_EXPORT_DEF( FT_Error )
4679 FT_Set_Renderer( FT_Library library,
4680 FT_Renderer renderer,
4685 FT_Error error = FT_Err_Ok;
4687 FT_Renderer_SetModeFunc set_mode;
4692 error = FT_THROW( Invalid_Library_Handle );
4698 error = FT_THROW( Invalid_Argument );
4704 error = FT_THROW( Invalid_Argument );
4708 node = FT_List_Find( &library->renderers, renderer );
4711 error = FT_THROW( Invalid_Argument );
4715 FT_List_Up( &library->renderers, node );
4717 if ( renderer->glyph_format == FT_GLYPH_FORMAT_OUTLINE )
4718 library->cur_renderer = renderer;
4720 set_mode = renderer->clazz->set_mode;
4722 for ( ; num_params > 0; num_params-- )
4735 FT_BASE_DEF( FT_Error )
4736 FT_Render_Glyph_Internal( FT_Library library,
4738 FT_Render_Mode render_mode )
4740 FT_Error error = FT_Err_Ok;
4741 FT_Face face = slot->face;
4742 FT_Renderer renderer;
4745 switch ( slot->format )
4748 if ( slot->internal->load_flags & FT_LOAD_COLOR )
4750 FT_LayerIterator iterator;
4752 FT_UInt base_glyph = slot->glyph_index;
4754 FT_Bool have_layers;
4755 FT_UInt glyph_index;
4756 FT_UInt color_index;
4761 have_layers = FT_Get_Color_Glyph_Layer( face,
4768 error = FT_New_GlyphSlot( face, NULL );
4771 TT_Face ttface = (TT_Face)face;
4772 SFNT_Service sfnt = (SFNT_Service)ttface->sfnt;
4777 FT_Int32 load_flags = slot->internal->load_flags;
4782 load_flags &= ~FT_LOAD_COLOR;
4785 load_flags |= FT_LOAD_RENDER;
4787 error = FT_Load_Glyph( face, glyph_index, load_flags );
4793 error = sfnt->colr_blend( ttface,
4800 }
while ( FT_Get_Color_Glyph_Layer( face,
4807 slot->format = FT_GLYPH_FORMAT_BITMAP;
4810 FT_Done_GlyphSlot( face->glyph );
4817 slot->format = FT_GLYPH_FORMAT_OUTLINE;
4822 FT_ListNode node = NULL;
4826 if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
4828 renderer = library->cur_renderer;
4829 node = library->renderers.head;
4832 renderer = FT_Lookup_Renderer( library, slot->format, &node );
4834 error = FT_ERR( Cannot_Render_Glyph );
4837 error = renderer->render( renderer, slot, render_mode, NULL );
4839 FT_ERR_NEQ( error, Cannot_Render_Glyph ) )
4848 renderer = FT_Lookup_Renderer( library, slot->format, &node );
4852 if ( FT_ERR_EQ( error, Cannot_Render_Glyph ) &&
4853 slot->format == FT_GLYPH_FORMAT_BITMAP )
4858#ifdef FT_DEBUG_LEVEL_TRACE
4861#define FT_COMPONENT checksum
4872 ft_trace_levels[trace_checksum] >= 3 &&
4873 slot->bitmap.buffer )
4879 FT_Bitmap_Init( &bitmap );
4883 err = FT_Bitmap_Convert( library, &slot->bitmap, &bitmap, 1 );
4887 unsigned char md5[16];
4888 unsigned long coverage = 0;
4890 int rows = (int)bitmap.rows;
4891 int pitch = bitmap.pitch;
4894 FT_TRACE3((
"FT_Render_Glyph: bitmap %dx%d, %s (mode %d)\n",
4897 pixel_modes[slot->bitmap.pixel_mode],
4898 slot->bitmap.pixel_mode ));
4900 for ( i = 0; i < rows; i++ )
4901 for ( j = 0; j < pitch; j++ )
4902 coverage += bitmap.buffer[i * pitch + j];
4904 FT_TRACE3((
" Total coverage: %lu\n", coverage ));
4907 if ( bitmap.buffer )
4908 MD5_Update( &ctx, bitmap.buffer,
4909 (
unsigned long)rows * (
unsigned long)pitch );
4910 MD5_Final( md5, &ctx );
4912 FT_TRACE3((
" MD5 checksum: " ));
4913 for ( i = 0; i < 16; i++ )
4914 FT_TRACE3((
"%02X", md5[i] ));
4915 FT_TRACE3((
"\n" ));
4918 FT_Bitmap_Done( library, &bitmap );
4927 ft_trace_levels[trace_checksum] >= 7 &&
4928 slot->bitmap.buffer )
4930 if ( slot->bitmap.rows < 128U &&
4931 slot->bitmap.width < 128U )
4933 int rows = (int)slot->bitmap.rows;
4934 int width = (int)slot->bitmap.width;
4935 int pitch = slot->bitmap.pitch;
4938 unsigned char* topleft = slot->bitmap.buffer;
4942 topleft -= pitch * ( rows - 1 );
4944 FT_TRACE7((
"Netpbm image: start\n" ));
4945 switch ( slot->bitmap.pixel_mode )
4947 case FT_PIXEL_MODE_MONO:
4948 FT_TRACE7((
"P1 %d %d\n", width, rows ));
4949 for ( i = 0; i < rows; i++ )
4951 for ( j = 0; j < width; )
4952 for ( m = 128; m > 0 && j < width; m >>= 1, j++ )
4954 ( topleft[i * pitch + j / 8] & m ) != 0 ));
4955 FT_TRACE7((
"\n" ));
4960 FT_TRACE7((
"P2 %d %d 255\n", width, rows ));
4961 for ( i = 0; i < rows; i++ )
4963 for ( j = 0; j < width; j += 1 )
4964 FT_TRACE7((
" %3u", topleft[i * pitch + j] ));
4965 FT_TRACE7((
"\n" ));
4968 FT_TRACE7((
"Netpbm image: end\n" ));
4971 FT_TRACE7((
"Netpbm image: too large, omitted\n" ));
4975#define FT_COMPONENT objs
4985 FT_EXPORT_DEF( FT_Error )
4986 FT_Render_Glyph( FT_GlyphSlot slot,
4987 FT_Render_Mode render_mode )
4992 if ( !slot || !slot->face )
4993 return FT_THROW( Invalid_Argument );
4995 library = FT_FACE_LIBRARY( slot->face );
4997 return FT_Render_Glyph_Internal( library, slot, render_mode );
5031 Destroy_Module( FT_Module module )
5033 const FT_Module_Class* clazz =
module->clazz;
5034 FT_Library library =
module->library;
5035 FT_Memory memory =
module->memory;
5038 if ( library && library->auto_hinter == module )
5039 library->auto_hinter = NULL;
5042 if ( FT_MODULE_IS_RENDERER( module ) )
5043 ft_remove_renderer( module );
5046 if ( FT_MODULE_IS_DRIVER( module ) )
5047 Destroy_Driver( FT_DRIVER( module ) );
5050 if ( clazz->module_done )
5051 clazz->module_done( module );
5060 FT_EXPORT_DEF( FT_Error )
5061 FT_Add_Module( FT_Library library,
5062 const FT_Module_Class* clazz )
5066 FT_Module module = NULL;
5070#define FREETYPE_VER_FIXED ( ( (FT_Long)FREETYPE_MAJOR << 16 ) | \
5074 return FT_THROW( Invalid_Library_Handle );
5077 return FT_THROW( Invalid_Argument );
5080 if ( clazz->module_requires > FREETYPE_VER_FIXED )
5081 return FT_THROW( Invalid_Version );
5084 for ( nn = 0; nn < library->num_modules; nn++ )
5086 module = library->modules[nn];
5087 if ( ft_strcmp( module->clazz->module_name, clazz->module_name ) == 0 )
5090 if ( clazz->module_version <= module->clazz->module_version )
5091 return FT_THROW( Lower_Module_Version );
5095 FT_Remove_Module( library, module );
5100 memory = library->memory;
5103 if ( library->num_modules >= FT_MAX_MODULES )
5105 error = FT_THROW( Too_Many_Drivers );
5110 if ( FT_ALLOC( module, clazz->module_size ) )
5114 module->clazz = clazz;
5115 module->library = library;
5116 module->memory = memory;
5120 if ( FT_MODULE_IS_RENDERER( module ) )
5123 error = ft_add_renderer( module );
5129 if ( FT_MODULE_IS_HINTER( module ) )
5130 library->auto_hinter =
module;
5133 if ( FT_MODULE_IS_DRIVER( module ) )
5135 FT_Driver driver = FT_DRIVER( module );
5138 driver->clazz = (FT_Driver_Class)module->clazz;
5141 if ( clazz->module_init )
5143 error = clazz->module_init( module );
5149 library->modules[library->num_modules++] =
module;
5155 if ( FT_MODULE_IS_RENDERER( module ) )
5157 FT_Renderer renderer = FT_RENDERER( module );
5160 if ( renderer->clazz &&
5161 renderer->clazz->glyph_format == FT_GLYPH_FORMAT_OUTLINE &&
5163 renderer->clazz->raster_class->raster_done( renderer->raster );
5173 FT_EXPORT_DEF( FT_Module )
5174 FT_Get_Module( FT_Library library,
5175 const char* module_name )
5177 FT_Module result = NULL;
5182 if ( !library || !module_name )
5185 cur = library->modules;
5186 limit = cur + library->num_modules;
5188 for ( ; cur < limit; cur++ )
5189 if ( ft_strcmp( cur[0]->clazz->module_name, module_name ) == 0 )
5201 FT_BASE_DEF(
const void* )
5202 FT_Get_Module_Interface( FT_Library library,
5203 const char* mod_name )
5210 module = FT_Get_Module( library, mod_name );
5212 return module ? module->clazz->module_interface : 0;
5216 FT_BASE_DEF( FT_Pointer )
5217 ft_module_get_service( FT_Module module,
5218 const char* service_id,
5221 FT_Pointer result = NULL;
5226 FT_ASSERT( module->clazz && module->clazz->get_interface );
5229 if ( module->clazz->get_interface )
5230 result =
module->clazz->get_interface( module, service_id );
5232 if ( global && !result )
5235 FT_Library library =
module->library;
5236 FT_Module* cur = library->modules;
5237 FT_Module* limit = cur + library->num_modules;
5240 for ( ; cur < limit; cur++ )
5242 if ( cur[0] != module )
5244 FT_ASSERT( cur[0]->clazz );
5246 if ( cur[0]->clazz->get_interface )
5248 result = cur[0]->clazz->get_interface( cur[0], service_id );
5263 FT_EXPORT_DEF( FT_Error )
5264 FT_Remove_Module( FT_Library library,
5270 return FT_THROW( Invalid_Library_Handle );
5274 FT_Module* cur = library->modules;
5275 FT_Module* limit = cur + library->num_modules;
5278 for ( ; cur < limit; cur++ )
5280 if ( cur[0] == module )
5283 library->num_modules--;
5285 while ( cur < limit )
5293 Destroy_Module( module );
5299 return FT_THROW( Invalid_Driver_Handle );
5304 ft_property_do( FT_Library library,
5305 const FT_String* module_name,
5306 const FT_String* property_name,
5309 FT_Bool value_is_string )
5313 FT_Module_Interface interface;
5315 FT_Service_Properties service;
5317#ifdef FT_DEBUG_LEVEL_ERROR
5318 const FT_String* set_name =
"FT_Property_Set";
5319 const FT_String* get_name =
"FT_Property_Get";
5320 const FT_String* func_name = set ? set_name : get_name;
5323 FT_Bool missing_func;
5327 return FT_THROW( Invalid_Library_Handle );
5329 if ( !module_name || !property_name || !value )
5330 return FT_THROW( Invalid_Argument );
5332 cur = library->modules;
5333 limit = cur + library->num_modules;
5336 for ( ; cur < limit; cur++ )
5337 if ( !ft_strcmp( cur[0]->clazz->module_name, module_name ) )
5342 FT_TRACE2((
"%s: can't find module `%s'\n",
5343 func_name, module_name ));
5344 return FT_THROW( Missing_Module );
5348 if ( !cur[0]->clazz->get_interface )
5350 FT_TRACE2((
"%s: module `%s' doesn't support properties\n",
5351 func_name, module_name ));
5352 return FT_THROW( Unimplemented_Feature );
5356 interface = cur[0]->clazz->get_interface( cur[0],
5357 FT_SERVICE_ID_PROPERTIES );
5360 FT_TRACE2((
"%s: module `%s' doesn't support properties\n",
5361 func_name, module_name ));
5362 return FT_THROW( Unimplemented_Feature );
5365 service = (FT_Service_Properties)interface;
5368 missing_func = FT_BOOL( !service->set_property );
5370 missing_func = FT_BOOL( !service->get_property );
5374 FT_TRACE2((
"%s: property service of module `%s' is broken\n",
5375 func_name, module_name ));
5376 return FT_THROW( Unimplemented_Feature );
5379 return set ? service->set_property( cur[0],
5383 : service->get_property( cur[0],
5391 FT_EXPORT_DEF( FT_Error )
5392 FT_Property_Set( FT_Library library,
5393 const FT_String* module_name,
5394 const FT_String* property_name,
5397 return ft_property_do( library,
5408 FT_EXPORT_DEF( FT_Error )
5409 FT_Property_Get( FT_Library library,
5410 const FT_String* module_name,
5411 const FT_String* property_name,
5414 return ft_property_do( library,
5423#ifdef FT_CONFIG_OPTION_ENVIRONMENT_PROPERTIES
5428 FT_BASE_DEF( FT_Error )
5429 ft_property_string_set( FT_Library library,
5430 const FT_String* module_name,
5431 const FT_String* property_name,
5434 return ft_property_do( library,
5460 FT_EXPORT_DEF( FT_Error )
5461 FT_Reference_Library( FT_Library library )
5464 return FT_THROW( Invalid_Library_Handle );
5466 library->refcount++;
5474 FT_EXPORT_DEF( FT_Error )
5475 FT_New_Library( FT_Memory memory,
5476 FT_Library *alibrary )
5478 FT_Library library = NULL;
5482 if ( !memory || !alibrary )
5483 return FT_THROW( Invalid_Argument );
5485#ifndef FT_DEBUG_LOGGING
5486#ifdef FT_DEBUG_LEVEL_ERROR
5493 if ( FT_NEW( library ) )
5496 library->memory = memory;
5498 library->version_major = FREETYPE_MAJOR;
5499 library->version_minor = FREETYPE_MINOR;
5500 library->version_patch = FREETYPE_PATCH;
5502 library->refcount = 1;
5505 *alibrary = library;
5513 FT_EXPORT_DEF(
void )
5514 FT_Library_Version( FT_Library library,
5526 major = library->version_major;
5527 minor = library->version_minor;
5528 patch = library->version_patch;
5544 FT_EXPORT_DEF( FT_Error )
5545 FT_Done_Library( FT_Library library )
5551 return FT_THROW( Invalid_Library_Handle );
5553 library->refcount--;
5554 if ( library->refcount > 0 )
5557 memory = library->memory;
5577 const char* driver_name[] = {
"type42", NULL };
5581 m <
sizeof ( driver_name ) /
sizeof ( driver_name[0] );
5584 for ( n = 0; n < library->num_modules; n++ )
5586 FT_Module module = library->modules[n];
5587 const char* module_name =
module->clazz->module_name;
5591 if ( driver_name[m] &&
5592 ft_strcmp( module_name, driver_name[m] ) != 0 )
5595 if ( ( module->clazz->module_flags & FT_MODULE_FONT_DRIVER ) == 0 )
5598 FT_TRACE7((
"FT_Done_Library: close faces for %s\n", module_name ));
5600 faces = &FT_DRIVER( module )->faces_list;
5601 while ( faces->head )
5603 FT_Done_Face( FT_FACE( faces->head->data ) );
5605 FT_TRACE0((
"FT_Done_Library: failed to free some faces\n" ));
5616 while ( library->num_modules > 0 )
5617 FT_Remove_Module( library,
5618 library->modules[library->num_modules - 1] );
5624 for ( n = 0; n < library->num_modules; n++ )
5626 FT_Module module = library->modules[n];
5631 Destroy_Module( module );
5632 library->modules[n] = NULL;
5647 FT_EXPORT_DEF(
void )
5648 FT_Set_Debug_Hook( FT_Library library,
5650 FT_DebugHook_Func debug_hook )
5652 if ( library && debug_hook &&
5654 (
sizeof ( library->debug_hooks ) / sizeof (
void* ) ) )
5655 library->debug_hooks[hook_index] = debug_hook;
5661 FT_EXPORT_DEF( FT_TrueTypeEngineType )
5662 FT_Get_TrueType_Engine_Type( FT_Library library )
5664 FT_TrueTypeEngineType result = FT_TRUETYPE_ENGINE_TYPE_NONE;
5669 FT_Module module = FT_Get_Module( library,
"truetype" );
5674 FT_Service_TrueTypeEngine service;
5677 service = (FT_Service_TrueTypeEngine)
5678 ft_module_get_service( module,
5679 FT_SERVICE_ID_TRUETYPE_ENGINE,
5682 result = service->engine_type;
5692 FT_EXPORT_DEF( FT_Error )
5693 FT_Get_SubGlyph_Info( FT_GlyphSlot glyph,
5699 FT_Matrix *p_transform )
5701 FT_Error error = FT_ERR( Invalid_Argument );
5706 glyph->format == FT_GLYPH_FORMAT_COMPOSITE &&
5707 sub_index < glyph->num_subglyphs )
5709 FT_SubGlyph subg = glyph->subglyphs + sub_index;
5712 *p_index = subg->index;
5713 *p_flags = subg->flags;
5714 *p_arg1 = subg->arg1;
5715 *p_arg2 = subg->arg2;
5716 *p_transform = subg->transform;
5727 FT_EXPORT_DEF( FT_Bool )
5728 FT_Get_Color_Glyph_Layer( FT_Face face,
5730 FT_UInt *aglyph_index,
5731 FT_UInt *acolor_index,
5732 FT_LayerIterator* iterator )
5742 base_glyph >= (FT_UInt)face->num_glyphs )
5745 if ( !FT_IS_SFNT( face ) )
5748 ttface = (TT_Face)face;
5749 sfnt = (SFNT_Service)ttface->sfnt;
5751 if ( sfnt->get_colr_layer )
5752 return sfnt->get_colr_layer( ttface,
5764 FT_EXPORT_DEF( FT_Bool )
5765 FT_Get_Color_Glyph_Paint( FT_Face face,
5767 FT_Color_Root_Transform root_transform,
5768 FT_OpaquePaint* paint )
5774 if ( !face || !paint )
5777 if ( !FT_IS_SFNT( face ) )
5780 ttface = (TT_Face)face;
5781 sfnt = (SFNT_Service)ttface->sfnt;
5783 if ( sfnt->get_colr_glyph_paint )
5784 return sfnt->get_colr_glyph_paint( ttface,
5795 FT_EXPORT_DEF( FT_Bool )
5796 FT_Get_Color_Glyph_ClipBox( FT_Face face,
5798 FT_ClipBox* clip_box )
5804 if ( !face || !clip_box )
5807 if ( !FT_IS_SFNT( face ) )
5810 ttface = (TT_Face)face;
5811 sfnt = (SFNT_Service)ttface->sfnt;
5813 if ( sfnt->get_color_glyph_clipbox )
5814 return sfnt->get_color_glyph_clipbox( ttface,
5824 FT_EXPORT_DEF( FT_Bool )
5825 FT_Get_Paint_Layers( FT_Face face,
5826 FT_LayerIterator* layer_iterator,
5827 FT_OpaquePaint* paint )
5833 if ( !face || !paint || !layer_iterator )
5836 if ( !FT_IS_SFNT( face ) )
5839 ttface = (TT_Face)face;
5840 sfnt = (SFNT_Service)ttface->sfnt;
5842 if ( sfnt->get_paint_layers )
5843 return sfnt->get_paint_layers( ttface, layer_iterator, paint );
5851 FT_EXPORT_DEF( FT_Bool )
5852 FT_Get_Paint( FT_Face face,
5853 FT_OpaquePaint opaque_paint,
5854 FT_COLR_Paint* paint )
5860 if ( !face || !paint )
5863 if ( !FT_IS_SFNT( face ) )
5866 ttface = (TT_Face)face;
5867 sfnt = (SFNT_Service)ttface->sfnt;
5869 if ( sfnt->get_paint )
5870 return sfnt->get_paint( ttface, opaque_paint, paint );
5878 FT_EXPORT_DEF( FT_Bool )
5879 FT_Get_Colorline_Stops ( FT_Face face,
5880 FT_ColorStop * color_stop,
5881 FT_ColorStopIterator *iterator )
5887 if ( !face || !color_stop || !iterator )
5890 if ( !FT_IS_SFNT( face ) )
5893 ttface = (TT_Face)face;
5894 sfnt = (SFNT_Service)ttface->sfnt;
5896 if ( sfnt->get_colorline_stops )
5897 return sfnt->get_colorline_stops ( ttface, color_stop, iterator );