diff -Nru freetype-2.7-old/include/freetype/freetype.h freetype-2.7/include/freetype/freetype.h --- freetype-2.7-old/include/freetype/freetype.h 2016-09-08 15:45:54.000000000 +0900 +++ freetype-2.7/include/freetype/freetype.h 2008-11-27 14:44:11.672551500 +0900 @@ -175,6 +175,7 @@ /* FT_Done_Face */ /* FT_Reference_Face */ /* FT_New_Memory_Face */ + /* FT_New_Memory_Face_Offset */ /* FT_Open_Face */ /* FT_Open_Args */ /* FT_Parameter */ @@ -234,6 +235,8 @@ /* FT_Get_Glyph_Name */ /* FT_Get_Postscript_Name */ /* */ + /* FT_TTCInfo */ + /* */ /* FT_CharMapRec */ /* FT_Select_Charmap */ /* FT_Set_Charmap */ @@ -803,6 +806,35 @@ #define ft_encoding_adobe_custom FT_ENCODING_ADOBE_CUSTOM #define ft_encoding_apple_roman FT_ENCODING_APPLE_ROMAN + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* T T C H A N D L I N G */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* */ + /* FT_TTCInfo */ + /* */ + /* */ + /* The font collection informatoin structure. */ + /* */ + /* */ + /* num_fonts :: The number of the fonts in the collection. */ + /* */ + /* offset_table :: The array of offsets. */ + /* */ + /* */ + /* It should be freed this structure after use. */ + /* */ + typedef struct FT_TTCInfo_ + { + FT_UInt32 num_fonts; + FT_UInt32 offset_table[1]; + } FT_TTCInfo; /*************************************************************************/ /* */ @@ -836,7 +868,6 @@ } FT_CharMapRec; - /*************************************************************************/ /*************************************************************************/ /* */ @@ -1949,6 +1980,8 @@ /* params :: Extra parameters passed to the font driver when */ /* opening a new face. */ /* */ + /* offset :: The position to begin reading. */ + /* */ /* */ /* The stream type is determined by the contents of `flags' that */ /* are tested in the following order by @FT_Open_Face: */ @@ -1985,7 +2018,7 @@ FT_Module driver; FT_Int num_params; FT_Parameter* params; - + FT_Long offset; } FT_Open_Args; @@ -2061,6 +2094,47 @@ FT_Long face_index, FT_Face *aface ); + /*************************************************************************/ + /* */ + /* */ + /* FT_New_Memory_Face_Offset */ + /* */ + /* */ + /* This function calls @FT_Open_Face to open a font that has been */ + /* loaded into memory. */ + /* */ + /* */ + /* library :: A handle to the library resource. */ + /* */ + /* */ + /* file_base :: A pointer to the beginning of the font data. */ + /* */ + /* file_size :: The size of the memory chunk used by the font data. */ + /* */ + /* face_index :: See @FT_Open_Face for a detailed description of this */ + /* parameter. */ + /* */ + /* offset :: The position to begin reading. */ + /* */ + /* */ + /* aface :: A handle to a new face object. If `face_index' is */ + /* greater than or equal to zero, it must be non-NULL. */ + /* */ + /* */ + /* FreeType error code. 0~means success. */ + /* */ + /* */ + /* You must not deallocate the memory before calling @FT_Done_Face. */ + /* This function is used for font collection files (*.ttc). */ + /* */ + FT_EXPORT( FT_Error ) + FT_New_Memory_Face_Offset( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface, + FT_Long offset); + /*************************************************************************/ /* */ @@ -4296,7 +4370,34 @@ FT_Bool value ); /* */ + FT_EXPORT( void ) + FT_Library_Version( FT_Library library, + FT_Int *amajor, + FT_Int *aminor, + FT_Int *apatch ); + /*************************************************************************/ + /* */ + /* */ + /* FT_GetTTCInfo */ + /* */ + /* */ + /* Gets the TTC info from contents of the font collection file. */ + /* */ + /* */ + /* file_base :: The beginning of file contents. */ + /* */ + /* file_size :: The size of the file. */ + /* */ + /* */ + /* If successful, returns the pointer to a FT_FontCollectionInfo. */ + /* */ + /* */ + /* FT_FontCollectionInfo should be freed after use. */ + /* */ + FT_EXPORT( FT_TTCInfo * ) + FT_GetTTCInfo( const FT_Byte* file_base, + FT_ULong file_size ); FT_END_HEADER diff -Nru freetype-2.7-old/include/freetype/internal/ftstream.h freetype-2.7/include/freetype/internal/ftstream.h --- freetype-2.7-old/include/freetype/internal/ftstream.h 2016-02-04 03:13:58.000000000 +0900 +++ freetype-2.7/include/freetype/internal/ftstream.h 2008-11-27 14:27:01.625752800 +0900 @@ -344,6 +344,11 @@ FT_Stream_OpenMemory( FT_Stream stream, const FT_Byte* base, FT_ULong size ); + FT_BASE( void ) + FT_Stream_OpenMemoryOffset( FT_Stream stream, + const FT_Byte* base, + FT_ULong size, + FT_ULong offset); /* close a stream (does not destroy the stream structure) */ FT_BASE( void ) diff -Nru freetype-2.7-old/src/base/ftmac.c freetype-2.7/src/base/ftmac.c --- freetype-2.7-old/src/base/ftmac.c 2016-03-20 17:04:20.000000000 +0900 +++ freetype-2.7/src/base/ftmac.c 2008-11-27 14:22:06.563401700 +0900 @@ -988,6 +988,7 @@ /* let it fall through to normal loader (.ttf, .otf, etc.) */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; + args.offset = 0; return FT_Open_Face( library, &args, face_index, aface ); } @@ -1033,6 +1034,7 @@ /* fallback to datafork font */ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; + args.offset = 0; return FT_Open_Face( library, &args, face_index, aface ); } diff -Nru freetype-2.7-old/src/base/ftobjs.c freetype-2.7/src/base/ftobjs.c --- freetype-2.7-old/src/base/ftobjs.c 2016-09-04 18:42:16.000000000 +0900 +++ freetype-2.7/src/base/ftobjs.c 2008-11-27 15:34:54.678826400 +0900 @@ -187,9 +187,10 @@ if ( args->flags & FT_OPEN_MEMORY ) { /* create a memory-based stream */ - FT_Stream_OpenMemory( stream, - (const FT_Byte*)args->memory_base, - (FT_ULong)args->memory_size ); + FT_Stream_OpenMemoryOffset( stream, + (const FT_Byte*)args->memory_base, + (FT_ULong)args->memory_size, + args->offset ); } #ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT @@ -1236,6 +1237,7 @@ args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; args.stream = NULL; + args.offset = 0; return FT_Open_Face( library, &args, face_index, aface ); } @@ -1243,14 +1245,13 @@ #endif - /* documentation is in freetype.h */ - FT_EXPORT_DEF( FT_Error ) - FT_New_Memory_Face( FT_Library library, - const FT_Byte* file_base, - FT_Long file_size, - FT_Long face_index, - FT_Face *aface ) + FT_New_Memory_Face_Offset( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface, + FT_Long offset) { FT_Open_Args args; @@ -1263,11 +1264,25 @@ args.memory_base = file_base; args.memory_size = file_size; args.stream = NULL; + args.offset = offset; return FT_Open_Face( library, &args, face_index, aface ); } + /* documentation is in freetype.h */ + + FT_EXPORT_DEF( FT_Error ) + FT_New_Memory_Face( FT_Library library, + const FT_Byte* file_base, + FT_Long file_size, + FT_Long face_index, + FT_Face *aface ) + { + return FT_New_Memory_Face_Offset(library, file_base, file_size, + face_index, aface, 0); + } + #ifdef FT_CONFIG_OPTION_MAC_FONTS /* The behavior here is very similar to that in base/ftmac.c, but it */ @@ -1379,6 +1394,7 @@ args.flags = FT_OPEN_STREAM; args.stream = stream; + args.offset = 0; if ( driver_name ) { args.flags = args.flags | FT_OPEN_DRIVER; @@ -2004,6 +2020,7 @@ args2.flags = FT_OPEN_PATHNAME; args2.pathname = file_names[i] ? file_names[i] : args->pathname; + args2.offset = 0; FT_TRACE3(( "Try rule %d: %s (offset=%d) ...", i, args2.pathname, offsets[i] )); @@ -2388,6 +2405,7 @@ open.stream = NULL; open.flags = FT_OPEN_PATHNAME; open.pathname = (char*)filepathname; + open.offset = 0; return FT_Attach_Stream( face, &open ); } @@ -5013,5 +5031,68 @@ return error; } + typedef struct _ENDIAN_TEST { + FT_UInt32 value; + } ENDIAN_TEST; + + static FT_UInt32 FT_ChangeEndianIfNeeds(FT_UInt32 value) + { + ENDIAN_TEST test; + FT_UInt32 new_value; + + test.value = 1; + if (*(char *)&test == 1) + { + new_value = 0; + new_value |= (value & 0xFF000000) >> 24; + new_value |= (value & 0xFF0000) >> 8; + new_value |= (value & 0xFF00) << 8; + new_value |= (value & 0xFF) << 24; + } + else + { + new_value = value; + } + return new_value; + } + + /* documentation is in freetype.h */ + + FT_EXPORT( FT_TTCInfo * ) + FT_GetTTCInfo( const FT_Byte* file_base, + FT_ULong file_size ) + { + FT_TTCInfo *info; + FT_ULong size, index, num_fonts; + FT_UInt32 value, *ptr; + + ptr = (FT_UInt32 *)file_base; + value = FT_ChangeEndianIfNeeds(ptr[0]); + if (value != 0x74746366) /* 'ttcf' */ + return NULL; + + value = FT_ChangeEndianIfNeeds(ptr[1]); + if (value != 0x00010000 && value != 0x00020000) + return NULL; + + value = FT_ChangeEndianIfNeeds(ptr[2]); + if (value == 0 || value >= 0x10000) + return NULL; + + num_fonts = value; + size = sizeof(FT_TTCInfo); + size += (num_fonts - 1) * sizeof(FT_UInt32); + + info = (FT_TTCInfo *)calloc(1, size); + if (info) + { + info->num_fonts = num_fonts; + for (index = 0; index < num_fonts; ++index) + { + info->offset_table[index] = ptr[3 + index]; + } + } + return info; + } /* END */ diff -Nru freetype-2.7-old/src/base/ftrfork.c freetype-2.7/src/base/ftrfork.c --- freetype-2.7-old/src/base/ftrfork.c 2016-03-20 17:04:20.000000000 +0900 +++ freetype-2.7/src/base/ftrfork.c 2008-11-27 13:39:31.536812900 +0900 @@ -790,6 +790,7 @@ args2.flags = FT_OPEN_PATHNAME; args2.pathname = file_name; + args2.offset = 0; error = FT_Stream_New( library, &args2, &stream2 ); if ( error ) return error; diff -Nru freetype-2.7-old/src/base/ftstream.c freetype-2.7/src/base/ftstream.c --- freetype-2.7-old/src/base/ftstream.c 2016-03-20 17:04:20.000000000 +0900 +++ freetype-2.7/src/base/ftstream.c 2008-11-27 14:26:36.260254400 +0900 @@ -44,6 +44,20 @@ stream->close = NULL; } + FT_BASE_DEF( void ) + FT_Stream_OpenMemoryOffset( FT_Stream stream, + const FT_Byte* base, + FT_ULong size, + FT_ULong offset ) + { + stream->base = (FT_Byte*) base; + stream->size = size; + stream->pos = offset; + stream->cursor = NULL; + stream->read = NULL; + stream->close = NULL; + } + FT_BASE_DEF( void ) FT_Stream_Close( FT_Stream stream ) diff -Nru freetype-2.7-old/src/type42/t42objs.c freetype-2.7/src/type42/t42objs.c --- freetype-2.7-old/src/type42/t42objs.c 2016-08-26 18:45:36.000000000 +0900 +++ freetype-2.7/src/type42/t42objs.c 2008-11-27 13:39:51.879728200 +0900 @@ -288,12 +288,12 @@ { FT_Open_Args args; - args.flags = FT_OPEN_MEMORY | FT_OPEN_DRIVER; args.driver = FT_Get_Module( FT_FACE_LIBRARY( face ), "truetype" ); args.memory_base = face->ttf_data; args.memory_size = face->ttf_size; + args.offset = 0; if ( num_params ) {