📄 cffobjs.c
字号:
/***************************************************************************//* *//* cffobjs.c *//* *//* OpenType objects manager (body). *//* *//* Copyright 1996-2001, 2002, 2003, 2004, 2005 by *//* David Turner, Robert Wilhelm, and Werner Lemberg. *//* *//* 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. *//* *//***************************************************************************/#include <ft2build.h>#include FT_INTERNAL_DEBUG_H#include FT_INTERNAL_CALC_H#include FT_INTERNAL_STREAM_H#include FT_ERRORS_H#include FT_TRUETYPE_IDS_H#include FT_TRUETYPE_TAGS_H#include FT_INTERNAL_SFNT_H#include FT_SERVICE_POSTSCRIPT_CMAPS_H#include FT_INTERNAL_POSTSCRIPT_HINTS_H#include "cffobjs.h"#include "cffload.h"#include "cffcmap.h"#include "cfferrs.h" /*************************************************************************/ /* */ /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ /* messages during execution. */ /* */#undef FT_COMPONENT#define FT_COMPONENT trace_cffobjs /*************************************************************************/ /* */ /* SIZE FUNCTIONS */ /* */ /* Note that we store the global hints in the size's `internal' root */ /* field. */ /* */ /*************************************************************************/#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS static FT_Error sbit_size_reset( CFF_Size size ) { CFF_Face face; FT_Error error = CFF_Err_Ok; FT_ULong strike_index; FT_Size_Metrics* metrics; FT_Size_Metrics* sbit_metrics; SFNT_Service sfnt; metrics = &size->root.metrics; face = (CFF_Face)size->root.face; sfnt = (SFNT_Service)face->sfnt; sbit_metrics = &size->strike_metrics; error = sfnt->set_sbit_strike( face, metrics->x_ppem, metrics->y_ppem, &strike_index ); if ( !error ) { /* XXX: TODO: move this code to the SFNT module where it belongs */#ifdef FT_OPTIMIZE_MEMORY FT_Byte* strike = face->sbit_table + 8 + strike_index*48; sbit_metrics->ascender = (FT_Char)strike[16] << 6; /* hori.ascender */ sbit_metrics->descender = (FT_Char)strike[17] << 6; /* hori.descender */ /* XXX: Is this correct? */ sbit_metrics->max_advance = ( (FT_Char)strike[22] + /* min_origin_SB */ strike[18] + /* max_width */ (FT_Char)strike[23] /* min_advance_SB */ ) << 6;#else /* !OPTIMIZE_MEMORY */ TT_SBit_Strike strike = face->sbit_strikes + strike_index; sbit_metrics->ascender = strike->hori.ascender << 6; sbit_metrics->descender = strike->hori.descender << 6; /* XXX: Is this correct? */ sbit_metrics->max_advance = ( strike->hori.min_origin_SB + strike->hori.max_width + strike->hori.min_advance_SB ) << 6;#endif /* !OPTIMIZE_MEMORY */ /* XXX: Is this correct? */ sbit_metrics->height = sbit_metrics->ascender - sbit_metrics->descender; sbit_metrics->x_ppem = metrics->x_ppem; sbit_metrics->y_ppem = metrics->y_ppem; size->strike_index = (FT_UInt)strike_index; } else { size->strike_index = 0xFFFFU; sbit_metrics->x_ppem = 0; sbit_metrics->y_ppem = 0; sbit_metrics->ascender = 0; sbit_metrics->descender = 0; sbit_metrics->height = 0; sbit_metrics->max_advance = 0; } return error; }#endif /* TT_CONFIG_OPTION_EMBEDDED_BITMAPS */ static PSH_Globals_Funcs cff_size_get_globals_funcs( CFF_Size size ) { CFF_Face face = (CFF_Face)size->root.face; CFF_Font font = (CFF_FontRec *)face->extra.data; PSHinter_Service pshinter = (PSHinter_Service)font->pshinter; FT_Module module; module = FT_Get_Module( size->root.face->driver->root.library, "pshinter" ); return ( module && pshinter && pshinter->get_globals_funcs ) ? pshinter->get_globals_funcs( module ) : 0; } FT_LOCAL_DEF( void ) cff_size_done( FT_Size cffsize ) /* CFF_Size */ { CFF_Size size = (CFF_Size)cffsize; if ( cffsize->internal ) { PSH_Globals_Funcs funcs; funcs = cff_size_get_globals_funcs( size ); if ( funcs ) funcs->destroy( (PSH_Globals)cffsize->internal ); cffsize->internal = 0; } } FT_LOCAL_DEF( FT_Error ) cff_size_init( FT_Size cffsize ) /* CFF_Size */ { CFF_Size size = (CFF_Size)cffsize; FT_Error error = CFF_Err_Ok; PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size ); if ( funcs ) { PSH_Globals globals; CFF_Face face = (CFF_Face)cffsize->face; CFF_Font font = (CFF_FontRec *)face->extra.data; CFF_SubFont subfont = &font->top_font; CFF_Private cpriv = &subfont->private_dict; PS_PrivateRec priv; /* IMPORTANT: The CFF and Type1 private dictionaries have */ /* slightly different structures; we need to */ /* synthetize a type1 dictionary on the fly here. */ { FT_UInt n, count; FT_MEM_ZERO( &priv, sizeof ( priv ) ); count = priv.num_blue_values = cpriv->num_blue_values; for ( n = 0; n < count; n++ ) priv.blue_values[n] = (FT_Short)cpriv->blue_values[n]; count = priv.num_other_blues = cpriv->num_other_blues; for ( n = 0; n < count; n++ ) priv.other_blues[n] = (FT_Short)cpriv->other_blues[n]; count = priv.num_family_blues = cpriv->num_family_blues; for ( n = 0; n < count; n++ ) priv.family_blues[n] = (FT_Short)cpriv->family_blues[n]; count = priv.num_family_other_blues = cpriv->num_family_other_blues; for ( n = 0; n < count; n++ ) priv.family_other_blues[n] = (FT_Short)cpriv->family_other_blues[n]; priv.blue_scale = cpriv->blue_scale; priv.blue_shift = (FT_Int)cpriv->blue_shift; priv.blue_fuzz = (FT_Int)cpriv->blue_fuzz; priv.standard_width[0] = (FT_UShort)cpriv->standard_width; priv.standard_height[0] = (FT_UShort)cpriv->standard_height; count = priv.num_snap_widths = cpriv->num_snap_widths; for ( n = 0; n < count; n++ ) priv.snap_widths[n] = (FT_Short)cpriv->snap_widths[n]; count = priv.num_snap_heights = cpriv->num_snap_heights; for ( n = 0; n < count; n++ ) priv.snap_heights[n] = (FT_Short)cpriv->snap_heights[n]; priv.force_bold = cpriv->force_bold; priv.language_group = cpriv->language_group; priv.lenIV = cpriv->lenIV; } error = funcs->create( cffsize->face->memory, &priv, &globals ); if ( !error ) cffsize->internal = (FT_Size_Internal)(void*)globals; } return error; } FT_LOCAL_DEF( FT_Error ) cff_size_reset( FT_Size cffsize, /* CFF_Size */ FT_UInt char_width, FT_UInt char_height ) { CFF_Size size = (CFF_Size)cffsize; PSH_Globals_Funcs funcs = cff_size_get_globals_funcs( size ); FT_Error error = CFF_Err_Ok; FT_Face face = cffsize->face; FT_UNUSED( char_width ); FT_UNUSED( char_height ); if ( funcs ) error = funcs->set_scale( (PSH_Globals)cffsize->internal, cffsize->metrics.x_scale, cffsize->metrics.y_scale, 0, 0 );#ifdef TT_CONFIG_OPTION_EMBEDDED_BITMAPS if ( face->face_flags & FT_FACE_FLAG_FIXED_SIZES ) { error = sbit_size_reset( size ); if ( !error && !( face->face_flags & FT_FACE_FLAG_SCALABLE ) ) cffsize->metrics = size->strike_metrics; }#endif if ( face->face_flags & FT_FACE_FLAG_SCALABLE ) return CFF_Err_Ok; else return error; } FT_LOCAL_DEF( FT_Error ) cff_point_size_reset( FT_Size cffsize, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution ) { FT_UNUSED( char_width ); FT_UNUSED( char_height ); FT_UNUSED( horz_resolution ); FT_UNUSED( vert_resolution ); return cff_size_reset( cffsize, 0, 0 ); } /*************************************************************************/ /* */ /* SLOT FUNCTIONS */ /* */ /*************************************************************************/ FT_LOCAL_DEF( void ) cff_slot_done( FT_GlyphSlot slot ) { slot->internal->glyph_hints = 0; } FT_LOCAL_DEF( FT_Error ) cff_slot_init( FT_GlyphSlot slot ) { CFF_Face face = (CFF_Face)slot->face; CFF_Font font = (CFF_FontRec *)face->extra.data; PSHinter_Service pshinter = (PSHinter_Service)font->pshinter; if ( pshinter ) { FT_Module module; module = FT_Get_Module( slot->face->driver->root.library, "pshinter" ); if ( module ) { T2_Hints_Funcs funcs; funcs = pshinter->get_t2_funcs( module ); slot->internal->glyph_hints = (void*)funcs; } } return 0; } /*************************************************************************/ /* */ /* FACE FUNCTIONS */ /* */ /*************************************************************************/ static FT_String* cff_strcpy( FT_Memory memory, const FT_String* source ) { FT_Error error; FT_String* result = 0; FT_Int len = (FT_Int)ft_strlen( source ); if ( !FT_ALLOC( result, len + 1 ) ) { FT_MEM_COPY( result, source, len ); result[len] = 0; } FT_UNUSED( error ); return result; } FT_LOCAL_DEF( FT_Error ) cff_face_init( FT_Stream stream, FT_Face cffface, /* CFF_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { CFF_Face face = (CFF_Face)cffface; FT_Error error; SFNT_Service sfnt; FT_Service_PsCMaps psnames; PSHinter_Service pshinter; FT_Bool pure_cff = 1; FT_Bool sfnt_format = 0;#if 0 FT_FACE_FIND_GLOBAL_SERVICE( face, sfnt, SFNT ); FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_NAMES ); FT_FACE_FIND_GLOBAL_SERVICE( face, pshinter, POSTSCRIPT_HINTER ); if ( !sfnt ) goto Bad_Format;#else sfnt = (SFNT_Service)FT_Get_Module_Interface( cffface->driver->root.library, "sfnt" ); if ( !sfnt ) goto Bad_Format; FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); pshinter = (PSHinter_Service)FT_Get_Module_Interface( cffface->driver->root.library, "pshinter" );#endif /* create input stream from resource */ if ( FT_STREAM_SEEK( 0 ) ) goto Exit; /* check whether we have a valid OpenType file */ error = sfnt->init_face( stream, face, face_index, num_params, params ); if ( !error ) { if ( face->format_tag != 0x4F54544FL ) /* `OTTO'; OpenType/CFF font */ { FT_TRACE2(( "[not a valid OpenType/CFF font]\n" )); goto Bad_Format; } /* if we are performing a simple font format check, exit immediately */ if ( face_index < 0 ) return CFF_Err_Ok; /* UNDOCUMENTED! A CFF in an SFNT can have only a single font. */ if ( face_index > 0 ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -