diff options
Diffstat (limited to 'src/pshinter/pshrec.c')
-rw-r--r-- | src/pshinter/pshrec.c | 570 |
1 files changed, 329 insertions, 241 deletions
diff --git a/src/pshinter/pshrec.c b/src/pshinter/pshrec.c index 250d9c46c..c78d55258 100644 --- a/src/pshinter/pshrec.c +++ b/src/pshinter/pshrec.c @@ -1,3 +1,21 @@ +/***************************************************************************/ +/* */ +/* pshrec.c */ +/* */ +/* FreeType PostScript hints recorder (body). */ +/* */ +/* Copyright 2001 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_FREETYPE_H #include FT_INTERNAL_OBJECTS_H @@ -7,21 +25,21 @@ #ifdef DEBUG_HINTER - extern PS_Hints ps_debug_hints = 0; - extern int ps_debug_no_horz_hints = 0; - extern int ps_debug_no_vert_hints = 0; + extern PS_Hints ps_debug_hints = 0; + extern int ps_debug_no_horz_hints = 0; + extern int ps_debug_no_vert_hints = 0; #endif - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** PS_HINT MANAGEMENT *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** PS_HINT MANAGEMENT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - /* destroy hints table */ + /* destroy hints table */ static void ps_hint_table_done( PS_Hint_Table table, FT_Memory memory ) @@ -32,7 +50,7 @@ } - /* ensure that a table can contain "count" elements */ + /* ensure that a table can contain "count" elements */ static FT_Error ps_hint_table_ensure( PS_Hint_Table table, FT_UInt count, @@ -42,6 +60,7 @@ FT_UInt new_max = count; FT_Error error = 0; + if ( new_max > old_max ) { /* try to grow the table */ @@ -62,16 +81,18 @@ FT_UInt count; PS_Hint hint = 0; + count = table->num_hints; count++; if ( count >= table->max_hints ) { error = ps_hint_table_ensure( table, count, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; } - hint = table->hints + count-1; + hint = table->hints + count - 1; hint->pos = 0; hint->len = 0; hint->flags = 0; @@ -84,15 +105,15 @@ } - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** PS_MASK MANAGEMENT *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** PS_MASK MANAGEMENT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - /* destroy mask */ + /* destroy mask */ static void ps_mask_done( PS_Mask mask, FT_Memory memory ) @@ -104,28 +125,28 @@ } - /* ensure that a mask can contain "count" bits */ + /* ensure that a mask can contain "count" bits */ static FT_Error ps_mask_ensure( PS_Mask mask, FT_UInt count, FT_Memory memory ) { - FT_UInt old_max = (mask->max_bits + 7) >> 3; - FT_UInt new_max = (count + 7) >> 3; + FT_UInt old_max = ( mask->max_bits + 7 ) >> 3; + FT_UInt new_max = ( count + 7 ) >> 3; FT_Error error = 0; + if ( new_max > old_max ) { new_max = ( new_max + 7 ) & -8; if ( !REALLOC_ARRAY( mask->bytes, old_max, new_max, FT_Byte ) ) - mask->max_bits = new_max*8; + mask->max_bits = new_max * 8; } return error; } - - /* test a bit value in a given mask */ + /* test a bit value in a given mask */ static FT_Int ps_mask_test_bit( PS_Mask mask, FT_Int index ) @@ -133,26 +154,27 @@ if ( (FT_UInt)index >= mask->num_bits ) return 0; - return mask->bytes[index >> 3] & (0x80 >> (index & 7)); + return mask->bytes[index >> 3] & ( 0x80 >> ( index & 7 ) ); } - /* clear a given bit */ + /* clear a given bit */ static void ps_mask_clear_bit( PS_Mask mask, FT_Int index ) { FT_Byte* p; + if ( (FT_UInt)index >= mask->num_bits ) return; - p = mask->bytes + (index >> 3); - p[0] = (FT_Byte)( p[0] & ~(0x80 >> (index & 7)) ); + p = mask->bytes + ( index >> 3 ); + p[0] = (FT_Byte)( p[0] & ~( 0x80 >> ( index & 7 ) ) ); } - /* set a given bit, eventually grow the mask */ + /* set a given bit, possibly grow the mask */ static FT_Error ps_mask_set_bit( PS_Mask mask, FT_Int index, @@ -161,26 +183,28 @@ FT_Error error = 0; FT_Byte* p; + if ( index < 0 ) goto Exit; if ( (FT_UInt)index >= mask->num_bits ) { - error = ps_mask_ensure( mask, index+1, memory ); - if (error) goto Exit; + error = ps_mask_ensure( mask, index + 1, memory ); + if ( error ) + goto Exit; - mask->num_bits = index+1; + mask->num_bits = index + 1; } - p = mask->bytes + (index >> 3); - p[0] = (FT_Byte)( p[0] | (0x80 >> (index & 7)) ); + p = mask->bytes + ( index >> 3 ); + p[0] = (FT_Byte)( p[0] | ( 0x80 >> ( index & 7 ) ) ); Exit: return error; } - /* destroy mask table */ + /* destroy mask table */ static void ps_mask_table_done( PS_Mask_Table table, FT_Memory memory ) @@ -188,6 +212,7 @@ FT_UInt count = table->max_masks; PS_Mask mask = table->masks; + for ( ; count > 0; count--, mask++ ) ps_mask_done( mask, memory ); @@ -197,7 +222,7 @@ } - /* ensure that a mask table can contain "count" masks */ + /* ensure that a mask table can contain "count" masks */ static FT_Error ps_mask_table_ensure( PS_Mask_Table table, FT_UInt count, @@ -207,9 +232,10 @@ FT_UInt new_max = count; FT_Error error = 0; + if ( new_max > old_max ) { - new_max = (new_max+7) & -8; + new_max = ( new_max + 7 ) & -8; if ( !REALLOC_ARRAY( table->masks, old_max, new_max, PS_MaskRec ) ) table->max_masks = new_max; } @@ -217,7 +243,7 @@ } - /* allocate a new mask in a table */ + /* allocate a new mask in a table */ static FT_Error ps_mask_table_alloc( PS_Mask_Table table, FT_Memory memory, @@ -225,7 +251,8 @@ { FT_UInt count; FT_Error error = 0; - PS_Mask mask = 0; + PS_Mask mask = 0; + count = table->num_masks; count++; @@ -233,7 +260,8 @@ if ( count > table->max_masks ) { error = ps_mask_table_ensure( table, count, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; } mask = table->masks + count - 1; @@ -247,7 +275,7 @@ } - /* return last hint mask in a table, create one if the table is empty */ + /* return last hint mask in a table, create one if the table is empty */ static FT_Error ps_mask_table_last( PS_Mask_Table table, FT_Memory memory, @@ -257,14 +285,16 @@ FT_UInt count; PS_Mask mask; + count = table->num_masks; if ( count == 0 ) { error = ps_mask_table_alloc( table, memory, &mask ); - if (error) goto Exit; + if ( error ) + goto Exit; } else - mask = table->masks + count-1; + mask = table->masks + count - 1; Exit: *amask = mask; @@ -272,7 +302,7 @@ } - /* set a new mask to a given bit range */ + /* set a new mask to a given bit range */ static FT_Error ps_mask_table_set_bits( PS_Mask_Table table, FT_Byte* source, @@ -283,23 +313,27 @@ FT_Error error = 0; PS_Mask mask; + /* allocate new mask, and grow it to "bit_count" bits */ error = ps_mask_table_alloc( table, memory, &mask ); - if (error) goto Exit; + if ( error ) + goto Exit; error = ps_mask_ensure( mask, bit_count, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; mask->num_bits = bit_count; /* now, copy bits */ { - FT_Byte* read = source + (bit_pos >> 3); - FT_Int rmask = 0x80 >> (bit_pos & 7); + FT_Byte* read = source + ( bit_pos >> 3 ); + FT_Int rmask = 0x80 >> ( bit_pos & 7 ); FT_Byte* write = mask->bytes; FT_Int wmask = 0x80; FT_Int val; + for ( ; bit_count > 0; bit_count-- ) { val = write[0] & ~wmask; @@ -307,7 +341,7 @@ if ( read[0] & rmask ) val |= wmask; - write[0] = (FT_Byte) val; + write[0] = (FT_Byte)val; rmask >>= 1; if ( rmask == 0 ) @@ -330,20 +364,21 @@ } - /* test wether two masks in a table intersect */ + /* test whether two masks in a table intersect */ static FT_Int ps_mask_table_test_intersect( PS_Mask_Table table, FT_Int index1, FT_Int index2 ) { - PS_Mask mask1 = table->masks + index1; - PS_Mask mask2 = table->masks + index2; + PS_Mask mask1 = table->masks + index1; + PS_Mask mask2 = table->masks + index2; FT_Byte* p1 = mask1->bytes; FT_Byte* p2 = mask2->bytes; FT_UInt count1 = mask1->num_bits; FT_UInt count2 = mask2->num_bits; FT_UInt count; + count = ( count1 <= count2 ) ? count1 : count2; for ( ; count >= 8; count -= 8 ) { @@ -357,11 +392,11 @@ if ( count == 0 ) return 0; - return ( p1[0] & p2[0] ) & ~(0xFF >> count); + return ( p1[0] & p2[0] ) & ~( 0xFF >> count ); } - /* merge two masks, used by ps_mask_table_merge_all */ + /* merge two masks, used by ps_mask_table_merge_all */ static FT_Error ps_mask_table_merge( PS_Mask_Table table, FT_Int index1, @@ -371,6 +406,7 @@ FT_UInt temp; FT_Error error = 0; + /* swap index1 and index2 so that index1 < index2 */ if ( index1 > index2 ) { @@ -382,12 +418,13 @@ if ( index1 < index2 && index1 >= 0 && index2 < (FT_Int)table->num_masks ) { /* we need to merge the bitsets of index1 and index2 with a */ - /* simple union.. */ - PS_Mask mask1 = table->masks + index1; - PS_Mask mask2 = table->masks + index2; - FT_UInt count1 = mask1->num_bits; - FT_UInt count2 = mask2->num_bits; - FT_Int delta; + /* simple union */ + PS_Mask mask1 = table->masks + index1; + PS_Mask mask2 = table->masks + index2; + FT_UInt count1 = mask1->num_bits; + FT_UInt count2 = mask2->num_bits; + FT_Int delta; + if ( count2 > 0 ) { @@ -395,21 +432,24 @@ FT_Byte* read; FT_Byte* write; + /* if "count2" is greater than "count1", we need to grow the */ - /* first bitset, and clear the highest bits.. */ + /* first bitset, and clear the highest bits */ if ( count2 > count1 ) { error = ps_mask_ensure( mask1, count2, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; for ( pos = count1; pos < count2; pos++ ) ps_mask_clear_bit( mask1, pos ); } - /* merge (union) the bitsets */ + /* merge (unite) the bitsets */ read = mask2->bytes; write = mask1->bytes; - pos = (FT_UInt)((count2+7) >> 3); + pos = (FT_UInt)( ( count2 + 7 ) >> 3 ); + for ( ; pos > 0; pos-- ) { write[0] = (FT_Byte)( write[0] | read[0] ); @@ -418,18 +458,19 @@ } } - /* now, remove "mask2" from the list, we need to keep the masks */ - /* sorted in order of importance, so move table elements.. */ + /* Now, remove "mask2" from the list. We need to keep the masks */ + /* sorted in order of importance, so move table elements. */ mask2->num_bits = 0; mask2->end_point = 0; - delta = table->num_masks-1 - index2; /* number of masks to move */ + delta = table->num_masks - 1 - index2; /* number of masks to move */ if ( delta > 0 ) { /* move to end of table for reuse */ PS_MaskRec dummy = *mask2; - memmove( mask2, mask2+1, delta*sizeof(PS_MaskRec) ); + + memmove( mask2, mask2 + 1, delta * sizeof ( PS_MaskRec ) ); mask2[delta] = dummy; } @@ -439,13 +480,15 @@ else FT_ERROR(( "%s: ignoring invalid indices (%d,%d)\n", index1, index2 )); + Exit: return error; } - /* try to merge all masks in a given table, this is used to merge */ - /* all counter masks into independent counter "paths" */ - /* */ + + /* Try to merge all masks in a given table. This is used to merge */ + /* all counter masks into independent counter "paths". */ + /* */ static FT_Error ps_mask_table_merge_all( PS_Mask_Table table, FT_Memory memory ) @@ -453,34 +496,37 @@ FT_Int index1, index2; FT_Error error = 0; - for ( index1 = table->num_masks-1; index1 > 0; index1-- ) + + for ( index1 = table->num_masks - 1; index1 > 0; index1-- ) { - for ( index2 = index1-1; index2 >= 0; index2-- ) + for ( index2 = index1 - 1; index2 >= 0; index2-- ) { if ( ps_mask_table_test_intersect( table, index1, index2 ) ) { error = ps_mask_table_merge( table, index2, index1, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; break; } } } + Exit: return error; } - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** PS_DIMENSION MANAGEMENT *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** PS_DIMENSION MANAGEMENT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - /* finalize a given dimension */ + /* finalize a given dimension */ static void ps_dimension_done( PS_Dimension dimension, FT_Memory memory ) @@ -491,7 +537,7 @@ } - /* initialise a given dimension */ + /* initialize a given dimension */ static void ps_dimension_init( PS_Dimension dimension ) { @@ -502,7 +548,8 @@ #if 0 - /* set a bit at a given index in the current hint mask */ + + /* set a bit at a given index in the current hint mask */ static FT_Error ps_dimension_set_mask_bit( PS_Dimension dim, FT_UInt index, @@ -511,35 +558,39 @@ PS_Mask mask; FT_Error error = 0; + /* get last hint mask */ error = ps_mask_table_last( &dim->masks, memory, &mask ); - if (error) goto Exit; + if ( error ) + goto Exit; error = ps_mask_set_bit( mask, index, memory ); Exit: return error; } + #endif - /* set the end point in a mask, called from "End" & "Reset" methods */ + /* set the end point in a mask, called from "End" & "Reset" methods */ static void ps_dimension_end_mask( PS_Dimension dim, FT_UInt end_point ) { - FT_UInt count = dim->masks.num_masks; - PS_Mask mask; + FT_UInt count = dim->masks.num_masks; + PS_Mask mask; + if ( count > 0 ) { - mask = dim->masks.masks + count-1; + mask = dim->masks.masks + count - 1; mask->end_point = end_point; } } - /* set the end point in the current mask, then create a new empty one */ - /* (called by "Reset" method) */ + /* set the end point in the current mask, then create a new empty one */ + /* (called by "Reset" method) */ static FT_Error ps_dimension_reset_mask( PS_Dimension dim, FT_UInt end_point, @@ -547,6 +598,7 @@ { PS_Mask mask; + /* end current mask */ ps_dimension_end_mask( dim, end_point ); @@ -555,7 +607,7 @@ } - /* set a new mask, called from the "T2Stem" method */ + /* set a new mask, called from the "T2Stem" method */ static FT_Error ps_dimension_set_mask_bits( PS_Dimension dim, const FT_Byte* source, @@ -566,20 +618,22 @@ { FT_Error error = 0; + /* reset current mask, if any */ error = ps_dimension_reset_mask( dim, end_point, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; /* set bits in new mask */ error = ps_mask_table_set_bits( &dim->masks, (FT_Byte*)source, - source_pos, source_bits, memory ); + source_pos, source_bits, memory ); + Exit: return error; } - - /* add a new single stem (called from "T1Stem" method) */ + /* add a new single stem (called from "T1Stem" method) */ static FT_Error ps_dimension_add_t1stem( PS_Dimension dim, FT_Int pos, @@ -590,6 +644,7 @@ FT_Error error = 0; FT_UInt flags = 0; + /* detect ghost stem */ if ( len < 0 ) { @@ -602,15 +657,16 @@ len = 0; } - if (aindex) + if ( aindex ) *aindex = -1; /* now, lookup stem in the current hints table */ { - PS_Mask mask; - FT_UInt index; - FT_UInt max = dim->hints.num_hints; - PS_Hint hint = dim->hints.hints; + PS_Mask mask; + FT_UInt index; + FT_UInt max = dim->hints.num_hints; + PS_Hint hint = dim->hints.hints; + for ( index = 0; index < max; index++, hint++ ) { @@ -622,7 +678,8 @@ if ( index >= max ) { error = ps_hint_table_alloc( &dim->hints, memory, &hint ); - if (error) goto Exit; + if ( error ) + goto Exit; hint->pos = pos; hint->len = len; @@ -631,20 +688,23 @@ /* now, store the hint in the current mask */ error = ps_mask_table_last( &dim->masks, memory, &mask ); - if (error) goto Exit; + if ( error ) + goto Exit; error = ps_mask_set_bit( mask, index, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; if ( aindex ) *aindex = (FT_Int)index; } + Exit: return error; } - /* add a "hstem3/vstem3" counter to our dimension table */ + /* add a "hstem3/vstem3" counter to our dimension table */ static FT_Error ps_dimension_add_counter( PS_Dimension dim, FT_Int hint1, @@ -656,39 +716,44 @@ FT_UInt count = dim->counters.num_masks; PS_Mask counter = dim->counters.masks; + /* try to find an existing counter mask that already uses */ - /* one of these stems here.. */ + /* one of these stems here */ for ( ; count > 0; count--, counter++ ) { if ( ps_mask_test_bit( counter, hint1 ) || ps_mask_test_bit( counter, hint2 ) || ps_mask_test_bit( counter, hint3 ) ) - break; + break; } /* creat a new counter when needed */ if ( count == 0 ) { error = ps_mask_table_alloc( &dim->counters, memory, &counter ); - if (error) goto Exit; + if ( error ) + goto Exit; } /* now, set the bits for our hints in the counter mask */ error = ps_mask_set_bit( counter, hint1, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; error = ps_mask_set_bit( counter, hint2, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; error = ps_mask_set_bit( counter, hint3, memory ); - if (error) goto Exit; + if ( error ) + goto Exit; Exit: return error; } - /* end of recording session for a given dimension */ + /* end of recording session for a given dimension */ static FT_Error ps_dimension_end( PS_Dimension dim, FT_UInt end_point, @@ -701,22 +766,23 @@ return ps_mask_table_merge_all( &dim->counters, memory ); } - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** PS_RECORDER MANAGEMENT *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** PS_RECORDER MANAGEMENT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - /* destroy hints */ + /* destroy hints */ FT_LOCAL void - ps_hints_done( PS_Hints hints ) + ps_hints_done( PS_Hints hints ) { FT_Memory memory = hints->memory; + ps_dimension_done( &hints->dimension[0], memory ); ps_dimension_done( &hints->dimension[1], memory ); @@ -724,44 +790,44 @@ hints->memory = 0; } + FT_LOCAL FT_Error - ps_hints_init( PS_Hints hints, + ps_hints_init( PS_Hints hints, FT_Memory memory ) { - memset( hints, 0, sizeof(*hints) ); + memset( hints, 0, sizeof ( *hints ) ); hints->memory = memory; return 0; } - /* initialise a hints for a new session */ + + /* initialize a hints for a new session */ static void ps_hints_open( PS_Hints hints, PS_Hint_Type hint_type ) { - switch (hint_type) + switch ( hint_type ) { - case PS_HINT_TYPE_1: - case PS_HINT_TYPE_2: - { - hints->error = 0; - hints->hint_type = hint_type; + case PS_HINT_TYPE_1: + case PS_HINT_TYPE_2: + hints->error = 0; + hints->hint_type = hint_type; - ps_dimension_init( &hints->dimension[0] ); - ps_dimension_init( &hints->dimension[1] ); - } - break; + ps_dimension_init( &hints->dimension[0] ); + ps_dimension_init( &hints->dimension[1] ); + break; - default: - hints->error = FT_Err_Invalid_Argument; - hints->hint_type = hint_type; + default: + hints->error = FT_Err_Invalid_Argument; + hints->hint_type = hint_type; - FT_ERROR(( "%s.init: invalid charstring type !!\n", "t1fitter.hints" )); + FT_ERROR(( "%s.init: invalid charstring type!\n", "pshrec.hints" )); + break; } } - - /* add one or more stems to the current hints table */ + /* add one or more stems to the current hints table */ static void ps_hints_stem( PS_Hints hints, FT_Int dimension, @@ -775,66 +841,70 @@ { FT_ERROR(( "ps.hints.stem: invalid dimension (%d) used\n", dimension )); - dimension = (dimension != 0); + dimension = ( dimension != 0 ); } /* record the stems in the current hints/masks table */ switch ( hints->hint_type ) { - case PS_HINT_TYPE_1: /* Type 1 "hstem" or "vstem" operator */ - case PS_HINT_TYPE_2: /* Type 2 "hstem" or "vstem" operator */ + case PS_HINT_TYPE_1: /* Type 1 "hstem" or "vstem" operator */ + case PS_HINT_TYPE_2: /* Type 2 "hstem" or "vstem" operator */ + { + PS_Dimension dim = &hints->dimension[dimension]; + + + for ( ; count > 0; count--, stems += 2 ) { - PS_Dimension dim = &hints->dimension[dimension]; + FT_Error error; + FT_Memory memory = hints->memory; + - for ( ; count > 0; count--, stems += 2 ) + error = ps_dimension_add_t1stem( dim, stems[0], stems[1], + memory, NULL ); + if ( error ) { - FT_Error error; - FT_Memory memory = hints->memory; - - error = ps_dimension_add_t1stem( dim, stems[0], stems[1], - memory, NULL ); - if (error) - { - FT_ERROR(( "t1f.hints.stem: could not add stem" - " (%d,%d) to hints table\n", stems[0], stems[1] )); - - hints->error = error; - return; - }; + FT_ERROR(( "ps.hints.stem: could not add stem" + " (%d,%d) to hints table\n", stems[0], stems[1] )); + + hints->error = error; + return; } } break; + } default: - FT_ERROR(( "t1f.hints.stem: called with invalid hint type (%d)\n", + FT_ERROR(( "ps.hints.stem: called with invalid hint type (%d)\n", hints->hint_type )); - ; + break; } } } - /* add one Type1 counter stem to the current hints table */ + /* add one Type1 counter stem to the current hints table */ static void ps_hints_t1stem3( PS_Hints hints, FT_Int dimension, FT_Long* stems ) { - FT_Error error = 0; + FT_Error error = 0; - if (!hints->error) + + if ( !hints->error ) { PS_Dimension dim; FT_Memory memory = hints->memory; FT_Int count; FT_Int index[3]; + /* limit "dimension" to 0..1 */ if ( dimension < 0 || dimension > 1 ) { - FT_ERROR(( "t1f.hints.stem: invalid dimension (%d) used\n", + FT_ERROR(( "ps.hints.stem: invalid dimension (%d) used\n", dimension )); - dimension = (dimension != 0); + dimension = ( dimension != 0 ); } dim = &hints->dimension[dimension]; @@ -846,18 +916,20 @@ for ( count = 0; count < 3; count++, stems += 2 ) { error = ps_dimension_add_t1stem( dim, stems[0], stems[1], - memory, &index[count] ); - if (error) goto Fail; + memory, &index[count] ); + if ( error ) + goto Fail; } /* now, add the hints to the counters table */ error = ps_dimension_add_counter( dim, index[0], index[1], - index[2], memory ); - if (error) goto Fail; + index[2], memory ); + if ( error ) + goto Fail; } else { - FT_ERROR(( "t1f.hints.stem3: called with invalid hint type !!\n" )); + FT_ERROR(( "ps.hints.stem3: called with invalid hint type!\n" )); error = FT_Err_Invalid_Argument; goto Fail; } @@ -866,32 +938,35 @@ return; Fail: - FT_ERROR(( "t1f.hints.stem3: could not add counter stems to table\n" )); + FT_ERROR(( "ps.hints.stem3: could not add counter stems to table\n" )); hints->error = error; } - - /* reset hints (only with Type 1 hints) */ + /* reset hints (only with Type 1 hints) */ static void ps_hints_t1reset( PS_Hints hints, FT_UInt end_point ) { FT_Error error = 0; + if ( !hints->error ) { FT_Memory memory = hints->memory; + if ( hints->hint_type == PS_HINT_TYPE_1 ) { error = ps_dimension_reset_mask( &hints->dimension[0], - end_point, memory ); - if (error) goto Fail; + end_point, memory ); + if ( error ) + goto Fail; error = ps_dimension_reset_mask( &hints->dimension[1], - end_point, memory ); - if (error) goto Fail; + end_point, memory ); + if ( error ) + goto Fail; } else { @@ -907,7 +982,7 @@ } - /* Type2 "hintmask" operator, add a new hintmask to each direction */ + /* Type2 "hintmask" operator, add a new hintmask to each direction */ static void ps_hints_t2mask( PS_Hints hints, FT_UInt end_point, @@ -916,6 +991,7 @@ { FT_Error error; + if ( !hints->error ) { PS_Dimension dim = hints->dimension; @@ -923,23 +999,26 @@ FT_UInt count1 = dim[0].hints.num_hints; FT_UInt count2 = dim[1].hints.num_hints; - /* check bit count, must be equal to current total hint count */ + + /* check bit count; must be equal to current total hint count */ if ( bit_count != count1 + count2 ) { error = FT_Err_Invalid_Argument; FT_ERROR(( "%s: called with invalid bitcount %d (instead of %d)\n", - bit_count, count1+count2 )); + bit_count, count1 + count2 )); goto Fail; } /* set-up new horizontal and vertical hint mask now */ error = ps_dimension_set_mask_bits( &dim[0], bytes, 0, count1, end_point, memory ); - if (error) goto Fail; + if ( error ) + goto Fail; error = ps_dimension_set_mask_bits( &dim[1], bytes, count1, count2, end_point, memory ); - if (error) goto Fail; + if ( error ) + goto Fail; } return; @@ -955,6 +1034,7 @@ { FT_Error error; + if ( !hints->error ) { PS_Dimension dim = hints->dimension; @@ -962,23 +1042,26 @@ FT_UInt count1 = dim[0].hints.num_hints; FT_UInt count2 = dim[1].hints.num_hints; + /* check bit count, must be equal to current total hint count */ if ( bit_count != count1 + count2 ) { error = FT_Err_Invalid_Argument; FT_ERROR(( "%s: called with invalid bitcount %d (instead of %d)\n", - bit_count, count1+count2 )); + bit_count, count1 + count2 )); goto Fail; } /* set-up new horizontal and vertical hint mask now */ error = ps_dimension_set_mask_bits( &dim[0], bytes, 0, count1, - 0, memory ); - if (error) goto Fail; + 0, memory ); + if ( error ) + goto Fail; error = ps_dimension_set_mask_bits( &dim[1], bytes, count1, count2, - 0, memory ); - if (error) goto Fail; + 0, memory ); + if ( error ) + goto Fail; } return; @@ -987,42 +1070,43 @@ } - - /* end recording session */ + /* end recording session */ static FT_Error ps_hints_close( PS_Hints hints, FT_UInt end_point ) { FT_Error error; + error = hints->error; - if (!error) + if ( !error ) { - FT_Error error; - FT_Memory memory = hints->memory; + FT_Memory memory = hints->memory; PS_Dimension dim = hints->dimension; + error = ps_dimension_end( &dim[0], end_point, memory ); - if (!error) + if ( !error ) { error = ps_dimension_end( &dim[1], end_point, memory ); } } #ifdef DEBUG_HINTER - if (!error) + if ( !error ) ps_debug_hints = hints; #endif return error; } - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** TYPE 1 HINTS RECORDING INTERFACE *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** TYPE 1 HINTS RECORDING INTERFACE *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ static void t1_hints_open( T1_Hints hints ) @@ -1031,9 +1115,9 @@ } static void - t1_hints_stem( T1_Hints hints, - FT_Int dimension, - FT_Long* coords ) + t1_hints_stem( T1_Hints hints, + FT_Int dimension, + FT_Long* coords ) { ps_hints_stem( (PS_Hints)hints, dimension, 1, coords ); } @@ -1042,25 +1126,24 @@ FT_LOCAL_DEF void t1_hints_funcs_init( T1_Hints_FuncsRec* funcs ) { - memset( (char*)funcs, 0, sizeof(*funcs) ); - - funcs->open = (T1_Hints_OpenFunc) t1_hints_open; - funcs->close = (T1_Hints_CloseFunc) ps_hints_close; - funcs->stem = (T1_Hints_SetStemFunc) t1_hints_stem; - funcs->stem3 = (T1_Hints_SetStem3Func) ps_hints_t1stem3; - funcs->reset = (T1_Hints_ResetFunc) ps_hints_t1reset; - funcs->apply = (T1_Hints_ApplyFunc) PS_HINTS_APPLY_FUNC; + memset( (char*)funcs, 0, sizeof ( *funcs ) ); + + funcs->open = (T1_Hints_OpenFunc) t1_hints_open; + funcs->close = (T1_Hints_CloseFunc) ps_hints_close; + funcs->stem = (T1_Hints_SetStemFunc) t1_hints_stem; + funcs->stem3 = (T1_Hints_SetStem3Func)ps_hints_t1stem3; + funcs->reset = (T1_Hints_ResetFunc) ps_hints_t1reset; + funcs->apply = (T1_Hints_ApplyFunc) PS_HINTS_APPLY_FUNC; } - - /***********************************************************************/ - /***********************************************************************/ - /***** *****/ - /***** TYPE 2 HINTS RECORDING INTERFACE *****/ - /***** *****/ - /***********************************************************************/ - /***********************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** TYPE 2 HINTS RECORDING INTERFACE *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ static void t2_hints_open( T2_Hints hints ) @@ -1068,15 +1151,17 @@ ps_hints_open( (PS_Hints)hints, PS_HINT_TYPE_2 ); } + static void - t2_hints_stems( T2_Hints hints, - FT_Int dimension, - FT_Int count, - FT_Fixed* coords ) + t2_hints_stems( T2_Hints hints, + FT_Int dimension, + FT_Int count, + FT_Fixed* coords ) { - FT_Long stems[32], n, total = count; + FT_Long stems[32], n, total = count; + - while (total > 0) + while ( total > 0 ) { /* determine number of stems to write */ count = total; @@ -1084,13 +1169,13 @@ count = 32; /* compute integer stem position in font units */ - for ( n = 0; n < count*2; n++ ) - stems[n] = (coords[n] + 0x8000) >> 16; + for ( n = 0; n < count * 2; n++ ) + stems[n] = ( coords[n] + 0x8000 ) >> 16; /* add them to the current dimension */ ps_hints_stem( (PS_Hints)hints, dimension, count, stems ); - total -= (count >> 1); + total -= count >> 1; } } @@ -1098,12 +1183,15 @@ FT_LOCAL_DEF void t2_hints_funcs_init( T2_Hints_FuncsRec* funcs ) { - memset( funcs, 0, sizeof(*funcs) ); - - funcs->open = (T2_Hints_OpenFunc) t2_hints_open; - funcs->close = (T2_Hints_CloseFunc) ps_hints_close; - funcs->stems = (T2_Hints_StemsFunc) t2_hints_stems; - funcs->hintmask = (T2_Hints_MaskFunc) ps_hints_t2mask; - funcs->counter = (T2_Hints_CounterFunc) ps_hints_t2counter; - funcs->apply = (T2_Hints_ApplyFunc) PS_HINTS_APPLY_FUNC; + memset( funcs, 0, sizeof ( *funcs ) ); + + funcs->open = (T2_Hints_OpenFunc) t2_hints_open; + funcs->close = (T2_Hints_CloseFunc) ps_hints_close; + funcs->stems = (T2_Hints_StemsFunc) t2_hints_stems; + funcs->hintmask= (T2_Hints_MaskFunc) ps_hints_t2mask; + funcs->counter = (T2_Hints_CounterFunc)ps_hints_t2counter; + funcs->apply = (T2_Hints_ApplyFunc) PS_HINTS_APPLY_FUNC; } + + +/* END */ |