📄 pshalgo1.c
字号:
for ( count = 0; count < table->num_hints; count++ ) { hint = table->sort[count]; if ( psh1_hint_is_active( hint ) ) {#if 1 FT_Pos pos = FT_MulFix( hint->org_pos, scale ) + delta; FT_Pos len = FT_MulFix( hint->org_len, scale ); FT_Pos fit_center; FT_Pos fit_len; PSH_AlignmentRec align; /* compute fitted width/height */ fit_len = psh_dimension_snap_width( dim, hint->org_len ); if ( fit_len < 64 ) fit_len = 64; else fit_len = ( fit_len + 32 ) & -64; hint->cur_len = fit_len; /* check blue zones for horizontal stems */ align.align = PSH_BLUE_ALIGN_NONE; align.align_bot = align.align_top = 0; if ( !vertical ) { psh_blues_snap_stem( &globals->blues, hint->org_pos + hint->org_len, hint->org_pos, &align ); } switch ( align.align ) { case PSH_BLUE_ALIGN_TOP: /* the top of the stem is aligned against a blue zone */ hint->cur_pos = align.align_top - fit_len; break; case PSH_BLUE_ALIGN_BOT: /* the bottom of the stem is aligned against a blue zone */ hint->cur_pos = align.align_bot; break; case PSH_BLUE_ALIGN_TOP | PSH_BLUE_ALIGN_BOT: /* both edges of the stem are aligned against blue zones */ hint->cur_pos = align.align_bot; hint->cur_len = align.align_top - align.align_bot; break; default: /* normal processing */ if ( ( fit_len / 64 ) & 1 ) { /* odd number of pixels */ fit_center = ( ( pos + ( len >> 1 ) ) & -64 ) + 32; } else { /* even number of pixels */ fit_center = ( pos + ( len >> 1 ) + 32 ) & -64; } hint->cur_pos = fit_center - ( fit_len >> 1 ); }# else hint->cur_pos = ( FT_MulFix( hint->org_pos, scale ) + delta + 32 ) & -64; hint->cur_len = FT_MulFix( hint->org_len, scale );# endif#ifdef DEBUG_HINTER if ( ps1_debug_hint_func ) ps1_debug_hint_func( hint, vertical );#endif } } } return 0; } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** POINTS INTERPOLATION ROUTINES *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/#define PSH1_ZONE_MIN -3200000#define PSH1_ZONE_MAX +3200000#define xxDEBUG_ZONES#ifdef DEBUG_ZONES#include <stdio.h> static void psh1_print_zone( PSH1_Zone zone ) { printf( "zone [scale,delta,min,max] = [%.3f,%.3f,%d,%d]\n", zone->scale / 65536.0, zone->delta / 64.0, zone->min, zone->max ); }#else#define psh1_print_zone( x ) do { } while ( 0 )#endif /* setup interpolation zones once the hints have been grid-fitted */ /* by the optimizer */ static void psh1_hint_table_setup_zones( PSH1_Hint_Table table, FT_Fixed scale, FT_Fixed delta ) { FT_UInt count; PSH1_Zone zone; PSH1_Hint *sort, hint, hint2; zone = table->zones; /* special case, no hints defined */ if ( table->num_hints == 0 ) { zone->scale = scale; zone->delta = delta; zone->min = PSH1_ZONE_MIN; zone->max = PSH1_ZONE_MAX; table->num_zones = 1; table->zone = zone; return; } /* the first zone is before the first hint */ /* x' = (x-x0)*s + x0' = x*s + ( x0' - x0*s ) */ sort = table->sort; hint = sort[0]; zone->scale = scale; zone->delta = hint->cur_pos - FT_MulFix( hint->org_pos, scale ); zone->min = PSH1_ZONE_MIN; zone->max = hint->org_pos; psh1_print_zone( zone ); zone++; for ( count = table->num_hints; count > 0; count-- ) { FT_Fixed scale2; if ( hint->org_len > 0 ) { /* setup a zone for inner-stem interpolation */ /* (x' - x0') = (x - x0)*(x1'-x0')/(x1-x0) */ /* x' = x*s2 + x0' - x0*s2 */ scale2 = FT_DivFix( hint->cur_len, hint->org_len ); zone->scale = scale2; zone->min = hint->org_pos; zone->max = hint->org_pos + hint->org_len; zone->delta = hint->cur_pos - FT_MulFix( zone->min, scale2 ); psh1_print_zone( zone ); zone++; } if ( count == 1 ) break; sort++; hint2 = sort[0]; /* setup zone for inter-stem interpolation */ /* (x'-x1') = (x-x1)*(x2'-x1')/(x2-x1) */ /* x' = x*s3 + x1' - x1*s3 */ scale2 = FT_DivFix( hint2->cur_pos - (hint->cur_pos + hint->cur_len), hint2->org_pos - (hint->org_pos + hint->org_len) ); zone->scale = scale2; zone->min = hint->org_pos + hint->org_len; zone->max = hint2->org_pos; zone->delta = hint->cur_pos + hint->cur_len - FT_MulFix( zone->min, scale2 ); psh1_print_zone( zone ); zone++; hint = hint2; } /* the last zone */ zone->scale = scale; zone->min = hint->org_pos + hint->org_len; zone->max = PSH1_ZONE_MAX; zone->delta = hint->cur_pos + hint->cur_len - FT_MulFix( zone->min, scale ); psh1_print_zone( zone ); zone++; table->num_zones = zone - table->zones; table->zone = table->zones; } /* tune a single coordinate with the current interpolation zones */ static FT_Pos psh1_hint_table_tune_coord( PSH1_Hint_Table table, FT_Int coord ) { PSH1_Zone zone; zone = table->zone; if ( coord < zone->min ) { do { if ( zone == table->zones ) break; zone--; } while ( coord < zone->min ); table->zone = zone; } else if ( coord > zone->max ) { do { if ( zone == table->zones + table->num_zones - 1 ) break; zone++; } while ( coord > zone->max ); table->zone = zone; } return FT_MulFix( coord, zone->scale ) + zone->delta; } /* tune a given outline with current interpolation zones. */ /* The function only works in a single dimension. */ static void psh1_hint_table_tune_outline( PSH1_Hint_Table table, FT_Outline* outline, PSH_Globals globals, FT_Int vertical ) { FT_UInt count, first, last; PS_Mask_Table hint_masks = table->hint_masks; PS_Mask mask; PSH_Dimension dim = &globals->dimension[vertical]; FT_Fixed scale = dim->scale_mult; FT_Fixed delta = dim->scale_delta; if ( hint_masks && hint_masks->num_masks > 0 ) { first = 0; mask = hint_masks->masks; count = hint_masks->num_masks; for ( ; count > 0; count--, mask++ ) { last = mask->end_point; if ( last > first ) { FT_Vector* vec; FT_Int count2; psh1_hint_table_activate_mask( table, mask ); psh1_hint_table_optimize( table, globals, outline, vertical ); psh1_hint_table_setup_zones( table, scale, delta ); last = mask->end_point; vec = outline->points + first; count2 = last - first; for ( ; count2 > 0; count2--, vec++ ) { FT_Pos x, *px; px = vertical ? &vec->x : &vec->y; x = *px; *px = psh1_hint_table_tune_coord( table, (FT_Int)x ); } } first = last; } } else /* no hints in this glyph, simply scale the outline */ { FT_Vector* vec; vec = outline->points; count = outline->n_points; if ( vertical ) { for ( ; count > 0; count--, vec++ ) vec->x = FT_MulFix( vec->x, scale ) + delta; } else { for ( ; count > 0; count--, vec++ ) vec->y = FT_MulFix( vec->y, scale ) + delta; } } } /*************************************************************************/ /*************************************************************************/ /***** *****/ /***** HIGH-LEVEL INTERFACE *****/ /***** *****/ /*************************************************************************/ /*************************************************************************/ FT_Error ps1_hints_apply( PS_Hints ps_hints, FT_Outline* outline, PSH_Globals globals ) { PSH1_Hint_TableRec hints; FT_Error error = 0; FT_Int dimension; for ( dimension = 1; dimension >= 0; dimension-- ) { PS_Dimension dim = &ps_hints->dimension[dimension]; /* initialize hints table */ ft_memset( &hints, 0, sizeof ( hints ) ); error = psh1_hint_table_init( &hints, &dim->hints, &dim->masks, &dim->counters, ps_hints->memory ); if ( error ) goto Exit; psh1_hint_table_tune_outline( &hints, outline, globals, dimension ); psh1_hint_table_done( &hints, ps_hints->memory ); } Exit: return error; }/* END */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -