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-29 09:54:26.231060900 +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 */ @@ -845,6 +846,7 @@ /*************************************************************************/ /*************************************************************************/ + #define FT_FACE_NAME_LEN_MAX 31 /*************************************************************************/ /* */ @@ -1084,6 +1086,8 @@ FT_Face_Internal internal; + char face_name[FT_FACE_NAME_LEN_MAX + 1]; + /*@private end */ } FT_FaceRec; @@ -1871,6 +1875,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 +1886,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 +1956,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 +1984,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 +1997,7 @@ FT_Module driver; FT_Int num_params; FT_Parameter* params; + FT_ULong offset; } FT_Open_Args; @@ -2061,6 +2074,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_ULong offset); + /*************************************************************************/ /* */ @@ -4206,7 +4260,7 @@ */ #define FREETYPE_MAJOR 2 #define FREETYPE_MINOR 7 -#define FREETYPE_PATCH 0 +#define FREETYPE_PATCH 1 /*************************************************************************/ @@ -4296,6 +4350,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/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-29 09:57:54.165239100 +0900 @@ -1,3 +1,4 @@ + /***************************************************************************/ /* */ /* ftobjs.c */ @@ -19,6 +20,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 @@ -190,6 +192,15 @@ FT_Stream_OpenMemory( stream, (const FT_Byte*)args->memory_base, (FT_ULong)args->memory_size ); + + /* move pos */ + if ( args->flags & FT_OPEN_OFFSET ) + { + if (args->offset <= stream->size) + stream->pos = args->offset; + else + stream->pos = stream->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_ULong 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,28 @@ 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 > FT_FACE_NAME_LEN_MAX) + SfntName.string_len = FT_FACE_NAME_LEN_MAX; + + memcpy(face->face_name, SfntName.string, SfntName.string_len); + face->face_name[SfntName.string_len] = 0; + } + else + { + int len = (int)strlen(face->family_name); + if (len > FT_FACE_NAME_LEN_MAX) + len = FT_FACE_NAME_LEN_MAX; + memcpy(face->face_name, face->family_name, len); + face->face_name[len] = 0; + } + } + return error; } @@ -5014,4 +5059,78 @@ } + static FT_UInt32 FT_FixEndian(FT_UInt32 value) + { + FT_UInt32 endian_test = 1; + FT_UInt32 new_value; + + if (*(char *)&endian_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 */