26 PSH_Globals ps_debug_globals = NULL;
41 psh_globals_scale_widths( PSH_Globals globals,
44 PSH_Dimension dim = &globals->dimension[direction];
45 PSH_Widths stdw = &dim->stdw;
46 FT_UInt count = stdw->count;
47 PSH_Width width = stdw->widths;
48 PSH_Width stand = width;
49 FT_Fixed scale = dim->scale_mult;
54 width->cur = FT_MulFix( width->org, scale );
55 width->fit = FT_PIX_ROUND( width->cur );
60 for ( ; count > 0; count--, width++ )
65 w = FT_MulFix( width->org, scale );
66 dist = w - stand->cur;
75 width->fit = FT_PIX_ROUND( w );
84 FT_LOCAL_DEF( FT_Pos )
85 psh_dimension_snap_width( PSH_Dimension dimension,
89 FT_Pos width = FT_MulFix( org_width, dimension->scale_mult );
90 FT_Pos best = 64 + 32 + 2;
91 FT_Pos reference = width;
94 for ( n = 0; n < dimension->stdw.count; n++ )
100 w = dimension->stdw.widths[n].cur;
111 if ( width >= reference )
114 if ( width < reference )
120 if ( width > reference )
139 psh_blues_set_zones_0( PSH_Blues target,
143 PSH_Blue_Table top_table,
144 PSH_Blue_Table bot_table )
146 FT_UInt count_top = top_table->count;
147 FT_UInt count_bot = bot_table->count;
153 for ( ; read_count > 1; read_count -= 2 )
155 FT_Int reference, delta;
157 PSH_Blue_Zone zones, zone;
163 if ( first || is_others )
166 delta = read[0] - reference;
168 zones = bot_table->zones;
175 delta = read[1] - reference;
177 zones = top_table->zones;
184 for ( ; count > 0; count--, zone++ )
186 if ( reference < zone->org_ref )
189 if ( reference == zone->org_ref )
191 FT_Int delta0 = zone->org_delta;
198 if ( delta < delta0 )
199 zone->org_delta = delta;
203 if ( delta > delta0 )
204 zone->org_delta = delta;
210 for ( ; count > 0; count-- )
211 zone[count] = zone[count-1];
213 zone->org_ref = reference;
214 zone->org_delta = delta;
225 top_table->count = count_top;
226 bot_table->count = count_bot;
234 psh_blues_set_zones( PSH_Blues target,
237 FT_UInt count_others,
238 FT_Short* other_blues,
242 PSH_Blue_Table top_table, bot_table;
243 FT_UInt count_top, count_bot;
248 top_table = &target->family_top;
249 bot_table = &target->family_bottom;
253 top_table = &target->normal_top;
254 bot_table = &target->normal_bottom;
259 top_table->count = 0;
260 bot_table->count = 0;
263 psh_blues_set_zones_0( target, 0,
264 count, blues, top_table, bot_table );
265 psh_blues_set_zones_0( target, 1,
266 count_others, other_blues, top_table, bot_table );
268 count_top = top_table->count;
269 count_bot = bot_table->count;
274 PSH_Blue_Zone zone = top_table->zones;
277 for ( count = count_top; count > 0; count--, zone++ )
284 delta = zone[1].org_ref - zone[0].org_ref;
285 if ( zone->org_delta > delta )
286 zone->org_delta = delta;
289 zone->org_bottom = zone->org_ref;
290 zone->org_top = zone->org_delta + zone->org_ref;
297 PSH_Blue_Zone zone = bot_table->zones;
300 for ( count = count_bot; count > 0; count--, zone++ )
307 delta = zone[0].org_ref - zone[1].org_ref;
308 if ( zone->org_delta < delta )
309 zone->org_delta = delta;
312 zone->org_top = zone->org_ref;
313 zone->org_bottom = zone->org_delta + zone->org_ref;
319 FT_Int dim, top, bot, delta;
323 zone = top_table->zones;
326 for ( dim = 1; dim >= 0; dim-- )
331 zone->org_bottom -= fuzz;
337 for ( count--; count > 0; count-- )
339 bot = zone[1].org_bottom;
342 if ( delta / 2 < fuzz )
343 zone[0].org_top = zone[1].org_bottom = top + delta / 2;
346 zone[0].org_top = top + fuzz;
347 zone[1].org_bottom = bot - fuzz;
355 zone->org_top = top + fuzz;
357 zone = bot_table->zones;
366 psh_blues_scale_zones( PSH_Blues blues,
372 PSH_Blue_Table table = NULL;
405 if ( scale >= 0x20C49BAL )
406 blues->no_overshoots = FT_BOOL( scale < blues->blue_scale * 8 / 125 );
408 blues->no_overshoots = FT_BOOL( scale * 125 < blues->blue_scale * 8 );
420 FT_Int threshold = blues->blue_shift;
423 while ( threshold > 0 && FT_MulFix( threshold, scale ) > 32 )
426 blues->blue_threshold = threshold;
429 for ( num = 0; num < 4; num++ )
437 table = &blues->normal_top;
440 table = &blues->normal_bottom;
443 table = &blues->family_top;
446 table = &blues->family_bottom;
451 count = table->count;
452 for ( ; count > 0; count--, zone++ )
454 zone->cur_top = FT_MulFix( zone->org_top, scale ) + delta;
455 zone->cur_bottom = FT_MulFix( zone->org_bottom, scale ) + delta;
456 zone->cur_ref = FT_MulFix( zone->org_ref, scale ) + delta;
457 zone->cur_delta = FT_MulFix( zone->org_delta, scale );
460 zone->cur_ref = FT_PIX_ROUND( zone->cur_ref );
463 if ( zone->cur_ref > zone->cur_top )
465 else if ( zone->cur_ref < zone->cur_bottom )
473 for ( num = 0; num < 2; num++ )
475 PSH_Blue_Zone zone1, zone2;
476 FT_UInt count1, count2;
477 PSH_Blue_Table normal, family;
483 normal = &blues->normal_top;
484 family = &blues->family_top;
488 normal = &blues->normal_bottom;
489 family = &blues->family_bottom;
492 zone1 = normal->zones;
493 count1 = normal->count;
495 for ( ; count1 > 0; count1--, zone1++ )
499 zone2 = family->zones;
500 count2 = family->count;
502 for ( ; count2 > 0; count2--, zone2++ )
507 Delta = zone1->org_ref - zone2->org_ref;
511 if ( FT_MulFix( Delta, scale ) < 64 )
513 zone1->cur_top = zone2->cur_top;
514 zone1->cur_bottom = zone2->cur_bottom;
515 zone1->cur_ref = zone2->cur_ref;
516 zone1->cur_delta = zone2->cur_delta;
527 psh_calc_max_height( FT_UInt num,
528 const FT_Short* values,
534 for ( count = 0; count < num; count += 2 )
536 FT_Short cur_height = values[count + 1] - values[count];
539 if ( cur_height > cur_max )
540 cur_max = cur_height;
548 psh_blues_snap_stem( PSH_Blues blues,
551 PSH_Alignment alignment )
553 PSH_Blue_Table table;
560 alignment->align = PSH_BLUE_ALIGN_NONE;
562 no_shoots = blues->no_overshoots;
565 table = &blues->normal_top;
566 count = table->count;
569 for ( ; count > 0; count--, zone++ )
571 delta = SUB_LONG( stem_top, zone->org_bottom );
572 if ( delta < -blues->blue_fuzz )
575 if ( stem_top <= zone->org_top + blues->blue_fuzz )
577 if ( no_shoots || delta <= blues->blue_threshold )
579 alignment->align |= PSH_BLUE_ALIGN_TOP;
580 alignment->align_top = zone->cur_ref;
587 table = &blues->normal_bottom;
588 count = table->count;
589 zone = table->zones + count-1;
591 for ( ; count > 0; count--, zone-- )
593 delta = SUB_LONG( zone->org_top, stem_bot );
594 if ( delta < -blues->blue_fuzz )
597 if ( stem_bot >= zone->org_bottom - blues->blue_fuzz )
599 if ( no_shoots || delta < blues->blue_threshold )
601 alignment->align |= PSH_BLUE_ALIGN_BOT;
602 alignment->align_bot = zone->cur_ref;
619 psh_globals_destroy( PSH_Globals globals )
626 memory = globals->memory;
627 globals->dimension[0].stdw.count = 0;
628 globals->dimension[1].stdw.count = 0;
630 globals->blues.normal_top.count = 0;
631 globals->blues.normal_bottom.count = 0;
632 globals->blues.family_top.count = 0;
633 globals->blues.family_bottom.count = 0;
638 ps_debug_globals = NULL;
645 psh_globals_new( FT_Memory memory,
647 PSH_Globals *aglobals )
649 PSH_Globals globals = NULL;
653 if ( !FT_QNEW( globals ) )
659 globals->memory = memory;
663 PSH_Dimension dim = &globals->dimension[1];
664 PSH_Width write = dim->stdw.widths;
667 write->org = priv->standard_width[0];
670 read = priv->snap_widths;
671 for ( count = priv->num_snap_widths; count > 0; count-- )
678 dim->stdw.count = priv->num_snap_widths + 1;
683 PSH_Dimension dim = &globals->dimension[0];
684 PSH_Width write = dim->stdw.widths;
687 write->org = priv->standard_height[0];
689 read = priv->snap_heights;
690 for ( count = priv->num_snap_heights; count > 0; count-- )
697 dim->stdw.count = priv->num_snap_heights + 1;
701 psh_blues_set_zones( &globals->blues, priv->num_blue_values,
702 priv->blue_values, priv->num_other_blues,
703 priv->other_blues, priv->blue_fuzz, 0 );
705 psh_blues_set_zones( &globals->blues, priv->num_family_blues,
706 priv->family_blues, priv->num_family_other_blues,
707 priv->family_other_blues, priv->blue_fuzz, 1 );
712 FT_Short max_height = 1;
715 max_height = psh_calc_max_height( priv->num_blue_values,
718 max_height = psh_calc_max_height( priv->num_other_blues,
721 max_height = psh_calc_max_height( priv->num_family_blues,
724 max_height = psh_calc_max_height( priv->num_family_other_blues,
725 priv->family_other_blues,
729 max_scale = FT_DivFix( 1000, max_height );
730 globals->blues.blue_scale = priv->blue_scale < max_scale
735 globals->blues.blue_shift = priv->blue_shift;
736 globals->blues.blue_fuzz = priv->blue_fuzz;
738 globals->dimension[0].scale_mult = 0;
739 globals->dimension[0].scale_delta = 0;
740 globals->dimension[1].scale_mult = 0;
741 globals->dimension[1].scale_delta = 0;
744 ps_debug_globals = globals;
754 psh_globals_set_scale( PSH_Globals globals,
763 dim = &globals->dimension[0];
764 if ( x_scale != dim->scale_mult ||
765 x_delta != dim->scale_delta )
767 dim->scale_mult = x_scale;
768 dim->scale_delta = x_delta;
770 psh_globals_scale_widths( globals, 0 );
773 dim = &globals->dimension[1];
774 if ( y_scale != dim->scale_mult ||
775 y_delta != dim->scale_delta )
777 dim->scale_mult = y_scale;
778 dim->scale_delta = y_delta;
780 psh_globals_scale_widths( globals, 1 );
781 psh_blues_scale_zones( &globals->blues, y_scale, y_delta );
787 psh_globals_funcs_init( PSH_Globals_FuncsRec* funcs )
789 funcs->create = psh_globals_new;
790 funcs->set_scale = psh_globals_set_scale;
791 funcs->destroy = psh_globals_destroy;