📄 sfobjs.c
字号:
FT_UNUSED( face_index ); FT_UNUSED( num_params ); FT_UNUSED( params ); /* Load tables */ /* We now support two SFNT-based bitmapped font formats. They */ /* are recognized easily as they do not include a `glyf' */ /* table. */ /* */ /* The first format comes from Apple, and uses a table named */ /* `bhed' instead of `head' to store the font header (using */ /* the same format). It also doesn't include horizontal and */ /* vertical metrics tables (i.e. `hhea' and `vhea' tables are */ /* missing). */ /* */ /* The other format comes from Microsoft, and is used with */ /* WinCE/PocketPC. It looks like a standard TTF, except that */ /* it doesn't contain outlines. */ /* */ /* do we have outlines in there? */#ifdef FT_CONFIG_OPTION_INCREMENTAL has_outline = FT_BOOL( face->root.internal->incremental_interface != 0 || tt_face_lookup_table( face, TTAG_glyf ) != 0 || tt_face_lookup_table( face, TTAG_CFF ) != 0 );#else has_outline = FT_BOOL( tt_face_lookup_table( face, TTAG_glyf ) != 0 || tt_face_lookup_table( face, TTAG_CFF ) != 0 );#endif is_apple_sbit = 0;#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS /* if this font doesn't contain outlines, we try to load */ /* a `bhed' table */ if ( !has_outline ) is_apple_sbit = FT_BOOL( !LOAD_( bitmap_header ) );#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ /* load the font header (`head' table) if this isn't an Apple */ /* sbit font file */ if ( !is_apple_sbit && LOAD_( header ) ) goto Exit; /* the following tables are often not present in embedded TrueType */ /* fonts within PDF documents, so don't check for them. */ (void)LOAD_( max_profile ); (void)LOAD_( charmaps ); /* the following tables are optional in PCL fonts -- */ /* don't check for errors */ (void)LOAD_( names ); psnames_error = LOAD_( psnames ); /* do not load the metrics headers and tables if this is an Apple */ /* sbit font file */ if ( !is_apple_sbit ) { /* load the `hhea' and `hmtx' tables at once */ error = sfnt->load_metrics( face, stream, 0 ); if ( error ) goto Exit; /* try to load the `vhea' and `vmtx' tables at once */ error = sfnt->load_metrics( face, stream, 1 ); if ( error ) goto Exit; if ( LOAD_( os2 ) ) goto Exit; } /* the optional tables */#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS /* embedded bitmap support. */ if ( sfnt->load_sbits && LOAD_( sbits ) ) { /* return an error if this font file has no outlines */ if ( error == SFNT_Err_Table_Missing && has_outline ) error = SFNT_Err_Ok; else goto Exit; }#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ if ( LOAD_( hdmx ) || LOAD_( pclt ) ) goto Exit; /* consider the kerning and gasp tables as optional */ (void)LOAD_( gasp ); (void)LOAD_( kerning ); error = SFNT_Err_Ok; face->root.family_name = tt_face_get_name( face, TT_NAME_ID_PREFERRED_FAMILY ); if ( !face->root.family_name ) face->root.family_name = tt_face_get_name( face, TT_NAME_ID_FONT_FAMILY ); face->root.style_name = tt_face_get_name( face, TT_NAME_ID_PREFERRED_SUBFAMILY ); if ( !face->root.style_name ) face->root.style_name = tt_face_get_name( face, TT_NAME_ID_FONT_SUBFAMILY ); /* now set up root fields */ { FT_Face root = &face->root; FT_Int32 flags = root->face_flags; /*********************************************************************/ /* */ /* Compute face flags. */ /* */ if ( has_outline == TRUE ) flags |= FT_FACE_FLAG_SCALABLE; /* scalable outlines */ flags |= FT_FACE_FLAG_SFNT | /* SFNT file format */ FT_FACE_FLAG_HORIZONTAL; /* horizontal data */#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES if ( psnames_error == SFNT_Err_Ok && face->postscript.FormatType != 0x00030000L ) flags |= FT_FACE_FLAG_GLYPH_NAMES;#endif /* fixed width font? */ if ( face->postscript.isFixedPitch ) flags |= FT_FACE_FLAG_FIXED_WIDTH; /* vertical information? */ if ( face->vertical_info ) flags |= FT_FACE_FLAG_VERTICAL;#if 0 /* kerning available ? */ if ( TT_FACE_HAS_KERNING( face ) ) flags |= FT_FACE_FLAG_KERNING;#endif#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT /* Don't bother to load the tables unless somebody asks for them. */ /* No need to do work which will (probably) not be used. */ if ( tt_face_lookup_table( face, TTAG_glyf ) != 0 && tt_face_lookup_table( face, TTAG_fvar ) != 0 && tt_face_lookup_table( face, TTAG_gvar ) != 0 ) flags |= FT_FACE_FLAG_MULTIPLE_MASTERS;#endif root->face_flags = flags; /*********************************************************************/ /* */ /* Compute style flags. */ /* */ flags = 0; if ( has_outline == TRUE && face->os2.version != 0xFFFFU ) { /* we have an OS/2 table; use the `fsSelection' field */ if ( face->os2.fsSelection & 1 ) flags |= FT_STYLE_FLAG_ITALIC; if ( face->os2.fsSelection & 32 ) flags |= FT_STYLE_FLAG_BOLD; } else { /* this is an old Mac font, use the header field */ if ( face->header.Mac_Style & 1 ) flags |= FT_STYLE_FLAG_BOLD; if ( face->header.Mac_Style & 2 ) flags |= FT_STYLE_FLAG_ITALIC; } root->style_flags = flags; /*********************************************************************/ /* */ /* Polish the charmaps. */ /* */ /* Try to set the charmap encoding according to the platform & */ /* encoding ID of each charmap. */ /* */ tt_face_build_cmaps( face ); /* ignore errors */ /* set the encoding fields */ { FT_Int m; for ( m = 0; m < root->num_charmaps; m++ ) { FT_CharMap charmap = root->charmaps[m]; charmap->encoding = sfnt_find_encoding( charmap->platform_id, charmap->encoding_id );#if 0 if ( root->charmap == NULL && charmap->encoding == FT_ENCODING_UNICODE ) { /* set 'root->charmap' to the first Unicode encoding we find */ root->charmap = charmap; }#endif } } /*********************************************************************/ /* */ /* Set up metrics. */ /* */ if ( has_outline == TRUE ) { /* XXX What about if outline header is missing */ /* (e.g. sfnt wrapped bitmap)? */ root->bbox.xMin = face->header.xMin; root->bbox.yMin = face->header.yMin; root->bbox.xMax = face->header.xMax; root->bbox.yMax = face->header.yMax; root->units_per_EM = face->header.Units_Per_EM; /* XXX: Computing the ascender/descender/height is very different */ /* from what the specification tells you. Apparently, we */ /* must be careful because */ /* */ /* - not all fonts have an OS/2 table; in this case, we take */ /* the values in the horizontal header. However, these */ /* values very often are not reliable. */ /* */ /* - otherwise, the correct typographic values are in the */ /* sTypoAscender, sTypoDescender & sTypoLineGap fields. */ /* */ /* However, certains fonts have these fields set to 0. */ /* Rather, they have usWinAscent & usWinDescent correctly */ /* set (but with different values). */ /* */ /* As an example, Arial Narrow is implemented through four */ /* files ARIALN.TTF, ARIALNI.TTF, ARIALNB.TTF & ARIALNBI.TTF */ /* */ /* Strangely, all fonts have the same values in their */ /* sTypoXXX fields, except ARIALNB which sets them to 0. */ /* */ /* On the other hand, they all have different */ /* usWinAscent/Descent values -- as a conclusion, the OS/2 */ /* table cannot be used to compute the text height reliably! */ /* */ /* The ascender/descender/height are computed from the OS/2 table */ /* when found. Otherwise, they're taken from the horizontal */ /* header. */ /* */ root->ascender = face->horizontal.Ascender; root->descender = face->horizontal.Descender; root->height = (FT_Short)( root->ascender - root->descender + face->horizontal.Line_Gap );#if 0 /* if the line_gap is 0, we add an extra 15% to the text height -- */ /* this computation is based on various versions of Times New Roman */ if ( face->horizontal.Line_Gap == 0 ) root->height = (FT_Short)( ( root->height * 115 + 50 ) / 100 );#endif#if 0 /* some fonts have the OS/2 "sTypoAscender", "sTypoDescender" & */ /* "sTypoLineGap" fields set to 0, like ARIALNB.TTF */ if ( face->os2.version != 0xFFFFU && root->ascender ) { FT_Int height; root->ascender = face->os2.sTypoAscender; root->descender = -face->os2.sTypoDescender; height = root->ascender + root->descender + face->os2.sTypoLineGap; if ( height > root->height ) root->height = height; }#endif /* 0 */ root->max_advance_width = face->horizontal.advance_Width_Max; root->max_advance_height = (FT_Short)( face->vertical_info ? face->vertical.advance_Height_Max : root->height ); root->underline_position = face->postscript.underlinePosition; root->underline_thickness = face->postscript.underlineThickness; /* root->max_points -- already set up */ /* root->max_contours -- already set up */ } } Exit: return error; }#undef LOAD_ FT_LOCAL_DEF( void ) sfnt_done_face( TT_Face face ) { FT_Memory memory = face->root.memory; SFNT_Service sfnt = (SFNT_Service)face->sfnt; if ( sfnt ) { /* destroy the postscript names table if it is loaded */ if ( sfnt->free_psnames ) sfnt->free_psnames( face ); /* destroy the embedded bitmaps table if it is loaded */ if ( sfnt->free_sbits ) sfnt->free_sbits( face ); } /* freeing the kerning table */ tt_face_done_kern( face ); /* freeing the collection table */ FT_FREE( face->ttc_header.offsets ); face->ttc_header.count = 0; /* freeing table directory */ FT_FREE( face->dir_tables ); face->num_tables = 0; { FT_Stream stream = FT_FACE_STREAM( face ); /* simply release the 'cmap' table frame */ FT_FRAME_RELEASE( face->cmap_table ); face->cmap_size = 0; } /* freeing the horizontal metrics */#ifdef FT_OPTIMIZE_MEMORY { FT_Stream stream = FT_FACE_STREAM( face ); FT_FRAME_RELEASE( face->horz_metrics ); FT_FRAME_RELEASE( face->vert_metrics ); face->horz_metrics_size = 0; face->vert_metrics_size = 0; }#else FT_FREE( face->horizontal.long_metrics ); FT_FREE( face->horizontal.short_metrics );#endif /* freeing the vertical ones, if any */ if ( face->vertical_info ) { FT_FREE( face->vertical.long_metrics ); FT_FREE( face->vertical.short_metrics ); face->vertical_info = 0; } /* freeing the gasp table */ FT_FREE( face->gasp.gaspRanges ); face->gasp.numRanges = 0; /* freeing the name table */ sfnt->free_names( face ); /* freeing the hdmx table */ sfnt->free_hdmx( face ); /* freeing family and style name */ FT_FREE( face->root.family_name ); FT_FREE( face->root.style_name ); /* freeing sbit size table */ FT_FREE( face->root.available_sizes ); face->root.num_fixed_sizes = 0; FT_FREE( face->postscript_name ); face->sfnt = 0; }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -