24 #include FT_INTERNAL_SFNT_H 25 #include FT_INTERNAL_DEBUG_H 26 #include FT_TRUETYPE_IDS_H 27 #include FT_TRUETYPE_TAGS_H 28 #include FT_SERVICE_POSTSCRIPT_CMAPS_H 29 #include FT_SFNT_NAMES_H 32 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 33 #include FT_SERVICE_MULTIPLE_MASTERS_H 34 #include FT_SERVICE_METRICS_VARIATIONS_H 39 #ifdef TT_CONFIG_OPTION_BDF 51 #define FT_COMPONENT trace_sfobjs 71 for (
n = 0;
n <
len;
n++ )
106 for (
n = 0;
n <
len;
n++ )
143 FT_Int found_apple_roman = -1;
144 FT_Int found_apple_english = -1;
146 FT_Int found_unicode = -1;
155 rec =
face->name_table.names;
156 for (
n = 0;
n <
face->num_names;
n++, rec++ )
186 found_apple_english =
n;
188 found_apple_roman =
n;
195 if ( found_win == -1 || ( rec->
languageID & 0x3FF ) == 0x009 )
218 found_apple = found_apple_roman;
219 if ( found_apple_english >= 0 )
220 found_apple = found_apple_english;
227 if ( found_win >= 0 && !( found_apple >= 0 && !
is_english ) )
229 rec =
face->name_table.names + found_win;
251 else if ( found_apple >= 0 )
253 rec =
face->name_table.names + found_apple;
256 else if ( found_unicode >= 0 )
258 rec =
face->name_table.names + found_unicode;
293 typedef struct TEncoding_
302 const TEncoding tt_encodings[] =
324 limit =
cur +
sizeof ( tt_encodings ) /
sizeof ( tt_encodings[0] );
328 if (
cur->platform_id == platform_id )
330 if (
cur->encoding_id == encoding_id ||
331 cur->encoding_id == -1 )
332 return cur->encoding;
336 return FT_ENCODING_NONE;
340 #define WRITE_USHORT( p, v ) \ 343 *(p)++ = (FT_Byte)( (v) >> 8 ); \ 344 *(p)++ = (FT_Byte)( (v) >> 0 ); \ 348 #define WRITE_ULONG( p, v ) \ 351 *(p)++ = (FT_Byte)( (v) >> 24 ); \ 352 *(p)++ = (FT_Byte)( (v) >> 16 ); \ 353 *(p)++ = (FT_Byte)( (v) >> 8 ); \ 354 *(p)++ = (FT_Byte)( (v) >> 0 ); \ 384 if ( offset1 > offset2 )
386 else if ( offset1 < offset2 )
421 #define FT_STRUCTURE WOFF_HeaderRec 462 FT_ERROR((
"woff_font_open: invalid WOFF header\n" ));
475 FT_UInt searchRange, entrySelector, rangeShift,
x;
487 searchRange = ( 1 << entrySelector ) * 16;
488 rangeShift = woff.
num_tables * 16 - searchRange;
506 " tag offset compLen origLen checksum\n" 507 " -------------------------------------------\n" ));
522 FT_TRACE2((
" %c%c%c%c %08lx %08lx %08lx %08lx\n",
532 if (
table->Tag <= old_tag )
536 FT_ERROR((
"woff_font_open: table tags are not sorted\n" ));
541 old_tag =
table->Tag;
564 if (
table->Offset != woff_offset ||
571 FT_ERROR((
"woff_font_open: invalid table offsets\n" ));
576 table->OrigOffset = sfnt_offset;
579 woff_offset += (
table->CompLength + 3 ) & ~3
U;
580 sfnt_offset += (
table->OrigLength + 3 ) & ~3
U;
598 " invalid `metadata' offset or length\n" ));
610 woff_offset = ( woff_offset + 3 ) & ~3
U;
615 FT_ERROR((
"woff_font_open: invalid `private' offset or length\n" ));
625 woff_offset != woff.
length )
627 FT_ERROR((
"woff_font_open: invalid `sfnt' table structure\n" ));
638 sfnt_header =
sfnt + 12;
667 #ifdef FT_CONFIG_OPTION_USE_ZLIB 678 if ( output_len !=
table->OrigLength )
680 FT_ERROR((
"woff_font_open: compressed table length mismatch\n" ));
697 sfnt_offset =
table->OrigOffset +
table->OrigLength;
698 while ( sfnt_offset & 3 )
700 sfnt[sfnt_offset] =
'\0';
714 face->root.stream = sfnt_stream;
750 #define FT_STRUCTURE TTC_HeaderRec 759 face->ttc_header.tag = 0;
760 face->ttc_header.version = 0;
761 face->ttc_header.count = 0;
771 FT_TRACE2((
"sfnt_open_font: file is a WOFF; synthesizing SFNT\n" ));
785 if (
tag != 0x00010000UL &&
792 tag != 0x00020000UL )
794 FT_TRACE2((
" not a font using the SFNT container format\n" ));
795 return FT_THROW( Unknown_File_Format );
805 FT_TRACE3((
"sfnt_open_font: file is a collection\n" ));
811 face->ttc_header.count ));
813 if (
face->ttc_header.count == 0 )
831 for (
n = 0;
n <
face->ttc_header.count;
n++ )
838 FT_TRACE3((
"sfnt_open_font: synthesize TTC\n" ));
840 face->ttc_header.version = 1 << 16;
841 face->ttc_header.count = 1;
856 FT_Int face_instance_index,
877 FT_ERROR((
"sfnt_init_face: cannot access `sfnt' module\n" ));
887 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 921 FT_TRACE2((
"sfnt_init_face: %08p, %d\n",
face, face_instance_index ));
923 face_index =
FT_ABS( face_instance_index ) & 0xFFFF;
926 if ( face_instance_index < 0 )
929 if ( face_index >=
face->ttc_header.count )
931 if ( face_instance_index >= 0 )
932 return FT_THROW( Invalid_Argument );
945 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 965 instance_index =
FT_ABS( face_instance_index ) >> 16;
987 if (
version != 0x00010000UL ||
992 !( instance_size == 4 + 4 * num_axes ||
993 instance_size == 6 + 4 * num_axes ) ||
995 num_instances > 0x7EFF ||
997 axis_size * num_axes +
998 instance_size * num_instances > fvar_len )
1016 !(
FT_ALLOC( default_values, num_axes * 4 ) ||
1017 FT_ALLOC( instance_values, num_axes * 4 ) ) )
1021 FT_ULong default_value_offset, instance_offset;
1027 default_value_offset = array_start + 8;
1030 for (
i = 0;
i < num_axes;
i++ )
1034 default_value_offset += axis_size;
1038 instance_offset = array_start + axis_size * num_axes + 4;
1040 for (
i = 0;
i < num_instances;
i++ )
1046 if ( !
ft_memcmp( default_values, instance_values, num_axes * 4 ) )
1049 instance_offset += instance_size;
1052 if (
i == num_instances )
1072 if ( instance_index > num_instances )
1074 if ( face_instance_index >= 0 )
1075 return FT_THROW( Invalid_Argument );
1080 face->root.style_flags = (
FT_Long)num_instances << 16;
1084 face->root.num_faces =
face->ttc_header.count;
1085 face->root.face_index = face_instance_index;
1091 #define LOAD_( x ) \ 1094 FT_TRACE2(( "`" #x "' " )); \ 1095 FT_TRACE3(( "-->\n" )); \ 1097 error = sfnt->load_ ## x( face, stream ); \ 1099 FT_TRACE2(( "%s\n", ( !error ) \ 1101 : FT_ERR_EQ( error, Table_Missing ) \ 1103 : "failed to load" )); \ 1104 FT_TRACE3(( "\n" )); \ 1107 #define LOADM_( x, vertical ) \ 1110 FT_TRACE2(( "`%s" #x "' ", \ 1111 vertical ? "vertical " : "" )); \ 1112 FT_TRACE3(( "-->\n" )); \ 1114 error = sfnt->load_ ## x( face, stream, vertical ); \ 1116 FT_TRACE2(( "%s\n", ( !error ) \ 1118 : FT_ERR_EQ( error, Table_Missing ) \ 1120 : "failed to load" )); \ 1121 FT_TRACE3(( "\n" )); \ 1124 #define GET_NAME( id, field ) \ 1127 error = tt_face_get_name( face, TT_NAME_ID_ ## id, field ); \ 1136 FT_Int face_instance_index,
1141 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 1161 for (
i = 0;
i < num_params;
i++ )
1164 ignore_typographic_family =
TRUE;
1166 ignore_typographic_subfamily =
TRUE;
1190 #ifdef FT_CONFIG_OPTION_INCREMENTAL 1191 has_outline =
FT_BOOL(
face->root.internal->incremental_interface ||
1207 if ( is_apple_sbix )
1208 has_outline =
FALSE;
1220 if ( !is_apple_sbit || is_apple_sbix )
1229 if (
face->header.Units_Per_EM < 16 ||
1230 face->header.Units_Per_EM > 16384 )
1247 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 1248 psnames_error =
error;
1253 if ( !is_apple_sbit )
1264 #ifdef FT_CONFIG_OPTION_INCREMENTAL 1267 if (
face->root.internal->incremental_interface &&
1268 face->root.internal->incremental_interface->funcs->
1271 face->horizontal.number_Of_HMetrics = 0;
1282 FT_TRACE2((
"This is an SFNT Mac font.\n" ));
1291 #ifdef FT_CONFIG_OPTION_INCREMENTAL 1294 if (
face->root.internal->incremental_interface &&
1295 face->root.internal->incremental_interface->funcs->
1298 face->horizontal.number_Of_HMetrics = 0;
1315 face->vertical_info = 1;
1325 face->os2.version = 0xFFFF
U;
1340 face->root.num_glyphs =
face->max_profile.numGlyphs;
1350 if (
face->os2.version != 0xFFFFU &&
face->os2.fsSelection & 256 )
1352 if ( !ignore_typographic_family )
1353 GET_NAME( TYPOGRAPHIC_FAMILY, &
face->root.family_name );
1354 if ( !
face->root.family_name )
1357 if ( !ignore_typographic_subfamily )
1358 GET_NAME( TYPOGRAPHIC_SUBFAMILY, &
face->root.style_name );
1359 if ( !
face->root.style_name )
1365 if ( !
face->root.family_name && !ignore_typographic_family )
1366 GET_NAME( TYPOGRAPHIC_FAMILY, &
face->root.family_name );
1367 if ( !
face->root.family_name )
1371 if ( !
face->root.style_name && !ignore_typographic_subfamily )
1372 GET_NAME( TYPOGRAPHIC_SUBFAMILY, &
face->root.style_name );
1373 if ( !
face->root.style_name )
1391 if ( has_outline ==
TRUE )
1399 #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES 1400 if ( !psnames_error &&
1401 face->postscript.FormatType != 0x00030000L )
1406 if (
face->postscript.isFixedPitch )
1410 if (
face->vertical_info )
1417 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT 1438 if ( has_outline ==
TRUE &&
face->os2.version != 0xFFFFU )
1444 if (
face->os2.fsSelection & 512 )
1446 else if (
face->os2.fsSelection & 1 )
1449 if (
face->os2.fsSelection & 32 )
1456 if (
face->header.Mac_Style & 1 )
1459 if (
face->header.Mac_Style & 2 )
1480 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 1485 for (
m = 0;
m <
root->num_charmaps;
m++ )
1493 #ifdef FT_CONFIG_OPTION_POSTSCRIPT_NAMES 1495 if ( charmap->
encoding == FT_ENCODING_UNICODE ||
1496 charmap->
encoding == FT_ENCODING_MS_SYMBOL )
1509 cmaprec.
encoding = FT_ENCODING_UNICODE;
1524 #ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS 1545 FT_UInt strike_idx, bsize_idx;
1548 if ( em_size == 0 ||
face->os2.version == 0xFFFFU )
1562 for ( strike_idx = 0; strike_idx <
count; strike_idx++ )
1573 ( avgwidth *
metrics.x_ppem + em_size / 2 ) / em_size );
1583 sbit_strike_map[bsize_idx++] = strike_idx;
1593 face->sbit_strike_map = sbit_strike_map;
1617 root->bbox.xMin =
face->header.xMin;
1618 root->bbox.yMin =
face->header.yMin;
1619 root->bbox.xMax =
face->header.xMax;
1620 root->bbox.yMax =
face->header.yMax;
1621 root->units_per_EM =
face->header.Units_Per_EM;
1653 root->ascender =
face->horizontal.Ascender;
1654 root->descender =
face->horizontal.Descender;
1657 face->horizontal.Line_Gap;
1659 if ( !(
root->ascender ||
root->descender ) )
1661 if (
face->os2.version != 0xFFFFU )
1663 if (
face->os2.sTypoAscender ||
face->os2.sTypoDescender )
1665 root->ascender =
face->os2.sTypoAscender;
1666 root->descender =
face->os2.sTypoDescender;
1669 face->os2.sTypoLineGap;
1681 root->max_advance_width =
1683 root->max_advance_height =
1690 root->underline_position =
face->postscript.underlinePosition -
1691 face->postscript.underlineThickness / 2;
1692 root->underline_thickness =
face->postscript.underlineThickness;
1698 FT_TRACE2((
"sfnt_load_face: done\n" ));
1733 #ifdef TT_CONFIG_OPTION_BDF 1735 tt_face_free_bdf_props(
face );
1743 face->ttc_header.count = 0;
1747 face->num_tables = 0;
1755 face->cmap_size = 0;
1758 face->horz_metrics_size = 0;
1759 face->vert_metrics_size = 0;
1762 if (
face->vertical_info )
1766 face->vertical_info = 0;
1771 face->gasp.numRanges = 0;
1784 face->root.num_fixed_sizes = 0;
1786 #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT
#define FT_ALLOC(ptr, size)
#define FT_SERVICE_ID_MULTI_MASTERS
#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_FAMILY
GLuint GLuint GLsizei GLenum const GLvoid * indices
#define GET_NAME(id, field)
SFNT_Interface * SFNT_Service
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
#define FT_FACE_FLAG_COLOR
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
tt_face_done_kern(TT_Face face)
GLsizei GLenum const GLvoid GLuint GLsizei GLfloat * metrics
struct outqueuenode * head
tt_face_build_cmaps(TT_Face face)
#define TT_MAC_LANGID_ENGLISH
TT_Loader_GotoTableFunc goto_table
TT_Free_Table_Func free_name
GLuint GLuint GLsizei count
#define FT_SERVICE_ID_METRICS_VARIATIONS
#define FT_FACE_FLAG_SCALABLE
FT_String *(* TT_Name_ConvertFunc)(TT_Name entry, FT_Memory memory)
struct nls_table * tables
static FT_String * tt_name_ascii_from_other(TT_Name entry, FT_Memory memory)
GLenum GLsizei GLenum GLenum const GLvoid * table
GLint GLint GLint GLint GLint x
#define FT_FACE_FLAG_MULTIPLE_MASTERS
tt_face_get_name(TT_Face face, FT_UShort nameid, FT_String **name)
#define FT_QNEW_ARRAY(ptr, count)
#define FT_FACE_FLAG_FIXED_SIZES
#define TT_MS_ID_UNICODE_CS
#define FT_FACE_FIND_GLOBAL_SERVICE(face, ptr, id)
static char memory[1024 *256]
#define FT_READ_USHORT(var)
sfnt_init_face(FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter *params)
FT_Stream_Close(FT_Stream stream)
#define TT_PLATFORM_MICROSOFT
FT_BEGIN_HEADER typedef unsigned char FT_Bool
TT_Load_Table_Func load_font_dir
ft_module_get_service(FT_Module module, const char *service_id, FT_Bool global)
TT_Load_Table_Func load_bhed
#define FT_ERROR(varformat)
static FT_Error sfnt_open_font(FT_Stream stream, TT_Face face)
GLenum const GLfloat * params
#define FT_ASSERT(condition)
#define FT_STYLE_FLAG_BOLD
GLenum GLuint GLenum GLsizei length
#define TT_PLATFORM_APPLE_UNICODE
FT_CALLBACK_TABLE const TT_CMap_ClassRec tt_cmap_unicode_class_rec
#define FT_FACE_FLAG_VERTICAL
#define FT_STREAM_READ_FIELDS(fields, object)
static const WCHAR version[]
sfnt_load_face(FT_Stream stream, TT_Face face, FT_Int face_instance_index, FT_Int num_params, FT_Parameter *params)
static FT_Encoding sfnt_find_encoding(int platform_id, int encoding_id)
#define FT_STREAM_SKIP(distance)
#define FT_FACE_FLAG_SFNT
#define FT_FACE_FLAG_FIXED_WIDTH
#define FT_FRAME_USHORT(f)
static FT_String * tt_name_ascii_from_utf16(TT_Name entry, FT_Memory memory)
#define FT_STREAM_READ_AT(position, buffer, count)
#define FT_PARAM_TAG_IGNORE_TYPOGRAPHIC_SUBFAMILY
TT_Load_Table_Func load_eblc
#define FT_READ_ULONG(var)
GLboolean GLboolean GLboolean b
#define TT_PLATFORM_MACINTOSH
#define FT_HAS_FIXED_SIZES(face)
#define WRITE_USHORT(p, v)
#define FT_FACE_FLAG_HORIZONTAL
#define FT_TRACE2(varformat)
static FT_Error woff_open_font(FT_Stream stream, TT_Face face)
TT_Load_Strike_Metrics_Func load_strike_metrics
static void sfnt_stream_close(FT_Stream stream)
#define FT_RENEW_ARRAY(ptr, curcnt, newcnt)
TT_Free_Table_Func free_psnames
#define FT_FACE_FLAG_EXTERNAL_STREAM
#define FT_CALLBACK_DEF(x)
enum FT_Encoding_ FT_Encoding
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
#define FT_NEW_ARRAY(ptr, count)
#define FT_STREAM_SEEK(position)
#define FT_NEXT_USHORT(buffer)
#define FT_FRAME_RELEASE(bytes)
#define FT_TRACE3(varformat)
FT_CMap_New(FT_CMap_Class clazz, FT_Pointer init_data, FT_CharMap charmap, FT_CMap *acmap)
#define TT_MS_ID_SYMBOL_CS
sfnt_done_face(TT_Face face)
#define FT_REALLOC(ptr, cursz, newsz)
#define FT_FRAME_ULONG(f)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
#define TT_FACE_FLAG_VAR_FVAR
FT_Stream_Free(FT_Stream stream, FT_Int external)
compare_offsets(const void *a, const void *b)
#define FT_FACE_FLAG_KERNING
FT_Gzip_Uncompress(FT_Memory memory, FT_Byte *output, FT_ULong *output_len, const FT_Byte *input, FT_ULong input_len)
#define LOADM_(x, vertical)
FT_Get_Module(FT_Library library, const char *module_name)
tt_face_lookup_table(TT_Face face, FT_ULong tag)
FT_Stream_OpenMemory(FT_Stream stream, const FT_Byte *base, FT_ULong size)
#define FT_FRAME_ENTER(size)
FT_Get_Module_Interface(FT_Library library, const char *mod_name)
#define TT_FACE_HAS_KERNING(face)
TT_Free_Table_Func free_eblc
#define FT_STYLE_FLAG_ITALIC
GLboolean GLboolean GLboolean GLboolean a
#define FT_FACE_STREAM(x)
#define FT_IS_SCALABLE(face)
#define FT_FACE_FLAG_GLYPH_NAMES
#define FT_STREAM_READ(buffer, count)
#define FT_FRAME_START(size)
#define WRITE_ULONG(p, v)
GLenum GLuint GLint GLenum face
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)
FT_Stream_CloseFunc close