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 2016-11-28 13:11:27.371000300 +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 */ @@ -1084,6 +1085,8 @@ FT_Face_Internal internal; + char font_name[32]; + /*@private end */ } FT_FaceRec; @@ -1871,6 +1874,8 @@ /* */ /* FT_OPEN_PARAMS :: Use the `num_params' and `params' fields. */ /* */ + /* FT_OPEN_OFFSET :: Use the `offset' field. */ + /* */ /* */ /* The `FT_OPEN_MEMORY', `FT_OPEN_STREAM', and `FT_OPEN_PATHNAME' */ /* flags are mutually exclusive. */ @@ -1880,6 +1885,7 @@ #define FT_OPEN_PATHNAME 0x4 #define FT_OPEN_DRIVER 0x8 #define FT_OPEN_PARAMS 0x10 +#define FT_OPEN_OFFSET 0x20 /* these constants are deprecated; use the corresponding `FT_OPEN_XXX' */ @@ -1949,6 +1955,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: */ @@ -1975,6 +1983,9 @@ /* as `const'; this is missing for API backwards compatibility. In */ /* other words, applications should treat them as read-only. */ /* */ + /* If the @FT_OPEN_OFFSET bit is set, the parameters given by */ + /* `offset' is used. It is ignored otherwise. */ + /* */ typedef struct FT_Open_Args_ { FT_UInt flags; @@ -1985,6 +1996,7 @@ FT_Module driver; FT_Int num_params; FT_Parameter* params; + FT_Long offset; } FT_Open_Args; @@ -2061,6 +2073,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 usually 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,6 +4349,110 @@ FT_Bool value ); /* */ + FT_EXPORT( void ) + FT_Library_Version( FT_Library library, + FT_Int *amajor, + FT_Int *aminor, + FT_Int *apatch ); + + /*************************************************************************/ + /*************************************************************************/ + /* */ + /* T T C H A N D L I N G */ + /* */ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /*
*/ + /* font_collection */ + /* */ + /* */ + /* Font Collection File Support */ + /* */ + /* <Abstract> */ + /* The FreeType~2 font collection file (*.ttc) support. */ + /* */ + /* <Description> */ + /* This section describes the font collection file (*.ttc) API */ + /* functions of FreeType~2. */ + /* */ + /* <Order> */ + /* FT_TTC_Info */ + /* FT_TTC_GetInfoMemory */ + /* FT_TTC_Free */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FT_TTC_Info */ + /* */ + /* <Description> */ + /* The font collection information structure. */ + /* */ + /* <Fields> */ + /* num_fonts :: The number of the fonts in the collection. */ + /* */ + /* offset_table :: The array of offsets. */ + /* */ + /* <Note> */ + /* It should be freed this structure by FT_TTC_FreeInfo after use. */ + /* */ + typedef struct FT_TTC_Info_ + { + FT_UInt32 num_fonts; + FT_UInt32 version; + FT_UInt32 offset_table[1]; + + } FT_TTC_Info; + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_TTC_GetInfoMemory */ + /* */ + /* <Description> */ + /* Gets the TTC info from contents of the font collection file. */ + /* */ + /* <Input> */ + /* library :: A library handle. */ + /* */ + /* file_base :: The beginning of file contents. */ + /* */ + /* file_size :: The size of the file. */ + /* */ + /* <Return> */ + /* If successful, returns the pointer to a FT_TTC_Info allocated. */ + /* Otherwise the function returns NULL. */ + /* */ + /* <Note> */ + /* FT_TTC_Info should be freed by FT_TTC_FreeInfo after use. */ + /* */ + FT_EXPORT( FT_TTC_Info * ) + FT_TTC_GetInfoMemory( FT_Library library, + const FT_Byte* file_base, + FT_ULong file_size ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FT_TTC_FreeInfo */ + /* */ + /* <Description> */ + /* Releases the TTC info allocated by FT_TTC_GetInfoMemory. */ + /* */ + /* <Input> */ + /* library :: A library handle. */ + /* */ + /* info :: The info to be released. */ + /* */ + FT_EXPORT( void ) + FT_TTC_FreeInfo( FT_Library library, + FT_TTC_Info * info ); 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 20:00:09.363622700 +0900 @@ -344,6 +344,12 @@ FT_Stream_OpenMemory( FT_Stream stream, const FT_Byte* base, FT_ULong size ); + /* initialize a stream for reading in-memory data with offset specified */ + 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/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 2016-11-28 13:14:18.845248700 +0900 @@ -19,6 +19,7 @@ #include <ft2build.h> #include FT_LIST_H #include FT_OUTLINE_H +#include FT_SFNT_NAMES_H #include FT_INTERNAL_VALIDATE_H #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_DEBUG_H @@ -187,9 +188,19 @@ 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 ); + if ( args->flags & FT_OPEN_OFFSET ) + { + FT_Stream_OpenMemoryOffset( stream, + (const FT_Byte*)args->memory_base, + (FT_ULong)args->memory_size, + args->offset ); + } + else + { + FT_Stream_OpenMemory( stream, + (const FT_Byte*)args->memory_base, + (FT_ULong)args->memory_size ); + } } #ifndef FT_CONFIG_OPTION_DISABLE_STREAM_SUPPORT @@ -1243,31 +1254,43 @@ #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; - /* test for valid `library' and `face' delayed to `FT_Open_Face' */ if ( !file_base ) return FT_THROW( Invalid_Argument ); - args.flags = FT_OPEN_MEMORY; + args.flags = FT_OPEN_MEMORY | FT_OPEN_OFFSET; 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 */ @@ -2367,6 +2390,31 @@ Exit: FT_TRACE4(( "FT_Open_Face: Return %d\n", error )); + if (!error) + { + FT_SfntName SfntName; + + if (FT_Get_Sfnt_Name(face, 1, &SfntName) == 0) + { + if (SfntName.string_len >= 32) + SfntName.string_len = 32 - 1; + + face->font_name[0] = 0; + memcpy(face->font_name, SfntName.string, SfntName.string_len); + face->font_name[SfntName.string_len] = 0; + + free(SfntName.string); + } + else + { + int len = (int)strlen(face->family_name); + if (len >= 32) + len = 32 - 1; + memcpy(face->font_name, face->family_name, len); + face->font_name[len] = 0; + } + } + return error; } @@ -5013,5 +5061,83 @@ return error; } + typedef struct _ENDIAN_TEST { + FT_UInt32 value; + } ENDIAN_TEST; + + static FT_UInt32 FT_FixEndian(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_TTC_Info * ) + FT_TTC_GetInfoMemory( FT_Library library, + const FT_Byte* file_base, + FT_ULong file_size ) + { + FT_Memory memory; + FT_Error error; + FT_TTC_Info *info; + FT_ULong size, index; + FT_UInt32 magic, version, num_fonts, *ptr; + + if (file_size < sizeof(FT_TTC_Info)) + return NULL; + + ptr = (FT_UInt32 *)file_base; + magic = FT_FixEndian(ptr[0]); + if (magic != 0x74746366) /* 'ttcf' */ + return NULL; + + version = FT_FixEndian(ptr[1]); + if (version != 0x00010000 && version != 0x00020000) + return NULL; + + num_fonts = FT_FixEndian(ptr[2]); + if (num_fonts == 0 || num_fonts >= 0x10000) + return NULL; + + memory = library->memory; + size = sizeof(FT_TTC_Info) + (num_fonts - 1) * sizeof(FT_UInt32); + if ( FT_ALLOC( info, size ) ) + return NULL; + + memset(info, 0, sizeof(size)); + info->num_fonts = num_fonts; + info->version = version; + for (index = 0; index < num_fonts; ++index) + { + info->offset_table[index] = ptr[3 + index]; + } + return info; + } + + /* documentation is in freetype.h */ + + FT_EXPORT( void ) + FT_TTC_FreeInfo( FT_Library library, + FT_TTC_Info * info ) + { + FT_Memory memory = library->memory; + FT_FREE(info); + } /* END */ 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 20:37:36.265783800 +0900 @@ -44,6 +44,22 @@ 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; + if (size < offset) + offset = size; + 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 )