📄 ftobjs.c
字号:
face->internal->incremental_interface = params[i].data; }#endif error = clazz->init_face( stream, face, (FT_Int)face_index, num_params, params ); if ( error ) goto Fail; /* select Unicode charmap by default */ error2 = find_unicode_charmap( face ); /* if no Unicode charmap can be found, FT_Err_Invalid_CharMap_Handle */ /* is returned. */ /* no error should happen, but we want to play safe */ if ( error2 && error2 != FT_Err_Invalid_CharMap_Handle ) { error = error2; goto Fail; } *aface = face; Fail: if ( error ) { destroy_charmaps( face, memory ); clazz->done_face( face ); FT_FREE( internal ); FT_FREE( face ); *aface = 0; } return error; } /* there's a Mac-specific extended implementation of FT_New_Face() */ /* in src/base/ftmac.c */#ifndef FT_MACINTOSH /* documentation is in freetype.h */ FT_EXPORT_DEF( FT_Error ) FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face *aface ) { FT_Open_Args args; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_Err_Invalid_Argument; args.flags = FT_OPEN_PATHNAME; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }#endif /* !FT_MACINTOSH */ /* 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_Open_Args args; /* test for valid `library' and `face' delayed to FT_Open_Face() */ if ( !file_base ) return FT_Err_Invalid_Argument; args.flags = FT_OPEN_MEMORY; args.memory_base = file_base; args.memory_size = file_size; return FT_Open_Face( library, &args, face_index, aface ); }#if !defined( FT_MACINTOSH ) && defined( 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 = 0; stream->close = 0; } /* 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; if ( !library ) return FT_Err_Invalid_Library_Handle; if ( !base ) return FT_Err_Invalid_Argument; *astream = 0; 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 */ static 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; 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 ); } error = FT_Open_Face( library, &args, face_index, aface ); if ( error == FT_Err_Ok ) (*aface)->face_flags &= ~FT_FACE_FLAG_EXTERNAL_STREAM; else { FT_Stream_Close( stream ); FT_FREE( stream ); } return error; } /* 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; int i, type, flags; FT_Long len; FT_Long pfb_len, pfb_pos, pfb_lenpos; FT_Long 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, offsets[i] ); if ( error ) goto Exit; if ( FT_READ_LONG( temp ) ) goto Exit; pfb_len += temp + 6; } 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 = 7; pfb_lenpos = 2; len = 0; type = 1; for ( i = 0; i < resource_cnt; ++i ) { error = FT_Stream_Seek( stream, offsets[i] ); if ( error ) goto Exit2; if ( FT_READ_LONG( rlen ) ) goto Exit; if ( FT_READ_USHORT( flags ) ) goto Exit; rlen -= 2; /* the flags are part of the resource */ if ( ( flags >> 8 ) == type ) len += rlen; else { 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; pfb_data[pfb_pos++] = 0x80; type = flags >> 8; len = rlen; pfb_data[pfb_pos++] = (FT_Byte)type; pfb_lenpos = (FT_Byte)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; } error = FT_Stream_Read( stream, (FT_Byte *)pfb_data + pfb_pos, rlen ); pfb_pos += rlen; } pfb_data[pfb_pos++] = 0x80; pfb_data[pfb_pos++] = 3; 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: 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 the 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; FT_Error error; FT_Long flag_offset; FT_Long rlen; int is_cff; if ( face_index == -1 ) face_index = 0; if ( face_index >= resource_cnt ) return FT_Err_Cannot_Open_Resource; flag_offset = 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_Err_Cannot_Open_Resource; if ( FT_ALLOC( sfnt_data, (FT_Long)rlen ) ) return error; error = FT_Stream_Read( stream, (FT_Byte *)sfnt_data, rlen ); if ( error ) goto Exit; is_cff = rlen > 4 && sfnt_data[0] == 'O' && sfnt_data[1] == 'T' && sfnt_data[2] == 'T' && sfnt_data[3] == 'O'; error = open_face_from_buffer( library, sfnt_data, rlen, face_index, 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, rdara_pos; FT_Long *data_offsets; FT_Long count; error = FT_Raccess_Get_HeaderInfo( library, stream, resource_offset, &map_offset, &rdara_pos ); if ( error ) return error; error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, FT_MAKE_TAG( 'P', 'O', 'S', 'T' ), &data_offsets, &count ); if ( !error ) { error = Mac_Read_POST_Resource( library, stream, data_offsets, count, face_index, aface ); FT_FREE( data_offsets ); return error; } error = FT_Raccess_Get_DataOffsets( library, stream, map_offset, rdara_pos, FT_MAKE_TAG( 's', 'f', 'n', 't' ), &data_offsets, &count ); if ( !error ) { error = Mac_Read_sfnt_Resource( library, stream, data_offsets, count, face_index, aface ); FT_FREE( data_offsets ); } 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 ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -