mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-19 04:26:52 -04:00
drop some stuff from freetype don't care about
This commit is contained in:
parent
4c63243c3b
commit
d14661c3e8
@ -29,7 +29,6 @@
|
||||
#include "freetype/ftobjs.c"
|
||||
#include "freetype/ftoutln.c"
|
||||
#include "freetype/ftpsprop.c"
|
||||
#include "freetype/ftrfork.c"
|
||||
#include "freetype/ftstream.c"
|
||||
#include "freetype/fttrigon.c"
|
||||
#include "freetype/ftutil.c"
|
||||
|
@ -27,49 +27,6 @@
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_MAC_FONTS
|
||||
|
||||
/* MacOS resource fork cannot exceed 16MB at least for Carbon code; */
|
||||
/* see https://support.microsoft.com/en-us/kb/130437 */
|
||||
#define FT_MAC_RFORK_MAX_LEN 0x00FFFFFFUL
|
||||
|
||||
|
||||
/* Assume the stream is sfnt-wrapped PS Type1 or sfnt-wrapped CID-keyed */
|
||||
/* font, and try to load a face specified by the face_index. */
|
||||
FT_LOCAL( FT_Error )
|
||||
open_face_PS_from_sfnt_stream( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_Int num_params,
|
||||
FT_Parameter *params,
|
||||
FT_Face *aface );
|
||||
|
||||
|
||||
/* Create a new FT_Face given a buffer and a driver name. */
|
||||
/* From ftmac.c. */
|
||||
FT_LOCAL( FT_Error )
|
||||
open_face_from_buffer( FT_Library library,
|
||||
FT_Byte* base,
|
||||
FT_ULong size,
|
||||
FT_Long face_index,
|
||||
const char* driver_name,
|
||||
FT_Face *aface );
|
||||
|
||||
|
||||
#if defined( FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK ) && \
|
||||
!defined( FT_MACINTOSH )
|
||||
/* Mac OS X/Darwin kernel often changes recommended method to access */
|
||||
/* the resource fork and older methods makes the kernel issue the */
|
||||
/* warning of deprecated method. To calm it down, the methods based */
|
||||
/* on Darwin VFS should be grouped and skip the rest methods after */
|
||||
/* the case the resource is opened but found to lack a font in it. */
|
||||
FT_LOCAL( FT_Bool )
|
||||
ft_raccess_rule_by_darwin_vfs( FT_Library library, FT_UInt rule_index );
|
||||
#endif
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_MAC_FONTS */
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTBASE_H_ */
|
||||
|
@ -121,161 +121,6 @@
|
||||
#endif
|
||||
|
||||
|
||||
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_GetFile_From_Mac_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
{
|
||||
FT_UNUSED( fontName );
|
||||
FT_UNUSED( pathSpec );
|
||||
FT_UNUSED( face_index );
|
||||
|
||||
return FT_THROW( Unimplemented_Feature );
|
||||
}
|
||||
|
||||
|
||||
/* Private function. */
|
||||
/* The FSSpec type has been discouraged for a long time, */
|
||||
/* unfortunately an FSRef replacement API for */
|
||||
/* ATSFontGetFileSpecification() is only available in */
|
||||
/* Mac OS X 10.5 and later. */
|
||||
static OSStatus
|
||||
FT_ATSFontGetFileReference( ATSFontRef ats_font_id,
|
||||
FSRef* ats_font_ref )
|
||||
{
|
||||
#if defined( MAC_OS_X_VERSION_10_5 ) && \
|
||||
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )
|
||||
|
||||
OSStatus err;
|
||||
|
||||
err = ATSFontGetFileReference( ats_font_id, ats_font_ref );
|
||||
|
||||
return err;
|
||||
#elif __LP64__ /* No 64bit Carbon API on legacy platforms */
|
||||
FT_UNUSED( ats_font_id );
|
||||
FT_UNUSED( ats_font_ref );
|
||||
|
||||
|
||||
return fnfErr;
|
||||
#else /* 32bit Carbon API on legacy platforms */
|
||||
OSStatus err;
|
||||
FSSpec spec;
|
||||
|
||||
|
||||
err = ATSFontGetFileSpecification( ats_font_id, &spec );
|
||||
if ( noErr == err )
|
||||
err = FSpMakeFSRef( &spec, ats_font_ref );
|
||||
|
||||
return err;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
FT_GetFileRef_From_Mac_ATS_Name( const char* fontName,
|
||||
FSRef* ats_font_ref,
|
||||
FT_Long* face_index )
|
||||
{
|
||||
CFStringRef cf_fontName;
|
||||
ATSFontRef ats_font_id;
|
||||
|
||||
|
||||
*face_index = 0;
|
||||
|
||||
cf_fontName = CFStringCreateWithCString( NULL, fontName,
|
||||
kCFStringEncodingMacRoman );
|
||||
ats_font_id = ATSFontFindFromName( cf_fontName,
|
||||
kATSOptionFlagsUnRestrictedScope );
|
||||
CFRelease( cf_fontName );
|
||||
|
||||
if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
/* face_index calculation by searching preceding fontIDs */
|
||||
/* with same FSRef */
|
||||
{
|
||||
ATSFontRef id2 = ats_font_id - 1;
|
||||
FSRef ref2;
|
||||
|
||||
|
||||
while ( id2 > 0 )
|
||||
{
|
||||
if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) )
|
||||
break;
|
||||
if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) )
|
||||
break;
|
||||
|
||||
id2 --;
|
||||
}
|
||||
*face_index = ats_font_id - ( id2 + 1 );
|
||||
}
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
|
||||
UInt8* path,
|
||||
UInt32 maxPathSize,
|
||||
FT_Long* face_index )
|
||||
{
|
||||
FSRef ref;
|
||||
FT_Error err;
|
||||
|
||||
|
||||
if ( !fontName || !face_index )
|
||||
return FT_THROW( Invalid_Argument);
|
||||
|
||||
err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
|
||||
if ( err )
|
||||
return err;
|
||||
|
||||
if ( noErr != FSRefMakePath( &ref, path, maxPathSize ) )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_GetFile_From_Mac_ATS_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
{
|
||||
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
|
||||
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
|
||||
FT_UNUSED( fontName );
|
||||
FT_UNUSED( pathSpec );
|
||||
FT_UNUSED( face_index );
|
||||
|
||||
return FT_THROW( Unimplemented_Feature );
|
||||
#else
|
||||
FSRef ref;
|
||||
FT_Error err;
|
||||
|
||||
|
||||
if ( !fontName || !face_index )
|
||||
return FT_THROW( Invalid_Argument );
|
||||
|
||||
err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
|
||||
if ( err )
|
||||
return err;
|
||||
|
||||
if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
|
||||
pathSpec, NULL ) )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
return FT_Err_Ok;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static OSErr
|
||||
FT_FSPathMakeRes( const UInt8* pathname,
|
||||
ResFileRefNum* res )
|
||||
@ -990,89 +835,6 @@
|
||||
return FT_Open_Face( library, args, face_index, aface );
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_New_Face_From_FSRef */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* FT_New_Face_From_FSRef is identical to FT_New_Face except it */
|
||||
/* accepts an FSRef instead of a path. */
|
||||
/* */
|
||||
/* This function is deprecated because Carbon data types (FSRef) */
|
||||
/* are not cross-platform, and thus not suitable for the FreeType API. */
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_New_Face_From_FSRef( FT_Library library,
|
||||
const FSRef* ref,
|
||||
FT_Long face_index,
|
||||
FT_Face* aface )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Open_Args args;
|
||||
|
||||
OSErr err;
|
||||
UInt8 pathname[PATH_MAX];
|
||||
|
||||
|
||||
/* check of `library' and `aface' delayed to */
|
||||
/* `FT_New_Face_From_Resource' */
|
||||
|
||||
if ( !ref )
|
||||
return FT_THROW( Invalid_Argument );
|
||||
|
||||
err = FSRefMakePath( ref, pathname, sizeof ( pathname ) );
|
||||
if ( err )
|
||||
error = FT_THROW( Cannot_Open_Resource );
|
||||
|
||||
error = FT_New_Face_From_Resource( library, pathname, face_index, aface );
|
||||
if ( error || *aface )
|
||||
return error;
|
||||
|
||||
/* fallback to datafork font */
|
||||
args.flags = FT_OPEN_PATHNAME;
|
||||
args.pathname = (char*)pathname;
|
||||
return FT_Open_Face( library, &args, face_index, aface );
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_New_Face_From_FSSpec */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* FT_New_Face_From_FSSpec is identical to FT_New_Face except it */
|
||||
/* accepts an FSSpec instead of a path. */
|
||||
/* */
|
||||
/* This function is deprecated because FSSpec is deprecated in Mac OS X */
|
||||
FT_EXPORT_DEF( FT_Error )
|
||||
FT_New_Face_From_FSSpec( FT_Library library,
|
||||
const FSSpec* spec,
|
||||
FT_Long face_index,
|
||||
FT_Face* aface )
|
||||
{
|
||||
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
|
||||
( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
|
||||
FT_UNUSED( library );
|
||||
FT_UNUSED( spec );
|
||||
FT_UNUSED( face_index );
|
||||
FT_UNUSED( aface );
|
||||
|
||||
return FT_THROW( Unimplemented_Feature );
|
||||
#else
|
||||
FSRef ref;
|
||||
|
||||
|
||||
/* check of `library' and `aface' delayed to `FT_New_Face_From_FSRef' */
|
||||
|
||||
if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )
|
||||
return FT_THROW( Invalid_Argument );
|
||||
else
|
||||
return FT_New_Face_From_FSRef( library, &ref, face_index, aface );
|
||||
#endif
|
||||
}
|
||||
|
||||
#else /* !FT_MACINTOSH */
|
||||
|
||||
/* ANSI C doesn't like empty source files */
|
||||
|
@ -103,166 +103,6 @@ FT_BEGIN_HEADER
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_GetFile_From_Mac_Name */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Return an FSSpec for the disk file containing the named font. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* fontName :: Mac OS name of the font (e.g., Times New Roman */
|
||||
/* Bold). */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* pathSpec :: FSSpec to the file. For passing to */
|
||||
/* @FT_New_Face_From_FSSpec. */
|
||||
/* */
|
||||
/* face_index :: Index of the face. For passing to */
|
||||
/* @FT_New_Face_From_FSSpec. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. 0~means success. */
|
||||
/* */
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFile_From_Mac_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_GetFile_From_Mac_ATS_Name */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Return an FSSpec for the disk file containing the named font. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* fontName :: Mac OS name of the font in ATS framework. */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* pathSpec :: FSSpec to the file. For passing to */
|
||||
/* @FT_New_Face_From_FSSpec. */
|
||||
/* */
|
||||
/* face_index :: Index of the face. For passing to */
|
||||
/* @FT_New_Face_From_FSSpec. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. 0~means success. */
|
||||
/* */
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFile_From_Mac_ATS_Name( const char* fontName,
|
||||
FSSpec* pathSpec,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_GetFilePath_From_Mac_ATS_Name */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Return a pathname of the disk file and face index for given font */
|
||||
/* name that is handled by ATS framework. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* fontName :: Mac OS name of the font in ATS framework. */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* path :: Buffer to store pathname of the file. For passing */
|
||||
/* to @FT_New_Face. The client must allocate this */
|
||||
/* buffer before calling this function. */
|
||||
/* */
|
||||
/* maxPathSize :: Lengths of the buffer `path' that client allocated. */
|
||||
/* */
|
||||
/* face_index :: Index of the face. For passing to @FT_New_Face. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. 0~means success. */
|
||||
/* */
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_GetFilePath_From_Mac_ATS_Name( const char* fontName,
|
||||
UInt8* path,
|
||||
UInt32 maxPathSize,
|
||||
FT_Long* face_index )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_New_Face_From_FSSpec */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Create a new face object from a given resource and typeface index */
|
||||
/* using an FSSpec to the font file. */
|
||||
/* */
|
||||
/* <InOut> */
|
||||
/* library :: A handle to the library resource. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* spec :: FSSpec to the font file. */
|
||||
/* */
|
||||
/* face_index :: The index of the face within the resource. The */
|
||||
/* first face has index~0. */
|
||||
/* <Output> */
|
||||
/* aface :: A handle to a new face object. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. 0~means success. */
|
||||
/* */
|
||||
/* <Note> */
|
||||
/* @FT_New_Face_From_FSSpec is identical to @FT_New_Face except */
|
||||
/* it accepts an FSSpec instead of a path. */
|
||||
/* */
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Face_From_FSSpec( FT_Library library,
|
||||
const FSSpec *spec,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_New_Face_From_FSRef */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Create a new face object from a given resource and typeface index */
|
||||
/* using an FSRef to the font file. */
|
||||
/* */
|
||||
/* <InOut> */
|
||||
/* library :: A handle to the library resource. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* spec :: FSRef to the font file. */
|
||||
/* */
|
||||
/* face_index :: The index of the face within the resource. The */
|
||||
/* first face has index~0. */
|
||||
/* <Output> */
|
||||
/* aface :: A handle to a new face object. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. 0~means success. */
|
||||
/* */
|
||||
/* <Note> */
|
||||
/* @FT_New_Face_From_FSRef is identical to @FT_New_Face except */
|
||||
/* it accepts an FSRef instead of a path. */
|
||||
/* */
|
||||
FT_EXPORT( FT_Error )
|
||||
FT_New_Face_From_FSRef( FT_Library library,
|
||||
const FSRef *ref,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
FT_DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/* */
|
||||
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include FT_INTERNAL_VALIDATE_H
|
||||
#include FT_INTERNAL_OBJECTS_H
|
||||
#include FT_INTERNAL_DEBUG_H
|
||||
#include FT_INTERNAL_RFORK_H
|
||||
#include FT_INTERNAL_STREAM_H
|
||||
#include FT_INTERNAL_SFNT_H /* for SFNT_Load_Table_Func */
|
||||
#include FT_INTERNAL_POSTSCRIPT_AUX_H /* for PS_Driver */
|
||||
@ -43,10 +42,6 @@
|
||||
|
||||
#include FT_DRIVER_H
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_MAC_FONTS
|
||||
#include "ftbase.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef FT_DEBUG_LEVEL_TRACE
|
||||
|
||||
@ -1395,866 +1390,6 @@
|
||||
}
|
||||
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_MAC_FONTS
|
||||
|
||||
/* The behavior here is very similar to that in base/ftmac.c, but it */
|
||||
/* is designed to work on non-mac systems, so no mac specific calls. */
|
||||
/* */
|
||||
/* We look at the file and determine if it is a mac dfont file or a mac */
|
||||
/* resource file, or a macbinary file containing a mac resource file. */
|
||||
/* */
|
||||
/* Unlike ftmac I'm not going to look at a `FOND'. I don't really see */
|
||||
/* the point, especially since there may be multiple `FOND' resources. */
|
||||
/* Instead I'll just look for `sfnt' and `POST' resources, ordered as */
|
||||
/* they occur in the file. */
|
||||
/* */
|
||||
/* Note that multiple `POST' resources do not mean multiple postscript */
|
||||
/* fonts; they all get jammed together to make what is essentially a */
|
||||
/* pfb file. */
|
||||
/* */
|
||||
/* We aren't interested in `NFNT' or `FONT' bitmap resources. */
|
||||
/* */
|
||||
/* As soon as we get an `sfnt' load it into memory and pass it off to */
|
||||
/* FT_Open_Face. */
|
||||
/* */
|
||||
/* If we have a (set of) `POST' resources, massage them into a (memory) */
|
||||
/* pfb file and pass that to FT_Open_Face. (As with ftmac.c I'm not */
|
||||
/* going to try to save the kerning info. After all that lives in the */
|
||||
/* `FOND' which isn't in the file containing the `POST' resources so */
|
||||
/* we don't really have access to it. */
|
||||
|
||||
|
||||
/* Finalizer for a memory stream; gets called by FT_Done_Face(). */
|
||||
/* It frees the memory it uses. */
|
||||
/* From `ftmac.c'. */
|
||||
static void
|
||||
memory_stream_close( FT_Stream stream )
|
||||
{
|
||||
FT_Memory memory = stream->memory;
|
||||
|
||||
|
||||
FT_FREE( stream->base );
|
||||
|
||||
stream->size = 0;
|
||||
stream->base = NULL;
|
||||
stream->close = NULL;
|
||||
}
|
||||
|
||||
|
||||
/* Create a new memory stream from a buffer and a size. */
|
||||
/* From `ftmac.c'. */
|
||||
static FT_Error
|
||||
new_memory_stream( FT_Library library,
|
||||
FT_Byte* base,
|
||||
FT_ULong size,
|
||||
FT_Stream_CloseFunc close,
|
||||
FT_Stream *astream )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Memory memory;
|
||||
FT_Stream stream = NULL;
|
||||
|
||||
|
||||
if ( !library )
|
||||
return FT_THROW( Invalid_Library_Handle );
|
||||
|
||||
if ( !base )
|
||||
return FT_THROW( Invalid_Argument );
|
||||
|
||||
*astream = NULL;
|
||||
memory = library->memory;
|
||||
if ( FT_NEW( stream ) )
|
||||
goto Exit;
|
||||
|
||||
FT_Stream_OpenMemory( stream, base, size );
|
||||
|
||||
stream->close = close;
|
||||
|
||||
*astream = stream;
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* Create a new FT_Face given a buffer and a driver name. */
|
||||
/* From `ftmac.c'. */
|
||||
FT_LOCAL_DEF( FT_Error )
|
||||
open_face_from_buffer( FT_Library library,
|
||||
FT_Byte* base,
|
||||
FT_ULong size,
|
||||
FT_Long face_index,
|
||||
const char* driver_name,
|
||||
FT_Face *aface )
|
||||
{
|
||||
FT_Open_Args args;
|
||||
FT_Error error;
|
||||
FT_Stream stream = NULL;
|
||||
FT_Memory memory = library->memory;
|
||||
|
||||
|
||||
error = new_memory_stream( library,
|
||||
base,
|
||||
size,
|
||||
memory_stream_close,
|
||||
&stream );
|
||||
if ( error )
|
||||
{
|
||||
FT_FREE( base );
|
||||
return error;
|
||||
}
|
||||
|
||||
args.flags = FT_OPEN_STREAM;
|
||||
args.stream = stream;
|
||||
if ( driver_name )
|
||||
{
|
||||
args.flags = args.flags | FT_OPEN_DRIVER;
|
||||
args.driver = FT_Get_Module( library, driver_name );
|
||||
}
|
||||
|
||||
#ifdef FT_MACINTOSH
|
||||
/* At this point, the face index has served its purpose; */
|
||||
/* whoever calls this function has already used it to */
|
||||
/* locate the correct font data. We should not propagate */
|
||||
/* this index to FT_Open_Face() (unless it is negative). */
|
||||
|
||||
if ( face_index > 0 )
|
||||
face_index &= 0x7FFF0000L; /* retain GX data */
|
||||
#endif
|
||||
|
||||
error = ft_open_face_internal( library, &args, face_index, aface, 0 );
|
||||
|
||||
if ( !error )
|
||||
(*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM;
|
||||
else
|
||||
#ifdef FT_MACINTOSH
|
||||
FT_Stream_Free( stream, 0 );
|
||||
#else
|
||||
{
|
||||
FT_Stream_Close( stream );
|
||||
FT_FREE( stream );
|
||||
}
|
||||
#endif
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* Look up `TYP1' or `CID ' table from sfnt table directory. */
|
||||
/* `offset' and `length' must exclude the binary header in tables. */
|
||||
|
||||
/* Type 1 and CID-keyed font drivers should recognize sfnt-wrapped */
|
||||
/* format too. Here, since we can't expect that the TrueType font */
|
||||
/* driver is loaded unconditionally, we must parse the font by */
|
||||
/* ourselves. We are only interested in the name of the table and */
|
||||
/* the offset. */
|
||||
|
||||
static FT_Error
|
||||
ft_lookup_PS_in_sfnt_stream( FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_ULong* offset,
|
||||
FT_ULong* length,
|
||||
FT_Bool* is_sfnt_cid )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_UShort numTables;
|
||||
FT_Long pstable_index;
|
||||
FT_ULong tag;
|
||||
int i;
|
||||
|
||||
|
||||
*offset = 0;
|
||||
*length = 0;
|
||||
*is_sfnt_cid = FALSE;
|
||||
|
||||
/* TODO: support for sfnt-wrapped PS/CID in TTC format */
|
||||
|
||||
/* version check for 'typ1' (should be ignored?) */
|
||||
if ( FT_READ_ULONG( tag ) )
|
||||
return error;
|
||||
if ( tag != TTAG_typ1 )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
if ( FT_READ_USHORT( numTables ) )
|
||||
return error;
|
||||
if ( FT_STREAM_SKIP( 2 * 3 ) ) /* skip binary search header */
|
||||
return error;
|
||||
|
||||
pstable_index = -1;
|
||||
*is_sfnt_cid = FALSE;
|
||||
|
||||
for ( i = 0; i < numTables; i++ )
|
||||
{
|
||||
if ( FT_READ_ULONG( tag ) || FT_STREAM_SKIP( 4 ) ||
|
||||
FT_READ_ULONG( *offset ) || FT_READ_ULONG( *length ) )
|
||||
return error;
|
||||
|
||||
if ( tag == TTAG_CID )
|
||||
{
|
||||
pstable_index++;
|
||||
*offset += 22;
|
||||
*length -= 22;
|
||||
*is_sfnt_cid = TRUE;
|
||||
if ( face_index < 0 )
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
else if ( tag == TTAG_TYP1 )
|
||||
{
|
||||
pstable_index++;
|
||||
*offset += 24;
|
||||
*length -= 24;
|
||||
*is_sfnt_cid = FALSE;
|
||||
if ( face_index < 0 )
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
if ( face_index >= 0 && pstable_index == face_index )
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
return FT_THROW( Table_Missing );
|
||||
}
|
||||
|
||||
|
||||
FT_LOCAL_DEF( FT_Error )
|
||||
open_face_PS_from_sfnt_stream( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_Int num_params,
|
||||
FT_Parameter *params,
|
||||
FT_Face *aface )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_Memory memory = library->memory;
|
||||
FT_ULong offset, length;
|
||||
FT_ULong pos;
|
||||
FT_Bool is_sfnt_cid;
|
||||
FT_Byte* sfnt_ps = NULL;
|
||||
|
||||
FT_UNUSED( num_params );
|
||||
FT_UNUSED( params );
|
||||
|
||||
|
||||
/* ignore GX stuff */
|
||||
if ( face_index > 0 )
|
||||
face_index &= 0xFFFFL;
|
||||
|
||||
pos = FT_STREAM_POS();
|
||||
|
||||
error = ft_lookup_PS_in_sfnt_stream( stream,
|
||||
face_index,
|
||||
&offset,
|
||||
&length,
|
||||
&is_sfnt_cid );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
if ( offset > stream->size )
|
||||
{
|
||||
FT_TRACE2(( "open_face_PS_from_sfnt_stream: invalid table offset\n" ));
|
||||
error = FT_THROW( Invalid_Table );
|
||||
goto Exit;
|
||||
}
|
||||
else if ( length > stream->size - offset )
|
||||
{
|
||||
FT_TRACE2(( "open_face_PS_from_sfnt_stream: invalid table length\n" ));
|
||||
error = FT_THROW( Invalid_Table );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
error = FT_Stream_Seek( stream, pos + offset );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
if ( FT_ALLOC( sfnt_ps, (FT_Long)length ) )
|
||||
goto Exit;
|
||||
|
||||
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_ps, length );
|
||||
if ( error )
|
||||
{
|
||||
FT_FREE( sfnt_ps );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
error = open_face_from_buffer( library,
|
||||
sfnt_ps,
|
||||
length,
|
||||
FT_MIN( face_index, 0 ),
|
||||
is_sfnt_cid ? "cid" : "type1",
|
||||
aface );
|
||||
Exit:
|
||||
{
|
||||
FT_Error error1;
|
||||
|
||||
|
||||
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
|
||||
{
|
||||
error1 = FT_Stream_Seek( stream, pos );
|
||||
if ( error1 )
|
||||
return error1;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef FT_MACINTOSH
|
||||
|
||||
/* The resource header says we've got resource_cnt `POST' (type1) */
|
||||
/* resources in this file. They all need to be coalesced into */
|
||||
/* one lump which gets passed on to the type1 driver. */
|
||||
/* Here can be only one PostScript font in a file so face_index */
|
||||
/* must be 0 (or -1). */
|
||||
/* */
|
||||
static FT_Error
|
||||
Mac_Read_POST_Resource( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long *offsets,
|
||||
FT_Long resource_cnt,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
{
|
||||
FT_Error error = FT_ERR( Cannot_Open_Resource );
|
||||
FT_Memory memory = library->memory;
|
||||
|
||||
FT_Byte* pfb_data = NULL;
|
||||
int i, type, flags;
|
||||
FT_ULong len;
|
||||
FT_ULong pfb_len, pfb_pos, pfb_lenpos;
|
||||
FT_ULong rlen, temp;
|
||||
|
||||
|
||||
if ( face_index == -1 )
|
||||
face_index = 0;
|
||||
if ( face_index != 0 )
|
||||
return error;
|
||||
|
||||
/* Find the length of all the POST resources, concatenated. Assume */
|
||||
/* worst case (each resource in its own section). */
|
||||
pfb_len = 0;
|
||||
for ( i = 0; i < resource_cnt; i++ )
|
||||
{
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
if ( FT_READ_ULONG( temp ) ) /* actually LONG */
|
||||
goto Exit;
|
||||
|
||||
/* FT2 allocator takes signed long buffer length,
|
||||
* too large value causing overflow should be checked
|
||||
*/
|
||||
FT_TRACE4(( " POST fragment #%d: length=0x%08x"
|
||||
" total pfb_len=0x%08x\n",
|
||||
i, temp, pfb_len + temp + 6 ));
|
||||
|
||||
if ( FT_MAC_RFORK_MAX_LEN < temp ||
|
||||
FT_MAC_RFORK_MAX_LEN - temp < pfb_len + 6 )
|
||||
{
|
||||
FT_TRACE2(( " MacOS resource length cannot exceed"
|
||||
" 0x%08x\n",
|
||||
FT_MAC_RFORK_MAX_LEN ));
|
||||
|
||||
error = FT_THROW( Invalid_Offset );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
pfb_len += temp + 6;
|
||||
}
|
||||
|
||||
FT_TRACE2(( " total buffer size to concatenate"
|
||||
" %d POST fragments: 0x%08x\n",
|
||||
resource_cnt, pfb_len + 2 ));
|
||||
|
||||
if ( pfb_len + 2 < 6 )
|
||||
{
|
||||
FT_TRACE2(( " too long fragment length makes"
|
||||
" pfb_len confused: pfb_len=0x%08x\n",
|
||||
pfb_len ));
|
||||
|
||||
error = FT_THROW( Array_Too_Large );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if ( FT_ALLOC( pfb_data, (FT_Long)pfb_len + 2 ) )
|
||||
goto Exit;
|
||||
|
||||
pfb_data[0] = 0x80;
|
||||
pfb_data[1] = 1; /* Ascii section */
|
||||
pfb_data[2] = 0; /* 4-byte length, fill in later */
|
||||
pfb_data[3] = 0;
|
||||
pfb_data[4] = 0;
|
||||
pfb_data[5] = 0;
|
||||
pfb_pos = 6;
|
||||
pfb_lenpos = 2;
|
||||
|
||||
len = 0;
|
||||
type = 1;
|
||||
|
||||
for ( i = 0; i < resource_cnt; i++ )
|
||||
{
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)offsets[i] );
|
||||
if ( error )
|
||||
goto Exit2;
|
||||
if ( FT_READ_ULONG( rlen ) )
|
||||
goto Exit2;
|
||||
|
||||
/* FT2 allocator takes signed long buffer length,
|
||||
* too large fragment length causing overflow should be checked
|
||||
*/
|
||||
if ( 0x7FFFFFFFUL < rlen )
|
||||
{
|
||||
error = FT_THROW( Invalid_Offset );
|
||||
goto Exit2;
|
||||
}
|
||||
|
||||
if ( FT_READ_USHORT( flags ) )
|
||||
goto Exit2;
|
||||
|
||||
FT_TRACE3(( "POST fragment[%d]:"
|
||||
" offsets=0x%08x, rlen=0x%08x, flags=0x%04x\n",
|
||||
i, offsets[i], rlen, flags ));
|
||||
|
||||
error = FT_ERR( Array_Too_Large );
|
||||
|
||||
/* postpone the check of `rlen longer than buffer' */
|
||||
/* until `FT_Stream_Read' */
|
||||
|
||||
if ( ( flags >> 8 ) == 0 ) /* Comment, should not be loaded */
|
||||
{
|
||||
FT_TRACE3(( " Skip POST fragment #%d because it is a comment\n",
|
||||
i ));
|
||||
continue;
|
||||
}
|
||||
|
||||
/* the flags are part of the resource, so rlen >= 2, */
|
||||
/* but some fonts declare rlen = 0 for empty fragment */
|
||||
if ( rlen > 2 )
|
||||
rlen -= 2;
|
||||
else
|
||||
rlen = 0;
|
||||
|
||||
if ( ( flags >> 8 ) == type )
|
||||
len += rlen;
|
||||
else
|
||||
{
|
||||
FT_TRACE3(( " Write POST fragment #%d header (4-byte) to buffer"
|
||||
" %p + 0x%08x\n",
|
||||
i, pfb_data, pfb_lenpos ));
|
||||
|
||||
if ( pfb_lenpos + 3 > pfb_len + 2 )
|
||||
goto Exit2;
|
||||
|
||||
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
|
||||
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
|
||||
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
|
||||
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
|
||||
|
||||
if ( ( flags >> 8 ) == 5 ) /* End of font mark */
|
||||
break;
|
||||
|
||||
FT_TRACE3(( " Write POST fragment #%d header (6-byte) to buffer"
|
||||
" %p + 0x%08x\n",
|
||||
i, pfb_data, pfb_pos ));
|
||||
|
||||
if ( pfb_pos + 6 > pfb_len + 2 )
|
||||
goto Exit2;
|
||||
|
||||
pfb_data[pfb_pos++] = 0x80;
|
||||
|
||||
type = flags >> 8;
|
||||
len = rlen;
|
||||
|
||||
pfb_data[pfb_pos++] = (FT_Byte)type;
|
||||
pfb_lenpos = pfb_pos;
|
||||
pfb_data[pfb_pos++] = 0; /* 4-byte length, fill in later */
|
||||
pfb_data[pfb_pos++] = 0;
|
||||
pfb_data[pfb_pos++] = 0;
|
||||
pfb_data[pfb_pos++] = 0;
|
||||
}
|
||||
|
||||
if ( pfb_pos > pfb_len || pfb_pos + rlen > pfb_len )
|
||||
goto Exit2;
|
||||
|
||||
FT_TRACE3(( " Load POST fragment #%d (%d byte) to buffer"
|
||||
" %p + 0x%08x\n",
|
||||
i, rlen, pfb_data, pfb_pos ));
|
||||
|
||||
error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen );
|
||||
if ( error )
|
||||
goto Exit2;
|
||||
|
||||
pfb_pos += rlen;
|
||||
}
|
||||
|
||||
error = FT_ERR( Array_Too_Large );
|
||||
|
||||
if ( pfb_pos + 2 > pfb_len + 2 )
|
||||
goto Exit2;
|
||||
pfb_data[pfb_pos++] = 0x80;
|
||||
pfb_data[pfb_pos++] = 3;
|
||||
|
||||
if ( pfb_lenpos + 3 > pfb_len + 2 )
|
||||
goto Exit2;
|
||||
pfb_data[pfb_lenpos ] = (FT_Byte)( len );
|
||||
pfb_data[pfb_lenpos + 1] = (FT_Byte)( len >> 8 );
|
||||
pfb_data[pfb_lenpos + 2] = (FT_Byte)( len >> 16 );
|
||||
pfb_data[pfb_lenpos + 3] = (FT_Byte)( len >> 24 );
|
||||
|
||||
return open_face_from_buffer( library,
|
||||
pfb_data,
|
||||
pfb_pos,
|
||||
face_index,
|
||||
"type1",
|
||||
aface );
|
||||
|
||||
Exit2:
|
||||
if ( FT_ERR_EQ( error, Array_Too_Large ) )
|
||||
FT_TRACE2(( " Abort due to too-short buffer to store"
|
||||
" all POST fragments\n" ));
|
||||
else if ( FT_ERR_EQ( error, Invalid_Offset ) )
|
||||
FT_TRACE2(( " Abort due to invalid offset in a POST fragment\n" ));
|
||||
|
||||
if ( error )
|
||||
error = FT_ERR( Cannot_Open_Resource );
|
||||
FT_FREE( pfb_data );
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* The resource header says we've got resource_cnt `sfnt' */
|
||||
/* (TrueType/OpenType) resources in this file. Look through */
|
||||
/* them for the one indicated by face_index, load it into mem, */
|
||||
/* pass it on to the truetype driver, and return it. */
|
||||
/* */
|
||||
static FT_Error
|
||||
Mac_Read_sfnt_Resource( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long *offsets,
|
||||
FT_Long resource_cnt,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
{
|
||||
FT_Memory memory = library->memory;
|
||||
FT_Byte* sfnt_data = NULL;
|
||||
FT_Error error;
|
||||
FT_ULong flag_offset;
|
||||
FT_Long rlen;
|
||||
int is_cff;
|
||||
FT_Long face_index_in_resource = 0;
|
||||
|
||||
|
||||
if ( face_index < 0 )
|
||||
face_index = -face_index - 1;
|
||||
if ( face_index >= resource_cnt )
|
||||
return FT_THROW( Cannot_Open_Resource );
|
||||
|
||||
flag_offset = (FT_ULong)offsets[face_index];
|
||||
error = FT_Stream_Seek( stream, flag_offset );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
if ( FT_READ_LONG( rlen ) )
|
||||
goto Exit;
|
||||
if ( rlen < 1 )
|
||||
return FT_THROW( Cannot_Open_Resource );
|
||||
if ( (FT_ULong)rlen > FT_MAC_RFORK_MAX_LEN )
|
||||
return FT_THROW( Invalid_Offset );
|
||||
|
||||
error = open_face_PS_from_sfnt_stream( library,
|
||||
stream,
|
||||
face_index,
|
||||
0, NULL,
|
||||
aface );
|
||||
if ( !error )
|
||||
goto Exit;
|
||||
|
||||
/* rewind sfnt stream before open_face_PS_from_sfnt_stream() */
|
||||
error = FT_Stream_Seek( stream, flag_offset + 4 );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
if ( FT_ALLOC( sfnt_data, rlen ) )
|
||||
return error;
|
||||
error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, (FT_ULong)rlen );
|
||||
if ( error ) {
|
||||
FT_FREE( sfnt_data );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
is_cff = rlen > 4 && !ft_memcmp( sfnt_data, "OTTO", 4 );
|
||||
error = open_face_from_buffer( library,
|
||||
sfnt_data,
|
||||
(FT_ULong)rlen,
|
||||
face_index_in_resource,
|
||||
is_cff ? "cff" : "truetype",
|
||||
aface );
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* Check for a valid resource fork header, or a valid dfont */
|
||||
/* header. In a resource fork the first 16 bytes are repeated */
|
||||
/* at the location specified by bytes 4-7. In a dfont bytes */
|
||||
/* 4-7 point to 16 bytes of zeroes instead. */
|
||||
/* */
|
||||
static FT_Error
|
||||
IsMacResource( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long resource_offset,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
{
|
||||
FT_Memory memory = library->memory;
|
||||
FT_Error error;
|
||||
FT_Long map_offset, rdata_pos;
|
||||
FT_Long *data_offsets;
|
||||
FT_Long count;
|
||||
|
||||
|
||||
error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset,
|
||||
&map_offset, &rdata_pos );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
/* POST resources must be sorted to concatenate properly */
|
||||
error = FT_Raccess_Get_DataOffsets( library, stream,
|
||||
map_offset, rdata_pos,
|
||||
TTAG_POST, TRUE,
|
||||
&data_offsets, &count );
|
||||
if ( !error )
|
||||
{
|
||||
error = Mac_Read_POST_Resource( library, stream, data_offsets, count,
|
||||
face_index, aface );
|
||||
FT_FREE( data_offsets );
|
||||
/* POST exists in an LWFN providing a single face */
|
||||
if ( !error )
|
||||
(*aface)->num_faces = 1;
|
||||
return error;
|
||||
}
|
||||
|
||||
/* sfnt resources should not be sorted to preserve the face order by
|
||||
QuickDraw API */
|
||||
error = FT_Raccess_Get_DataOffsets( library, stream,
|
||||
map_offset, rdata_pos,
|
||||
TTAG_sfnt, FALSE,
|
||||
&data_offsets, &count );
|
||||
if ( !error )
|
||||
{
|
||||
FT_Long face_index_internal = face_index % count;
|
||||
|
||||
|
||||
error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count,
|
||||
face_index_internal, aface );
|
||||
FT_FREE( data_offsets );
|
||||
if ( !error )
|
||||
(*aface)->num_faces = count;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/* Check for a valid macbinary header, and if we find one */
|
||||
/* check that the (flattened) resource fork in it is valid. */
|
||||
/* */
|
||||
static FT_Error
|
||||
IsMacBinary( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface )
|
||||
{
|
||||
unsigned char header[128];
|
||||
FT_Error error;
|
||||
FT_Long dlen, offset;
|
||||
|
||||
|
||||
if ( !stream )
|
||||
return FT_THROW( Invalid_Stream_Operation );
|
||||
|
||||
error = FT_Stream_Seek( stream, 0 );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
error = FT_Stream_Read( stream, (FT_Byte*)header, 128 );
|
||||
if ( error )
|
||||
goto Exit;
|
||||
|
||||
if ( header[ 0] != 0 ||
|
||||
header[74] != 0 ||
|
||||
header[82] != 0 ||
|
||||
header[ 1] == 0 ||
|
||||
header[ 1] > 33 ||
|
||||
header[63] != 0 ||
|
||||
header[2 + header[1]] != 0 ||
|
||||
header[0x53] > 0x7F )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
dlen = ( header[0x53] << 24 ) |
|
||||
( header[0x54] << 16 ) |
|
||||
( header[0x55] << 8 ) |
|
||||
header[0x56];
|
||||
#if 0
|
||||
rlen = ( header[0x57] << 24 ) |
|
||||
( header[0x58] << 16 ) |
|
||||
( header[0x59] << 8 ) |
|
||||
header[0x5A];
|
||||
#endif /* 0 */
|
||||
offset = 128 + ( ( dlen + 127 ) & ~127 );
|
||||
|
||||
return IsMacResource( library, stream, offset, face_index, aface );
|
||||
|
||||
Exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
load_face_in_embedded_rfork( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface,
|
||||
const FT_Open_Args *args )
|
||||
{
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_raccess
|
||||
|
||||
FT_Memory memory = library->memory;
|
||||
FT_Error error = FT_ERR( Unknown_File_Format );
|
||||
FT_UInt i;
|
||||
|
||||
char * file_names[FT_RACCESS_N_RULES];
|
||||
FT_Long offsets[FT_RACCESS_N_RULES];
|
||||
FT_Error errors[FT_RACCESS_N_RULES];
|
||||
FT_Bool is_darwin_vfs, vfs_rfork_has_no_font = FALSE; /* not tested */
|
||||
|
||||
FT_Open_Args args2;
|
||||
FT_Stream stream2 = NULL;
|
||||
|
||||
|
||||
FT_Raccess_Guess( library, stream,
|
||||
args->pathname, file_names, offsets, errors );
|
||||
|
||||
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
|
||||
{
|
||||
is_darwin_vfs = ft_raccess_rule_by_darwin_vfs( library, i );
|
||||
if ( is_darwin_vfs && vfs_rfork_has_no_font )
|
||||
{
|
||||
FT_TRACE3(( "Skip rule %d: darwin vfs resource fork"
|
||||
" is already checked and"
|
||||
" no font is found\n",
|
||||
i ));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( errors[i] )
|
||||
{
|
||||
FT_TRACE3(( "Error 0x%x has occurred in rule %d\n",
|
||||
errors[i], i ));
|
||||
continue;
|
||||
}
|
||||
|
||||
args2.flags = FT_OPEN_PATHNAME;
|
||||
args2.pathname = file_names[i] ? file_names[i] : args->pathname;
|
||||
|
||||
FT_TRACE3(( "Try rule %d: %s (offset=%d) ...",
|
||||
i, args2.pathname, offsets[i] ));
|
||||
|
||||
error = FT_Stream_New( library, &args2, &stream2 );
|
||||
if ( is_darwin_vfs && FT_ERR_EQ( error, Cannot_Open_Stream ) )
|
||||
vfs_rfork_has_no_font = TRUE;
|
||||
|
||||
if ( error )
|
||||
{
|
||||
FT_TRACE3(( "failed\n" ));
|
||||
continue;
|
||||
}
|
||||
|
||||
error = IsMacResource( library, stream2, offsets[i],
|
||||
face_index, aface );
|
||||
FT_Stream_Free( stream2, 0 );
|
||||
|
||||
FT_TRACE3(( "%s\n", error ? "failed": "successful" ));
|
||||
|
||||
if ( !error )
|
||||
break;
|
||||
else if ( is_darwin_vfs )
|
||||
vfs_rfork_has_no_font = TRUE;
|
||||
}
|
||||
|
||||
for (i = 0; i < FT_RACCESS_N_RULES; i++)
|
||||
{
|
||||
if ( file_names[i] )
|
||||
FT_FREE( file_names[i] );
|
||||
}
|
||||
|
||||
/* Caller (load_mac_face) requires FT_Err_Unknown_File_Format. */
|
||||
if ( error )
|
||||
error = FT_ERR( Unknown_File_Format );
|
||||
|
||||
return error;
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_objs
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Check for some macintosh formats without Carbon framework. */
|
||||
/* Is this a macbinary file? If so look at the resource fork. */
|
||||
/* Is this a mac dfont file? */
|
||||
/* Is this an old style resource fork? (in data) */
|
||||
/* Else call load_face_in_embedded_rfork to try extra rules */
|
||||
/* (defined in `ftrfork.c'). */
|
||||
/* */
|
||||
static FT_Error
|
||||
load_mac_face( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long face_index,
|
||||
FT_Face *aface,
|
||||
const FT_Open_Args *args )
|
||||
{
|
||||
FT_Error error;
|
||||
FT_UNUSED( args );
|
||||
|
||||
error = IsMacBinary( library, stream, face_index, aface );
|
||||
if ( FT_ERR_EQ( error, Unknown_File_Format ) )
|
||||
{
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_raccess
|
||||
|
||||
#ifdef FT_DEBUG_LEVEL_TRACE
|
||||
FT_TRACE3(( "Try as dfont: " ));
|
||||
if ( !( args->flags & FT_OPEN_MEMORY ) )
|
||||
FT_TRACE3(( "%s ...", args->pathname ));
|
||||
#endif
|
||||
|
||||
error = IsMacResource( library, stream, 0, face_index, aface );
|
||||
|
||||
FT_TRACE3(( "%s\n", error ? "failed" : "successful" ));
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_objs
|
||||
|
||||
}
|
||||
|
||||
if ( ( FT_ERR_EQ( error, Unknown_File_Format ) ||
|
||||
FT_ERR_EQ( error, Invalid_Stream_Operation ) ) &&
|
||||
( args->flags & FT_OPEN_PATHNAME ) )
|
||||
error = load_face_in_embedded_rfork( library, stream,
|
||||
face_index, aface, args );
|
||||
return error;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
|
||||
|
||||
|
||||
/* documentation is in freetype.h */
|
||||
|
||||
#ifndef FT_MACINTOSH
|
||||
@ -2295,9 +1430,7 @@
|
||||
FT_Module* cur;
|
||||
FT_Module* limit;
|
||||
|
||||
#ifndef FT_CONFIG_OPTION_MAC_FONTS
|
||||
FT_UNUSED( test_mac_fonts );
|
||||
#endif
|
||||
|
||||
/* test for valid `library' delayed to `FT_Stream_New' */
|
||||
|
||||
@ -2374,30 +1507,6 @@
|
||||
if ( !error )
|
||||
goto Success;
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_MAC_FONTS
|
||||
if ( test_mac_fonts &&
|
||||
ft_strcmp( cur[0]->clazz->module_name, "truetype" ) == 0 &&
|
||||
FT_ERR_EQ( error, Table_Missing ) )
|
||||
{
|
||||
/* TrueType but essential tables are missing */
|
||||
error = FT_Stream_Seek( stream, 0 );
|
||||
if ( error )
|
||||
break;
|
||||
|
||||
error = open_face_PS_from_sfnt_stream( library,
|
||||
stream,
|
||||
face_index,
|
||||
num_params,
|
||||
params,
|
||||
aface );
|
||||
if ( !error )
|
||||
{
|
||||
FT_Stream_Free( stream, external_stream );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
|
||||
goto Fail3;
|
||||
}
|
||||
@ -2412,27 +1521,6 @@
|
||||
FT_ERR_NEQ( error, Invalid_Stream_Operation ) )
|
||||
goto Fail2;
|
||||
|
||||
#if !defined( FT_MACINTOSH ) && defined( FT_CONFIG_OPTION_MAC_FONTS )
|
||||
if ( test_mac_fonts )
|
||||
{
|
||||
error = load_mac_face( library, stream, face_index, aface, args );
|
||||
if ( !error )
|
||||
{
|
||||
/* We don't want to go to Success here. We've already done */
|
||||
/* that. On the other hand, if we succeeded we still need to */
|
||||
/* close this stream (we opened a different stream which */
|
||||
/* extracted the interesting information out of this stream */
|
||||
/* here. That stream will still be open and the face will */
|
||||
/* point to it). */
|
||||
FT_Stream_Free( stream, external_stream );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
|
||||
goto Fail2;
|
||||
#endif /* !FT_MACINTOSH && FT_CONFIG_OPTION_MAC_FONTS */
|
||||
|
||||
/* no driver is able to handle this format */
|
||||
error = FT_THROW( Unknown_File_Format );
|
||||
|
||||
|
@ -252,42 +252,6 @@ FT_BEGIN_HEADER
|
||||
#define FT_CONFIG_OPTION_ADOBE_GLYPH_LIST
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* Support for Mac fonts */
|
||||
/* */
|
||||
/* Define this macro if you want support for outline fonts in Mac */
|
||||
/* format (mac dfont, mac resource, macbinary containing a mac */
|
||||
/* resource) on non-Mac platforms. */
|
||||
/* */
|
||||
/* Note that the `FOND' resource isn't checked. */
|
||||
/* */
|
||||
#define FT_CONFIG_OPTION_MAC_FONTS
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* Guessing methods to access embedded resource forks */
|
||||
/* */
|
||||
/* Enable extra Mac fonts support on non-Mac platforms (e.g. */
|
||||
/* GNU/Linux). */
|
||||
/* */
|
||||
/* Resource forks which include fonts data are stored sometimes in */
|
||||
/* locations which users or developers don't expected. In some cases, */
|
||||
/* resource forks start with some offset from the head of a file. In */
|
||||
/* other cases, the actual resource fork is stored in file different */
|
||||
/* from what the user specifies. If this option is activated, */
|
||||
/* FreeType tries to guess whether such offsets or different file */
|
||||
/* names must be used. */
|
||||
/* */
|
||||
/* Note that normal, direct access of resource forks is controlled via */
|
||||
/* the FT_CONFIG_OPTION_MAC_FONTS option. */
|
||||
/* */
|
||||
#ifdef FT_CONFIG_OPTION_MAC_FONTS
|
||||
#define FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
|
||||
#endif
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* Allow the use of FT_Incremental_Interface to load typefaces that */
|
||||
|
@ -1,942 +0,0 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* ftrfork.c */
|
||||
/* */
|
||||
/* Embedded resource forks accessor (body). */
|
||||
/* */
|
||||
/* Copyright 2004-2018 by */
|
||||
/* Masatake YAMATO and Redhat K.K. */
|
||||
/* */
|
||||
/* FT_Raccess_Get_HeaderInfo() and raccess_guess_darwin_hfsplus() are */
|
||||
/* derived from ftobjs.c. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
/***************************************************************************/
|
||||
/* Development of the code in this file is support of */
|
||||
/* Information-technology Promotion Agency, Japan. */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#include "ft2build.h"
|
||||
#include FT_INTERNAL_DEBUG_H
|
||||
#include FT_INTERNAL_STREAM_H
|
||||
#include FT_INTERNAL_RFORK_H
|
||||
#include "ftbase.h"
|
||||
|
||||
#undef FT_COMPONENT
|
||||
#define FT_COMPONENT trace_raccess
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/**** ****/
|
||||
/**** ****/
|
||||
/**** Resource fork directory access ****/
|
||||
/**** ****/
|
||||
/**** ****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
FT_BASE_DEF( FT_Error )
|
||||
FT_Raccess_Get_HeaderInfo( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long rfork_offset,
|
||||
FT_Long *map_offset,
|
||||
FT_Long *rdata_pos )
|
||||
{
|
||||
FT_Error error;
|
||||
unsigned char head[16], head2[16];
|
||||
FT_Long map_pos, map_len, rdata_len;
|
||||
int allzeros, allmatch, i;
|
||||
FT_Long type_list;
|
||||
|
||||
FT_UNUSED( library );
|
||||
|
||||
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)rfork_offset );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
error = FT_Stream_Read( stream, (FT_Byte*)head, 16 );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
/* ensure positive values */
|
||||
if ( head[0] >= 0x80 ||
|
||||
head[4] >= 0x80 ||
|
||||
head[8] >= 0x80 ||
|
||||
head[12] >= 0x80 )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
*rdata_pos = ( head[ 0] << 24 ) |
|
||||
( head[ 1] << 16 ) |
|
||||
( head[ 2] << 8 ) |
|
||||
head[ 3];
|
||||
map_pos = ( head[ 4] << 24 ) |
|
||||
( head[ 5] << 16 ) |
|
||||
( head[ 6] << 8 ) |
|
||||
head[ 7];
|
||||
rdata_len = ( head[ 8] << 24 ) |
|
||||
( head[ 9] << 16 ) |
|
||||
( head[10] << 8 ) |
|
||||
head[11];
|
||||
map_len = ( head[12] << 24 ) |
|
||||
( head[13] << 16 ) |
|
||||
( head[14] << 8 ) |
|
||||
head[15];
|
||||
|
||||
/* the map must not be empty */
|
||||
if ( !map_pos )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
/* check whether rdata and map overlap */
|
||||
if ( *rdata_pos < map_pos )
|
||||
{
|
||||
if ( *rdata_pos > map_pos - rdata_len )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( map_pos > *rdata_pos - map_len )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
}
|
||||
|
||||
/* check whether end of rdata or map exceeds stream size */
|
||||
if ( FT_LONG_MAX - rdata_len < *rdata_pos ||
|
||||
FT_LONG_MAX - map_len < map_pos ||
|
||||
|
||||
FT_LONG_MAX - ( *rdata_pos + rdata_len ) < rfork_offset ||
|
||||
FT_LONG_MAX - ( map_pos + map_len ) < rfork_offset ||
|
||||
|
||||
(FT_ULong)( rfork_offset + *rdata_pos + rdata_len ) > stream->size ||
|
||||
(FT_ULong)( rfork_offset + map_pos + map_len ) > stream->size )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
*rdata_pos += rfork_offset;
|
||||
map_pos += rfork_offset;
|
||||
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)map_pos );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
head2[15] = (FT_Byte)( head[15] + 1 ); /* make it be different */
|
||||
|
||||
error = FT_Stream_Read( stream, (FT_Byte*)head2, 16 );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
allzeros = 1;
|
||||
allmatch = 1;
|
||||
for ( i = 0; i < 16; i++ )
|
||||
{
|
||||
if ( head2[i] != 0 )
|
||||
allzeros = 0;
|
||||
if ( head2[i] != head[i] )
|
||||
allmatch = 0;
|
||||
}
|
||||
if ( !allzeros && !allmatch )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
/* If we have reached this point then it is probably a mac resource */
|
||||
/* file. Now, does it contain any interesting resources? */
|
||||
|
||||
(void)FT_STREAM_SKIP( 4 /* skip handle to next resource map */
|
||||
+ 2 /* skip file resource number */
|
||||
+ 2 ); /* skip attributes */
|
||||
|
||||
if ( FT_READ_SHORT( type_list ) )
|
||||
return error;
|
||||
if ( type_list < 0 )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)( map_pos + type_list ) );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
*map_offset = map_pos + type_list;
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
ft_raccess_sort_ref_by_id( FT_RFork_Ref* a,
|
||||
FT_RFork_Ref* b )
|
||||
{
|
||||
if ( a->res_id < b->res_id )
|
||||
return -1;
|
||||
else if ( a->res_id > b->res_id )
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
FT_BASE_DEF( FT_Error )
|
||||
FT_Raccess_Get_DataOffsets( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long map_offset,
|
||||
FT_Long rdata_pos,
|
||||
FT_Long tag,
|
||||
FT_Bool sort_by_res_id,
|
||||
FT_Long **offsets,
|
||||
FT_Long *count )
|
||||
{
|
||||
FT_Error error;
|
||||
int i, j, cnt, subcnt;
|
||||
FT_Long tag_internal, rpos;
|
||||
FT_Memory memory = library->memory;
|
||||
FT_Long temp;
|
||||
FT_Long *offsets_internal = NULL;
|
||||
FT_RFork_Ref *ref = NULL;
|
||||
|
||||
|
||||
FT_TRACE3(( "\n" ));
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)map_offset );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
if ( FT_READ_SHORT( cnt ) )
|
||||
return error;
|
||||
cnt++;
|
||||
|
||||
/* `rpos' is a signed 16bit integer offset to resource records; the */
|
||||
/* size of a resource record is 12 bytes. The map header is 28 bytes, */
|
||||
/* and a type list needs 10 bytes or more. If we assume that the name */
|
||||
/* list is empty and we have only a single entry in the type list, */
|
||||
/* there can be at most */
|
||||
/* */
|
||||
/* (32768 - 28 - 10) / 12 = 2727 */
|
||||
/* */
|
||||
/* resources. */
|
||||
/* */
|
||||
/* A type list starts with a two-byte counter, followed by 10-byte */
|
||||
/* type records. Assuming that there are no resources, the number of */
|
||||
/* type records can be at most */
|
||||
/* */
|
||||
/* (32768 - 28 - 2) / 8 = 4079 */
|
||||
/* */
|
||||
if ( cnt > 4079 )
|
||||
return FT_THROW( Invalid_Table );
|
||||
|
||||
for ( i = 0; i < cnt; i++ )
|
||||
{
|
||||
if ( FT_READ_LONG( tag_internal ) ||
|
||||
FT_READ_SHORT( subcnt ) ||
|
||||
FT_READ_SHORT( rpos ) )
|
||||
return error;
|
||||
|
||||
FT_TRACE2(( "Resource tags: %c%c%c%c\n",
|
||||
(char)( 0xFF & ( tag_internal >> 24 ) ),
|
||||
(char)( 0xFF & ( tag_internal >> 16 ) ),
|
||||
(char)( 0xFF & ( tag_internal >> 8 ) ),
|
||||
(char)( 0xFF & ( tag_internal >> 0 ) ) ));
|
||||
FT_TRACE3(( " : subcount=%d, suboffset=0x%04x\n",
|
||||
subcnt, rpos ));
|
||||
|
||||
if ( tag_internal == tag )
|
||||
{
|
||||
*count = subcnt + 1;
|
||||
rpos += map_offset;
|
||||
|
||||
/* a zero count might be valid in the resource specification, */
|
||||
/* however, it is completely useless to us */
|
||||
if ( *count < 1 || *count > 2727 )
|
||||
return FT_THROW( Invalid_Table );
|
||||
|
||||
error = FT_Stream_Seek( stream, (FT_ULong)rpos );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
if ( FT_NEW_ARRAY( ref, *count ) )
|
||||
return error;
|
||||
|
||||
for ( j = 0; j < *count; j++ )
|
||||
{
|
||||
if ( FT_READ_SHORT( ref[j].res_id ) )
|
||||
goto Exit;
|
||||
if ( FT_STREAM_SKIP( 2 ) ) /* resource name offset */
|
||||
goto Exit;
|
||||
if ( FT_READ_LONG( temp ) ) /* attributes (8bit), offset (24bit) */
|
||||
goto Exit;
|
||||
if ( FT_STREAM_SKIP( 4 ) ) /* mbz */
|
||||
goto Exit;
|
||||
|
||||
/*
|
||||
* According to Inside Macintosh: More Macintosh Toolbox,
|
||||
* "Resource IDs" (1-46), there are some reserved IDs.
|
||||
* However, FreeType2 is not a font synthesizer, no need
|
||||
* to check the acceptable resource ID.
|
||||
*/
|
||||
if ( temp < 0 )
|
||||
{
|
||||
error = FT_THROW( Invalid_Table );
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
ref[j].offset = temp & 0xFFFFFFL;
|
||||
|
||||
FT_TRACE3(( " [%d]:"
|
||||
" resource_id=0x%04x, offset=0x%08x\n",
|
||||
j, (FT_UShort)ref[j].res_id, ref[j].offset ));
|
||||
}
|
||||
|
||||
if ( sort_by_res_id )
|
||||
{
|
||||
ft_qsort( ref,
|
||||
(size_t)*count,
|
||||
sizeof ( FT_RFork_Ref ),
|
||||
( int(*)(const void*,
|
||||
const void*) )ft_raccess_sort_ref_by_id );
|
||||
|
||||
FT_TRACE3(( " -- sort resources by their ids --\n" ));
|
||||
|
||||
for ( j = 0; j < *count; j++ )
|
||||
FT_TRACE3(( " [%d]:"
|
||||
" resource_id=0x%04x, offset=0x%08x\n",
|
||||
j, ref[j].res_id, ref[j].offset ));
|
||||
}
|
||||
|
||||
if ( FT_NEW_ARRAY( offsets_internal, *count ) )
|
||||
goto Exit;
|
||||
|
||||
/* XXX: duplicated reference ID,
|
||||
* gap between reference IDs are acceptable?
|
||||
* further investigation on Apple implementation is needed.
|
||||
*/
|
||||
for ( j = 0; j < *count; j++ )
|
||||
offsets_internal[j] = rdata_pos + ref[j].offset;
|
||||
|
||||
*offsets = offsets_internal;
|
||||
error = FT_Err_Ok;
|
||||
|
||||
Exit:
|
||||
FT_FREE( ref );
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return FT_THROW( Cannot_Open_Resource );
|
||||
}
|
||||
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
|
||||
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/**** ****/
|
||||
/**** ****/
|
||||
/**** Guessing functions ****/
|
||||
/**** ****/
|
||||
/**** When you add a new guessing function, ****/
|
||||
/**** update FT_RACCESS_N_RULES in ftrfork.h. ****/
|
||||
/**** ****/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_double( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_single( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_ufs_export( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_newvfs( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_hfsplus( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_vfat( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_cap( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_double( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_netatalk( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
|
||||
CONST_FT_RFORK_RULE_ARRAY_BEGIN(ft_raccess_guess_table,
|
||||
ft_raccess_guess_rec)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_double, apple_double)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(apple_single, apple_single)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_ufs_export, darwin_ufs_export)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_newvfs, darwin_newvfs)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(darwin_hfsplus, darwin_hfsplus)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(vfat, vfat)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_cap, linux_cap)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_double, linux_double)
|
||||
CONST_FT_RFORK_RULE_ARRAY_ENTRY(linux_netatalk, linux_netatalk)
|
||||
CONST_FT_RFORK_RULE_ARRAY_END
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/**** ****/
|
||||
/**** Helper functions ****/
|
||||
/**** ****/
|
||||
/*************************************************************************/
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_generic( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
FT_Int32 magic,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_double_from_file_name( FT_Library library,
|
||||
char * file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
static char *
|
||||
raccess_make_file_name( FT_Memory memory,
|
||||
const char *original_name,
|
||||
const char *insertion );
|
||||
|
||||
FT_BASE_DEF( void )
|
||||
FT_Raccess_Guess( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char* base_name,
|
||||
char **new_names,
|
||||
FT_Long *offsets,
|
||||
FT_Error *errors )
|
||||
{
|
||||
FT_Int i;
|
||||
|
||||
|
||||
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
|
||||
{
|
||||
new_names[i] = NULL;
|
||||
if ( NULL != stream )
|
||||
errors[i] = FT_Stream_Seek( stream, 0 );
|
||||
else
|
||||
errors[i] = FT_Err_Ok;
|
||||
|
||||
if ( errors[i] )
|
||||
continue;
|
||||
|
||||
errors[i] = (ft_raccess_guess_table[i].func)( library,
|
||||
stream, base_name,
|
||||
&(new_names[i]),
|
||||
&(offsets[i]) );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#if defined( FT_CONFIG_OPTION_MAC_FONTS ) && !defined( FT_MACINTOSH )
|
||||
static FT_RFork_Rule
|
||||
raccess_get_rule_type_from_rule_index( FT_Library library,
|
||||
FT_UInt rule_index )
|
||||
{
|
||||
FT_UNUSED( library );
|
||||
|
||||
if ( rule_index >= FT_RACCESS_N_RULES )
|
||||
return FT_RFork_Rule_invalid;
|
||||
|
||||
return ft_raccess_guess_table[rule_index].type;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* For this function, refer ftbase.h.
|
||||
*/
|
||||
FT_LOCAL_DEF( FT_Bool )
|
||||
ft_raccess_rule_by_darwin_vfs( FT_Library library,
|
||||
FT_UInt rule_index )
|
||||
{
|
||||
switch( raccess_get_rule_type_from_rule_index( library, rule_index ) )
|
||||
{
|
||||
case FT_RFork_Rule_darwin_newvfs:
|
||||
case FT_RFork_Rule_darwin_hfsplus:
|
||||
return TRUE;
|
||||
|
||||
default:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_double( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
FT_Int32 magic = ( 0x00 << 24 ) |
|
||||
( 0x05 << 16 ) |
|
||||
( 0x16 << 8 ) |
|
||||
0x07;
|
||||
|
||||
|
||||
*result_file_name = NULL;
|
||||
if ( NULL == stream )
|
||||
return FT_THROW( Cannot_Open_Stream );
|
||||
|
||||
return raccess_guess_apple_generic( library, stream, base_file_name,
|
||||
magic, result_offset );
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_single( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
FT_Int32 magic = ( 0x00 << 24 ) |
|
||||
( 0x05 << 16 ) |
|
||||
( 0x16 << 8 ) |
|
||||
0x00;
|
||||
|
||||
|
||||
*result_file_name = NULL;
|
||||
if ( NULL == stream )
|
||||
return FT_THROW( Cannot_Open_Stream );
|
||||
|
||||
return raccess_guess_apple_generic( library, stream, base_file_name,
|
||||
magic, result_offset );
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_ufs_export( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
char* newpath;
|
||||
FT_Error error;
|
||||
FT_Memory memory;
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
newpath = raccess_make_file_name( memory, base_file_name, "._" );
|
||||
if ( !newpath )
|
||||
return FT_THROW( Out_Of_Memory );
|
||||
|
||||
error = raccess_guess_linux_double_from_file_name( library, newpath,
|
||||
result_offset );
|
||||
if ( !error )
|
||||
*result_file_name = newpath;
|
||||
else
|
||||
FT_FREE( newpath );
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_hfsplus( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
/*
|
||||
Only meaningful on systems with hfs+ drivers (or Macs).
|
||||
*/
|
||||
FT_Error error;
|
||||
char* newpath = NULL;
|
||||
FT_Memory memory;
|
||||
FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name );
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
if ( base_file_len + 6 > FT_INT_MAX )
|
||||
return FT_THROW( Array_Too_Large );
|
||||
|
||||
if ( FT_ALLOC( newpath, base_file_len + 6 ) )
|
||||
return error;
|
||||
|
||||
FT_MEM_COPY( newpath, base_file_name, base_file_len );
|
||||
FT_MEM_COPY( newpath + base_file_len, "/rsrc", 6 );
|
||||
|
||||
*result_file_name = newpath;
|
||||
*result_offset = 0;
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_darwin_newvfs( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
/*
|
||||
Only meaningful on systems with Mac OS X (> 10.1).
|
||||
*/
|
||||
FT_Error error;
|
||||
char* newpath = NULL;
|
||||
FT_Memory memory;
|
||||
FT_Long base_file_len = (FT_Long)ft_strlen( base_file_name );
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
if ( base_file_len + 18 > FT_INT_MAX )
|
||||
return FT_THROW( Array_Too_Large );
|
||||
|
||||
if ( FT_ALLOC( newpath, base_file_len + 18 ) )
|
||||
return error;
|
||||
|
||||
FT_MEM_COPY( newpath, base_file_name, base_file_len );
|
||||
FT_MEM_COPY( newpath + base_file_len, "/..namedfork/rsrc", 18 );
|
||||
|
||||
*result_file_name = newpath;
|
||||
*result_offset = 0;
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_vfat( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
char* newpath;
|
||||
FT_Memory memory;
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
newpath = raccess_make_file_name( memory, base_file_name,
|
||||
"resource.frk/" );
|
||||
if ( !newpath )
|
||||
return FT_THROW( Out_Of_Memory );
|
||||
|
||||
*result_file_name = newpath;
|
||||
*result_offset = 0;
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_cap( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
char* newpath;
|
||||
FT_Memory memory;
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
newpath = raccess_make_file_name( memory, base_file_name, ".resource/" );
|
||||
if ( !newpath )
|
||||
return FT_THROW( Out_Of_Memory );
|
||||
|
||||
*result_file_name = newpath;
|
||||
*result_offset = 0;
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_double( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
char* newpath;
|
||||
FT_Error error;
|
||||
FT_Memory memory;
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
newpath = raccess_make_file_name( memory, base_file_name, "%" );
|
||||
if ( !newpath )
|
||||
return FT_THROW( Out_Of_Memory );
|
||||
|
||||
error = raccess_guess_linux_double_from_file_name( library, newpath,
|
||||
result_offset );
|
||||
if ( !error )
|
||||
*result_file_name = newpath;
|
||||
else
|
||||
FT_FREE( newpath );
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_netatalk( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
char* newpath;
|
||||
FT_Error error;
|
||||
FT_Memory memory;
|
||||
|
||||
FT_UNUSED( stream );
|
||||
|
||||
|
||||
memory = library->memory;
|
||||
|
||||
newpath = raccess_make_file_name( memory, base_file_name,
|
||||
".AppleDouble/" );
|
||||
if ( !newpath )
|
||||
return FT_THROW( Out_Of_Memory );
|
||||
|
||||
error = raccess_guess_linux_double_from_file_name( library, newpath,
|
||||
result_offset );
|
||||
if ( !error )
|
||||
*result_file_name = newpath;
|
||||
else
|
||||
FT_FREE( newpath );
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_apple_generic( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
FT_Int32 magic,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
FT_Int32 magic_from_stream;
|
||||
FT_Error error;
|
||||
FT_Int32 version_number = 0;
|
||||
FT_UShort n_of_entries;
|
||||
|
||||
int i;
|
||||
FT_Int32 entry_id, entry_offset, entry_length = 0;
|
||||
|
||||
const FT_Int32 resource_fork_entry_id = 0x2;
|
||||
|
||||
FT_UNUSED( library );
|
||||
FT_UNUSED( base_file_name );
|
||||
FT_UNUSED( version_number );
|
||||
FT_UNUSED( entry_length );
|
||||
|
||||
|
||||
if ( FT_READ_LONG( magic_from_stream ) )
|
||||
return error;
|
||||
if ( magic_from_stream != magic )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
if ( FT_READ_LONG( version_number ) )
|
||||
return error;
|
||||
|
||||
/* filler */
|
||||
error = FT_Stream_Skip( stream, 16 );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
if ( FT_READ_USHORT( n_of_entries ) )
|
||||
return error;
|
||||
if ( n_of_entries == 0 )
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
|
||||
for ( i = 0; i < n_of_entries; i++ )
|
||||
{
|
||||
if ( FT_READ_LONG( entry_id ) )
|
||||
return error;
|
||||
if ( entry_id == resource_fork_entry_id )
|
||||
{
|
||||
if ( FT_READ_LONG( entry_offset ) ||
|
||||
FT_READ_LONG( entry_length ) )
|
||||
continue;
|
||||
*result_offset = entry_offset;
|
||||
|
||||
return FT_Err_Ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
error = FT_Stream_Skip( stream, 4 + 4 ); /* offset + length */
|
||||
if ( error )
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
return FT_THROW( Unknown_File_Format );
|
||||
}
|
||||
|
||||
|
||||
static FT_Error
|
||||
raccess_guess_linux_double_from_file_name( FT_Library library,
|
||||
char *file_name,
|
||||
FT_Long *result_offset )
|
||||
{
|
||||
FT_Open_Args args2;
|
||||
FT_Stream stream2;
|
||||
char * nouse = NULL;
|
||||
FT_Error error;
|
||||
|
||||
|
||||
args2.flags = FT_OPEN_PATHNAME;
|
||||
args2.pathname = file_name;
|
||||
error = FT_Stream_New( library, &args2, &stream2 );
|
||||
if ( error )
|
||||
return error;
|
||||
|
||||
error = raccess_guess_apple_double( library, stream2, file_name,
|
||||
&nouse, result_offset );
|
||||
|
||||
FT_Stream_Free( stream2, 0 );
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
raccess_make_file_name( FT_Memory memory,
|
||||
const char *original_name,
|
||||
const char *insertion )
|
||||
{
|
||||
char* new_name = NULL;
|
||||
const char* tmp;
|
||||
const char* slash;
|
||||
size_t new_length;
|
||||
FT_Error error = FT_Err_Ok;
|
||||
|
||||
FT_UNUSED( error );
|
||||
|
||||
|
||||
new_length = ft_strlen( original_name ) + ft_strlen( insertion );
|
||||
if ( FT_ALLOC( new_name, new_length + 1 ) )
|
||||
return NULL;
|
||||
|
||||
tmp = ft_strrchr( original_name, '/' );
|
||||
if ( tmp )
|
||||
{
|
||||
ft_strncpy( new_name,
|
||||
original_name,
|
||||
(size_t)( tmp - original_name + 1 ) );
|
||||
new_name[tmp - original_name + 1] = '\0';
|
||||
slash = tmp + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
slash = original_name;
|
||||
new_name[0] = '\0';
|
||||
}
|
||||
|
||||
ft_strcat( new_name, insertion );
|
||||
ft_strcat( new_name, slash );
|
||||
|
||||
return new_name;
|
||||
}
|
||||
|
||||
|
||||
#else /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* Dummy function; just sets errors */
|
||||
/*************************************************************************/
|
||||
|
||||
FT_BASE_DEF( void )
|
||||
FT_Raccess_Guess( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_name,
|
||||
char **new_names,
|
||||
FT_Long *offsets,
|
||||
FT_Error *errors )
|
||||
{
|
||||
FT_Int i;
|
||||
|
||||
FT_UNUSED( library );
|
||||
FT_UNUSED( stream );
|
||||
FT_UNUSED( base_name );
|
||||
|
||||
|
||||
for ( i = 0; i < FT_RACCESS_N_RULES; i++ )
|
||||
{
|
||||
new_names[i] = NULL;
|
||||
offsets[i] = 0;
|
||||
errors[i] = FT_ERR( Unimplemented_Feature );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* !FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
|
||||
|
||||
|
||||
/* END */
|
@ -1,267 +0,0 @@
|
||||
/***************************************************************************/
|
||||
/* */
|
||||
/* ftrfork.h */
|
||||
/* */
|
||||
/* Embedded resource forks accessor (specification). */
|
||||
/* */
|
||||
/* Copyright 2004-2018 by */
|
||||
/* Masatake YAMATO and Redhat K.K. */
|
||||
/* */
|
||||
/* This file is part of the FreeType project, and may only be used, */
|
||||
/* modified, and distributed under the terms of the FreeType project */
|
||||
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */
|
||||
/* this file you indicate that you have read the license and */
|
||||
/* understand and accept it fully. */
|
||||
/* */
|
||||
/***************************************************************************/
|
||||
|
||||
/***************************************************************************/
|
||||
/* Development of the code in this file is support of */
|
||||
/* Information-technology Promotion Agency, Japan. */
|
||||
/***************************************************************************/
|
||||
|
||||
|
||||
#ifndef FTRFORK_H_
|
||||
#define FTRFORK_H_
|
||||
|
||||
|
||||
#include "ft2build.h"
|
||||
#include FT_INTERNAL_OBJECTS_H
|
||||
|
||||
|
||||
FT_BEGIN_HEADER
|
||||
|
||||
|
||||
/* Number of guessing rules supported in `FT_Raccess_Guess'. */
|
||||
/* Don't forget to increment the number if you add a new guessing rule. */
|
||||
#define FT_RACCESS_N_RULES 9
|
||||
|
||||
|
||||
/* A structure to describe a reference in a resource by its resource ID */
|
||||
/* and internal offset. The `POST' resource expects to be concatenated */
|
||||
/* by the order of resource IDs instead of its appearance in the file. */
|
||||
|
||||
typedef struct FT_RFork_Ref_
|
||||
{
|
||||
FT_Short res_id;
|
||||
FT_Long offset;
|
||||
|
||||
} FT_RFork_Ref;
|
||||
|
||||
|
||||
#ifdef FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK
|
||||
typedef FT_Error
|
||||
(*ft_raccess_guess_func)( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char *base_file_name,
|
||||
char **result_file_name,
|
||||
FT_Long *result_offset );
|
||||
|
||||
typedef enum FT_RFork_Rule_ {
|
||||
FT_RFork_Rule_invalid = -2,
|
||||
FT_RFork_Rule_uknown, /* -1 */
|
||||
FT_RFork_Rule_apple_double,
|
||||
FT_RFork_Rule_apple_single,
|
||||
FT_RFork_Rule_darwin_ufs_export,
|
||||
FT_RFork_Rule_darwin_newvfs,
|
||||
FT_RFork_Rule_darwin_hfsplus,
|
||||
FT_RFork_Rule_vfat,
|
||||
FT_RFork_Rule_linux_cap,
|
||||
FT_RFork_Rule_linux_double,
|
||||
FT_RFork_Rule_linux_netatalk
|
||||
} FT_RFork_Rule;
|
||||
|
||||
/* For fast translation between rule index and rule type,
|
||||
* the macros FT_RFORK_xxx should be kept consistent with
|
||||
* the raccess_guess_funcs table
|
||||
*/
|
||||
typedef struct ft_raccess_guess_rec_ {
|
||||
ft_raccess_guess_func func;
|
||||
FT_RFork_Rule type;
|
||||
} ft_raccess_guess_rec;
|
||||
|
||||
#ifndef FT_CONFIG_OPTION_PIC
|
||||
|
||||
/* this array is a storage in non-PIC mode, so ; is needed in END */
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type ) \
|
||||
static const type name[] = {
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix ) \
|
||||
{ raccess_guess_ ## func_suffix, \
|
||||
FT_RFork_Rule_ ## type_suffix },
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_END };
|
||||
|
||||
#else /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
/* this array is a function in PIC mode, so no ; is needed in END */
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_BEGIN( name, type ) \
|
||||
void \
|
||||
FT_Init_Table_ ## name( type* storage ) \
|
||||
{ \
|
||||
type* local = storage; \
|
||||
\
|
||||
\
|
||||
int i = 0;
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_ENTRY( func_suffix, type_suffix ) \
|
||||
local[i].func = raccess_guess_ ## func_suffix; \
|
||||
local[i].type = FT_RFork_Rule_ ## type_suffix; \
|
||||
i++;
|
||||
#define CONST_FT_RFORK_RULE_ARRAY_END }
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_PIC */
|
||||
|
||||
#endif /* FT_CONFIG_OPTION_GUESSING_EMBEDDED_RFORK */
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_Raccess_Guess */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Guess a file name and offset where the actual resource fork is */
|
||||
/* stored. The macro FT_RACCESS_N_RULES holds the number of */
|
||||
/* guessing rules; the guessed result for the Nth rule is */
|
||||
/* represented as a triplet: a new file name (new_names[N]), a file */
|
||||
/* offset (offsets[N]), and an error code (errors[N]). */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* library :: */
|
||||
/* A FreeType library instance. */
|
||||
/* */
|
||||
/* stream :: */
|
||||
/* A file stream containing the resource fork. */
|
||||
/* */
|
||||
/* base_name :: */
|
||||
/* The (base) file name of the resource fork used for some */
|
||||
/* guessing rules. */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* new_names :: */
|
||||
/* An array of guessed file names in which the resource forks may */
|
||||
/* exist. If `new_names[N]' is NULL, the guessed file name is */
|
||||
/* equal to `base_name'. */
|
||||
/* */
|
||||
/* offsets :: */
|
||||
/* An array of guessed file offsets. `offsets[N]' holds the file */
|
||||
/* offset of the possible start of the resource fork in file */
|
||||
/* `new_names[N]'. */
|
||||
/* */
|
||||
/* errors :: */
|
||||
/* An array of FreeType error codes. `errors[N]' is the error */
|
||||
/* code of Nth guessing rule function. If `errors[N]' is not */
|
||||
/* FT_Err_Ok, `new_names[N]' and `offsets[N]' are meaningless. */
|
||||
/* */
|
||||
FT_BASE( void )
|
||||
FT_Raccess_Guess( FT_Library library,
|
||||
FT_Stream stream,
|
||||
char* base_name,
|
||||
char** new_names,
|
||||
FT_Long* offsets,
|
||||
FT_Error* errors );
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_Raccess_Get_HeaderInfo */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Get the information from the header of resource fork. The */
|
||||
/* information includes the file offset where the resource map */
|
||||
/* starts, and the file offset where the resource data starts. */
|
||||
/* `FT_Raccess_Get_DataOffsets' requires these two data. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* library :: */
|
||||
/* A FreeType library instance. */
|
||||
/* */
|
||||
/* stream :: */
|
||||
/* A file stream containing the resource fork. */
|
||||
/* */
|
||||
/* rfork_offset :: */
|
||||
/* The file offset where the resource fork starts. */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* map_offset :: */
|
||||
/* The file offset where the resource map starts. */
|
||||
/* */
|
||||
/* rdata_pos :: */
|
||||
/* The file offset where the resource data starts. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. FT_Err_Ok means success. */
|
||||
/* */
|
||||
FT_BASE( FT_Error )
|
||||
FT_Raccess_Get_HeaderInfo( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long rfork_offset,
|
||||
FT_Long *map_offset,
|
||||
FT_Long *rdata_pos );
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* <Function> */
|
||||
/* FT_Raccess_Get_DataOffsets */
|
||||
/* */
|
||||
/* <Description> */
|
||||
/* Get the data offsets for a tag in a resource fork. Offsets are */
|
||||
/* stored in an array because, in some cases, resources in a resource */
|
||||
/* fork have the same tag. */
|
||||
/* */
|
||||
/* <Input> */
|
||||
/* library :: */
|
||||
/* A FreeType library instance. */
|
||||
/* */
|
||||
/* stream :: */
|
||||
/* A file stream containing the resource fork. */
|
||||
/* */
|
||||
/* map_offset :: */
|
||||
/* The file offset where the resource map starts. */
|
||||
/* */
|
||||
/* rdata_pos :: */
|
||||
/* The file offset where the resource data starts. */
|
||||
/* */
|
||||
/* tag :: */
|
||||
/* The resource tag. */
|
||||
/* */
|
||||
/* sort_by_res_id :: */
|
||||
/* A Boolean to sort the fragmented resource by their ids. */
|
||||
/* The fragmented resources for `POST' resource should be sorted */
|
||||
/* to restore Type1 font properly. For `sfnt' resources, sorting */
|
||||
/* may induce a different order of the faces in comparison to that */
|
||||
/* by QuickDraw API. */
|
||||
/* */
|
||||
/* <Output> */
|
||||
/* offsets :: */
|
||||
/* The stream offsets for the resource data specified by `tag'. */
|
||||
/* This array is allocated by the function, so you have to call */
|
||||
/* @ft_mem_free after use. */
|
||||
/* */
|
||||
/* count :: */
|
||||
/* The length of offsets array. */
|
||||
/* */
|
||||
/* <Return> */
|
||||
/* FreeType error code. FT_Err_Ok means success. */
|
||||
/* */
|
||||
/* <Note> */
|
||||
/* Normally you should use `FT_Raccess_Get_HeaderInfo' to get the */
|
||||
/* value for `map_offset' and `rdata_pos'. */
|
||||
/* */
|
||||
FT_BASE( FT_Error )
|
||||
FT_Raccess_Get_DataOffsets( FT_Library library,
|
||||
FT_Stream stream,
|
||||
FT_Long map_offset,
|
||||
FT_Long rdata_pos,
|
||||
FT_Long tag,
|
||||
FT_Bool sort_by_res_id,
|
||||
FT_Long **offsets,
|
||||
FT_Long *count );
|
||||
|
||||
|
||||
FT_END_HEADER
|
||||
|
||||
#endif /* FTRFORK_H_ */
|
||||
|
||||
|
||||
/* END */
|
Loading…
x
Reference in New Issue
Block a user