diff options
author | Werner Lemberg <wl@gnu.org> | 2005-03-01 02:13:50 +0000 |
---|---|---|
committer | Werner Lemberg <wl@gnu.org> | 2005-03-01 02:13:50 +0000 |
commit | e793092d0a9f4d4d383315bcefd485dcbe4804b3 (patch) | |
tree | eb8ca59af95da475b0985b803340d36ef73dd8de /src/sfnt | |
parent | 7305f62767eacd6b58d1c6d5dcf8eda1b209c457 (diff) | |
download | freetype2-e793092d0a9f4d4d383315bcefd485dcbe4804b3.tar.gz |
Formatting.
* src/truetype/ttpload.c (tt_face_load_loca): Fix typo.
* src/sfnt/ttkern.c: Include `ttkern.h'.
(FT_COMPONENT): Updated.
* include/freetype/internal/fttrace.h: Add entry for `ttkern'.
* src/sfnt/ttsbit0.c: s/FT_Err_/SFNT_Err_/.
Decorate constants with `U' and `L' where necessary.
* src/sfnt/ttcmap.c (tt_cmap4_next): Remove unused variable.
Diffstat (limited to 'src/sfnt')
-rw-r--r-- | src/sfnt/Jamfile | 2 | ||||
-rw-r--r-- | src/sfnt/rules.mk | 2 | ||||
-rw-r--r-- | src/sfnt/sfdriver.c | 6 | ||||
-rw-r--r-- | src/sfnt/sfnt.c | 2 | ||||
-rw-r--r-- | src/sfnt/sfobjs.c | 7 | ||||
-rw-r--r-- | src/sfnt/ttcmap.c | 86 | ||||
-rw-r--r-- | src/sfnt/ttkern.c | 215 | ||||
-rw-r--r-- | src/sfnt/ttkern.h | 9 | ||||
-rw-r--r-- | src/sfnt/ttload.c | 46 | ||||
-rw-r--r-- | src/sfnt/ttload.h | 2 | ||||
-rw-r--r-- | src/sfnt/ttsbit.c | 14 | ||||
-rw-r--r-- | src/sfnt/ttsbit0.c | 472 |
12 files changed, 456 insertions, 407 deletions
diff --git a/src/sfnt/Jamfile b/src/sfnt/Jamfile index 256b63afd..03c429a65 100644 --- a/src/sfnt/Jamfile +++ b/src/sfnt/Jamfile @@ -1,4 +1,4 @@ -# FreeType 2 src/sfnt Jamfile (c) 2001, 2002, 2004 David Turner +# FreeType 2 src/sfnt Jamfile (c) 2001, 2002, 2004, 2005 David Turner # SubDir FT2_TOP $(FT2_SRC_DIR) sfnt ; diff --git a/src/sfnt/rules.mk b/src/sfnt/rules.mk index 865eac1a1..e15681b21 100644 --- a/src/sfnt/rules.mk +++ b/src/sfnt/rules.mk @@ -3,7 +3,7 @@ # -# Copyright 1996-2000, 2002, 2003, 2004 by +# Copyright 1996-2000, 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, diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index ffb68709a..2595c72d2 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -4,7 +4,7 @@ /* */ /* High-level SFNT driver interface (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ @@ -366,8 +366,8 @@ /* see `ttsbit.h' and `sfnt.h' */ tt_face_set_sbit_strike, tt_face_load_sbit_strikes, - NULL /* tt_find_sbit_image */, - NULL /* tt_load_sbit_metrics */, + 0 /* tt_find_sbit_image */, + 0 /* tt_load_sbit_metrics */, tt_face_load_sbit_image, tt_face_free_sbit_strikes, diff --git a/src/sfnt/sfnt.c b/src/sfnt/sfnt.c index 1102bcb5e..798f923fa 100644 --- a/src/sfnt/sfnt.c +++ b/src/sfnt/sfnt.c @@ -4,7 +4,7 @@ /* */ /* Single object library component. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 7d6a1a4b5..79e0e9619 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -4,7 +4,7 @@ /* */ /* SFNT object management (base). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ @@ -511,7 +511,7 @@ (void)LOAD_( gasp ); (void)LOAD_( kerning ); - error = 0; + error = SFNT_Err_Ok; face->root.family_name = tt_face_get_name( face, TT_NAME_ID_PREFERRED_FAMILY ); @@ -560,7 +560,7 @@ #if 0 /* kerning available ? */ - if ( TT_FACE_HAS_KERNING(face) ) + if ( TT_FACE_HAS_KERNING( face ) ) flags |= FT_FACE_FLAG_KERNING; #endif @@ -780,6 +780,7 @@ { FT_Stream stream = FT_FACE_STREAM( face ); + FT_FRAME_RELEASE( face->horz_metrics ); FT_FRAME_RELEASE( face->vert_metrics ); face->horz_metrics_size = 0; diff --git a/src/sfnt/ttcmap.c b/src/sfnt/ttcmap.c index 8193368d1..b4b8ef84d 100644 --- a/src/sfnt/ttcmap.c +++ b/src/sfnt/ttcmap.c @@ -4,7 +4,7 @@ /* */ /* TrueType character mapping table (cmap) support (body). */ /* */ -/* Copyright 2002, 2003, 2004 by */ +/* Copyright 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, */ @@ -627,18 +627,18 @@ typedef struct TT_CMap4Rec_ { - TT_CMapRec cmap; - FT_UInt32 old_charcode; /* old charcode */ - FT_UInt32 cur_charcode; /* current charcode */ - FT_UInt cur_gindex; /* current glyph index */ - - FT_UInt table_length; - FT_UInt num_ranges; - FT_UInt cur_range; - FT_UInt cur_start; - FT_UInt cur_end; - FT_Int cur_delta; - FT_Byte* cur_values; + TT_CMapRec cmap; + FT_UInt32 old_charcode; /* old charcode */ + FT_UInt32 cur_charcode; /* current charcode */ + FT_UInt cur_gindex; /* current glyph index */ + + FT_UInt table_length; + FT_UInt num_ranges; + FT_UInt cur_range; + FT_UInt cur_start; + FT_UInt cur_end; + FT_Int cur_delta; + FT_Byte* cur_values; } TT_CMap4Rec, *TT_CMap4; @@ -647,15 +647,16 @@ tt_cmap4_init( TT_CMap4 cmap, FT_Byte* table ) { - FT_Byte* p; + FT_Byte* p; + cmap->cmap.data = table; p = table + 2; - cmap->table_length = FT_PEEK_USHORT(p); + cmap->table_length = FT_PEEK_USHORT( p ); p = table + 6; - cmap->num_ranges = FT_PEEK_USHORT(p) >> 1; + cmap->num_ranges = FT_PEEK_USHORT( p ) >> 1; cmap->cur_range = cmap->num_ranges; cmap->old_charcode = 0xFFFFFFFFUL; cmap->cur_charcode = 0; @@ -665,7 +666,6 @@ } - static FT_Int tt_cmap4_set_range( TT_CMap4 cmap, FT_UInt range_index ) @@ -674,23 +674,25 @@ FT_Byte* p; FT_UInt num_ranges = cmap->num_ranges; + while ( range_index < num_ranges ) { FT_UInt offset; - p = table + 14 + range_index*2; - cmap->cur_end = FT_PEEK_USHORT(p); - p += 2 + num_ranges*2; - cmap->cur_start = FT_PEEK_USHORT(p); + p = table + 14 + range_index * 2; + cmap->cur_end = FT_PEEK_USHORT( p ); + + p += 2 + num_ranges * 2; + cmap->cur_start = FT_PEEK_USHORT( p ); - p += num_ranges*2; - cmap->cur_delta = FT_PEEK_SHORT(p); + p += num_ranges * 2; + cmap->cur_delta = FT_PEEK_SHORT( p ); - p += num_ranges*2; - offset = FT_PEEK_SHORT(p); + p += num_ranges * 2; + offset = FT_PEEK_SHORT( p ); - if ( offset != 0xFFFF ) + if ( offset != 0xFFFFU ) { cmap->cur_values = offset ? p + offset : NULL; cmap->cur_range = range_index; @@ -712,30 +714,33 @@ static void tt_cmap4_next( TT_CMap4 cmap ) { - FT_UInt num_ranges = cmap->num_ranges; FT_UInt charcode = cmap->cur_charcode + 1; + cmap->old_charcode = cmap->cur_charcode; for ( ;; ) { - FT_Byte* values = cmap->cur_values; - FT_UInt end = cmap->cur_end; - FT_Int delta = cmap->cur_delta; + FT_Byte* values = cmap->cur_values; + FT_UInt end = cmap->cur_end; + FT_Int delta = cmap->cur_delta; + if ( charcode <= end ) { if ( values ) { - FT_Byte* p = values + 2*(charcode-cmap->cur_start); + FT_Byte* p = values + 2 * ( charcode - cmap->cur_start ); + do { - FT_UInt gindex = FT_NEXT_USHORT(p); + FT_UInt gindex = FT_NEXT_USHORT( p ); + if ( gindex != 0 ) { - gindex = (FT_UInt)((gindex + delta) & 0xFFFF); + gindex = (FT_UInt)( ( gindex + delta ) & 0xFFFFU ); if ( gindex != 0 ) { cmap->cur_charcode = charcode; @@ -743,14 +748,14 @@ return; } } - } - while ( ++charcode <= end ); + } while ( ++charcode <= end ); } else { do { - FT_UInt gindex = (FT_UInt)((charcode + delta) & 0xFFFFU); + FT_UInt gindex = (FT_UInt)( ( charcode + delta ) & 0xFFFFU ); + if ( gindex != 0 ) { @@ -758,14 +763,12 @@ cmap->cur_gindex = gindex; return; } - } - while ( ++charcode <= end ); + } while ( ++charcode <= end ); } } - /* we need to find another range - */ - if ( tt_cmap4_set_range( cmap, cmap->cur_range+1 ) < 0 ) + /* we need to find another range */ + if ( tt_cmap4_set_range( cmap, cmap->cur_range + 1 ) < 0 ) break; charcode = cmap->cur_start; @@ -1092,6 +1095,7 @@ { TT_CMap4 cmap4 = (TT_CMap4)cmap; + if ( char_code == cmap4->old_charcode ) { result = cmap4->cur_charcode; diff --git a/src/sfnt/ttkern.c b/src/sfnt/ttkern.c index f59dc033c..a488404d8 100644 --- a/src/sfnt/ttkern.c +++ b/src/sfnt/ttkern.c @@ -1,11 +1,11 @@ /***************************************************************************/ /* */ -/* ttkern.h */ +/* ttkern.c */ /* */ -/* Load the basic TrueType kerning table. This doesn't handle */ +/* Load the basic TrueType kerning table. This doesn't handle */ /* kerning data within the GPOS table at the moment. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ @@ -21,6 +21,7 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_TRUETYPE_TAGS_H +#include "ttkern.h" #include "ttload.h" #include "sferrors.h" @@ -33,7 +34,7 @@ /* messages during execution. */ /* */ #undef FT_COMPONENT -#define FT_COMPONENT trace_ttload +#define FT_COMPONENT trace_ttkern #undef TT_KERN_INDEX @@ -72,15 +73,15 @@ FT_ERROR(( "could not extract kerning table\n" )); goto Exit; } - + face->kern_table_size = table_size; - + p = face->kern_table; p_limit = p + table_size; p += 2; /* skip version */ - num_tables = FT_NEXT_USHORT(p); - + num_tables = FT_NEXT_USHORT( p ); + if ( num_tables > 32 ) /* we only support up to 32 sub-tables */ num_tables = 32; @@ -89,56 +90,61 @@ FT_UInt num_pairs, version, length, coverage; FT_Byte* p_next; FT_UInt32 mask = 1UL << nn; - + + if ( p + 6 > p_limit ) break; p_next = p; - - version = FT_NEXT_USHORT(p); - length = FT_NEXT_USHORT(p); - coverage = FT_NEXT_USHORT(p); - + + version = FT_NEXT_USHORT( p ); + length = FT_NEXT_USHORT( p ); + coverage = FT_NEXT_USHORT( p ); + if ( length <= 6 ) break; p_next += length; - - if ( (coverage & ~8) != 0x0001 || /* only use horizontal kerning tables */ - p+8 > p_limit ) + + /* only use horizontal kerning tables */ + if ( ( coverage & ~8 ) != 0x0001 || + p + 8 > p_limit ) goto NextTable; - num_pairs = FT_NEXT_USHORT(p); + num_pairs = FT_NEXT_USHORT( p ); p += 6; - - if ( p + 6*num_pairs > p_limit ) + + if ( p + 6 * num_pairs > p_limit ) goto NextTable; avail |= mask; - - /* now, try to see if the pairs in this table are ordered. - * when they are, we'll be able to use binary search - */ + + /* + * Now check whether the pairs in this table are ordered. + * We then can use binary search. + */ if ( num_pairs > 0 ) { - FT_UInt count; - FT_UInt old_pair; - - old_pair = FT_NEXT_ULONG(p); + FT_UInt count; + FT_UInt old_pair; + + + old_pair = FT_NEXT_ULONG( p ); p += 2; - for ( count = num_pairs-1; count > 0; count-- ) + for ( count = num_pairs - 1; count > 0; count-- ) { FT_UInt32 cur_pair; - - cur_pair = FT_NEXT_ULONG(p); + + + cur_pair = FT_NEXT_ULONG( p ); if ( cur_pair <= old_pair ) break; p += 2; old_pair = cur_pair; } - + if ( count == 0 ) ordered |= mask; } @@ -150,7 +156,7 @@ face->num_kern_tables = nn; face->kern_avail_bits = avail; face->kern_order_bits = ordered; - + Exit: return error; } @@ -160,7 +166,8 @@ tt_face_done_kern( TT_Face face ) { FT_Stream stream = face->root.stream; - + + FT_FRAME_RELEASE( face->kern_table ); face->kern_table_size = 0; face->num_kern_tables = 0; @@ -179,6 +186,7 @@ FT_Byte* p = face->kern_table; FT_Byte* p_limit = p + face->kern_table_size; + p += 4; mask = 0x0001; @@ -186,88 +194,95 @@ { FT_Byte* base = p; FT_Byte* next = base; - FT_UInt version = FT_NEXT_USHORT(p); - FT_UInt length = FT_NEXT_USHORT(p); - FT_UInt coverage = FT_NEXT_USHORT(p); + FT_UInt version = FT_NEXT_USHORT( p ); + FT_UInt length = FT_NEXT_USHORT( p ); + FT_UInt coverage = FT_NEXT_USHORT( p ); FT_Int value = 0; - + + next = base + length; - - if ( (face->kern_avail_bits & mask) == 0 ) + + if ( ( face->kern_avail_bits & mask ) == 0 ) goto NextTable; - if ( p+8 > next ) + if ( p + 8 > next ) goto NextTable; switch ( coverage >> 8 ) { case 0: + { + FT_UInt num_pairs = FT_NEXT_USHORT( p ); + FT_ULong key0 = TT_KERN_INDEX( left_glyph, right_glyph ); + + + p += 6; + + if ( face->kern_order_bits & mask ) /* binary search */ { - FT_UInt num_pairs = FT_NEXT_USHORT(p); - FT_ULong key0 = TT_KERN_INDEX(left_glyph,right_glyph); + FT_UInt min = 0; + FT_UInt max = num_pairs; + FT_Byte* q; - p += 6; - - if ( face->kern_order_bits & mask ) /* binary search */ + + while ( min < max ) { - FT_UInt min = 0; - FT_UInt max = num_pairs; - FT_Byte* q; - - while ( min < max ) + FT_UInt mid = ( min + max ) >> 1; + FT_Byte* q = p + 6 * mid; + FT_ULong key; + + + key = FT_NEXT_ULONG( q ); + + if ( key == key0 ) { - FT_UInt mid = (min+max) >> 1; - FT_Byte* q = p + 6*mid; - FT_ULong key; - - key = FT_NEXT_ULONG(q); - - if ( key == key0 ) - { - value = FT_PEEK_SHORT(q); - goto Found; - } - if ( key < key0 ) - min = mid+1; - else - max = mid; + value = FT_PEEK_SHORT( q ); + goto Found; } + if ( key < key0 ) + min = mid + 1; + else + max = mid; } - else /* linear search */ + } + else /* linear search */ + { + FT_UInt count = num_pairs; + + + for ( ; count > 0; count-- ) { - FT_UInt count = num_pairs; + FT_ULong key = FT_NEXT_ULONG( p ); + - for ( ; count > 0; count-- ) + if ( key == key0 ) { - FT_ULong key = FT_NEXT_ULONG(p); - - if ( key == key0 ) - { - value = FT_PEEK_SHORT(p); - goto Found; - } - p += 2; + value = FT_PEEK_SHORT( p ); + goto Found; } + p += 2; } } - break; + } + break; - /* we don't support format 2 because we've never seen a single font - * using it in real life... - */ + /* + * We don't support format 2 because we've never seen a single font + * using it in real life... + */ default: - ; + ; } goto NextTable; - + Found: - if ( coverage & 8 ) /* overide or addition */ + if ( coverage & 8 ) /* overide or add */ result = value; else result += value; - + NextTable: p = next; } @@ -276,8 +291,7 @@ return result; } - -#else /* !OPTMIZE_MEMORY */ +#else /* !OPTIMIZE_MEMORY */ FT_CALLBACK_DEF( int ) tt_kern_pair_compare( const void* a, @@ -365,20 +379,20 @@ { TT_Kern0_Pair pair0 = face->kern_pairs; FT_ULong prev = TT_KERN_INDEX( pair0->left, pair0->right ); - + for ( pair0++; pair0 < limit; pair0++ ) { FT_ULong next = TT_KERN_INDEX( pair0->left, pair0->right ); - + if ( next < prev ) goto SortIt; - + prev = next; } goto Exit; - + SortIt: ft_qsort( (void*)face->kern_pairs, (int)num_pairs, sizeof ( TT_Kern0_PairRec ), tt_kern_pair_compare ); @@ -400,6 +414,7 @@ return error; } + FT_CALLBACK_DEF( int ) tt_kern_pair_compare( const void* a, const void* b ) @@ -410,9 +425,9 @@ FT_ULong index1 = TT_KERN_INDEX( pair1->left, pair1->right ); FT_ULong index2 = TT_KERN_INDEX( pair2->left, pair2->right ); - - return ( index1 < index2 ? -1 : - ( index1 > index2 ? 1 : 0 )); + return index1 < index2 ? -1 + : ( index1 > index2 ? 1 + : 0 ); } @@ -420,17 +435,17 @@ tt_face_done_kern( TT_Face face ) { FT_Memory memory = face->root.stream->memory; - + + FT_FREE( face->kern_pairs ); face->num_kern_pairs = 0; } - FT_LOCAL_DEF( FT_Int ) - tt_face_get_kerning( TT_Face face, - FT_UInt left_glyph, - FT_UInt right_glyph ) + tt_face_get_kerning( TT_Face face, + FT_UInt left_glyph, + FT_UInt right_glyph ) { FT_Int result = 0; TT_Kern0_Pair pair; @@ -477,5 +492,5 @@ #undef TT_KERN_INDEX - + /* END */ diff --git a/src/sfnt/ttkern.h b/src/sfnt/ttkern.h index f71849b1f..18b1381b4 100644 --- a/src/sfnt/ttkern.h +++ b/src/sfnt/ttkern.h @@ -2,10 +2,10 @@ /* */ /* ttkern.h */ /* */ -/* Load the basic TrueType kerning table. This doesn't handle */ +/* Load the basic TrueType kerning table. This doesn't handle */ /* kerning data within the GPOS table at the moment. */ /* */ -/* Copyright 1996-2001, 2002 by */ +/* Copyright 1996-2001, 2002, 2005 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -42,11 +42,12 @@ FT_BEGIN_HEADER FT_UInt right_glyph ); #ifdef FT_OPTIMIZE_MEMORY -# define TT_FACE_HAS_KERNING(face) ((face)->kern_avail_bits != 0) +# define TT_FACE_HAS_KERNING( face ) ( (face)->kern_avail_bits != 0 ) #else -# define TT_FACE_HAS_KERNING(face) ((face)->kern_pairs != NULL) +# define TT_FACE_HAS_KERNING( face ) ( (face)->kern_pairs != NULL ) #endif + FT_END_HEADER #endif /* __TTKERN_H__ */ diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c index e7a45f7e0..f59ef40da 100644 --- a/src/sfnt/ttload.c +++ b/src/sfnt/ttload.c @@ -5,7 +5,7 @@ /* Load the basic TrueType tables, i.e., tables that can be either in */ /* TTF or OTF fonts (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ @@ -801,6 +801,7 @@ /* FreeType error code. 0 means success. */ /* */ #ifdef FT_OPTIMIZE_MEMORY + static FT_Error tt_face_load_metrics( TT_Face face, FT_Stream stream, @@ -822,7 +823,7 @@ ptable = &face->vert_metrics; ptable_size = &face->vert_metrics_size; - /* The table is optional, quit silently if it wasn't found */ + /* The table is optional, quit silently if it wasn't found. */ /* */ /* XXX: Some fonts have a valid vertical header with a non-null */ /* `number_of_VMetrics' fields, but no corresponding `vmtx' */ @@ -849,10 +850,10 @@ { #ifdef FT_CONFIG_OPTION_INCREMENTAL /* If this is an incrementally loaded font and there are */ - /* overriding metrics tolerate a missing 'hmtx' table. */ - if ( face->root.internal->incremental_interface && + /* overriding metrics, tolerate a missing `hmtx' table. */ + if ( face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs-> - get_glyph_metrics ) + get_glyph_metrics ) { face->horizontal.number_Of_HMetrics = 0; error = SFNT_Err_Ok; @@ -876,6 +877,7 @@ } #else /* !OPTIMIZE_MEMORY */ + static FT_Error tt_face_load_metrics( TT_Face face, FT_Stream stream, @@ -897,7 +899,7 @@ if ( vertical ) { - /* The table is optional, quit silently if it wasn't found */ + /* The table is optional, quit silently if it wasn't found. */ /* */ /* XXX: Some fonts have a valid vertical header with a non-null */ /* `number_of_VMetrics' fields, but no corresponding `vmtx' */ @@ -927,10 +929,10 @@ #ifdef FT_CONFIG_OPTION_INCREMENTAL /* If this is an incrementally loaded font and there are */ - /* overriding metrics tolerate a missing 'hmtx' table. */ - if ( face->root.internal->incremental_interface && + /* overriding metrics, tolerate a missing `hmtx' table. */ + if ( face->root.internal->incremental_interface && face->root.internal->incremental_interface->funcs-> - get_glyph_metrics ) + get_glyph_metrics ) { face->horizontal.number_Of_HMetrics = 0; error = SFNT_Err_Ok; @@ -993,9 +995,9 @@ for ( ; cur < limit; cur++ ) *cur = FT_GET_SHORT(); - /* we fill up the missing left side bearings with the */ + /* We fill up the missing left side bearings with the */ /* last valid value. Since this will occur for buggy CJK */ - /* fonts usually only, nothing serious will happen */ + /* fonts usually only, nothing serious will happen. */ if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 ) { FT_Short val = (*shorts)[num_shorts_checked - 1]; @@ -1014,8 +1016,10 @@ Exit: return error; } + #endif /* !FT_OPTIMIZE_METRICS */ + /*************************************************************************/ /* */ /* <Function> */ @@ -1704,6 +1708,7 @@ /* FreeType error code. 0 means success. */ /* */ #ifdef FT_OPTIMIZE_MEMORY + FT_LOCAL_DEF( FT_Error ) tt_face_load_hdmx( TT_Face face, FT_Stream stream ) @@ -1715,6 +1720,7 @@ FT_Byte* p; FT_Byte* limit; + /* this table is optional */ error = face->goto_table( face, TTAG_hdmx, stream, &table_size ); if ( error || table_size < 8 ) @@ -1726,9 +1732,9 @@ p = face->hdmx_table; limit = p + table_size; - version = FT_NEXT_USHORT(p); - num_records = FT_NEXT_USHORT(p); - record_size = FT_NEXT_ULONG(p); + version = FT_NEXT_USHORT( p ); + num_records = FT_NEXT_USHORT( p ); + record_size = FT_NEXT_ULONG( p ); if ( version != 0 || num_records > 255 || record_size > 0x40000 ) { @@ -1741,7 +1747,7 @@ for ( nn = 0; nn < num_records; nn++ ) { - if ( p+record_size > limit ) + if ( p + record_size > limit ) break; face->hdmx_record_sizes[nn] = p[0]; @@ -1767,11 +1773,13 @@ FT_Stream stream = face->root.stream; FT_Memory memory = stream->memory; + FT_FREE( face->hdmx_record_sizes ); FT_FRAME_RELEASE( face->hdmx_table ); } #else /* !FT_OPTIMIZE_MEMORY */ + FT_LOCAL_DEF( FT_Error ) tt_face_load_hdmx( TT_Face face, FT_Stream stream ) @@ -1797,9 +1805,9 @@ if ( FT_FRAME_ENTER( 8L ) ) goto Exit; - hdmx->version = FT_GET_USHORT(); - num_records = FT_GET_SHORT(); - record_size = FT_GET_LONG(); + hdmx->version = FT_GET_USHORT(); + num_records = FT_GET_SHORT(); + record_size = FT_GET_LONG(); FT_FRAME_EXIT(); @@ -1831,7 +1839,7 @@ FT_READ_BYTE( cur->max_width ) ) goto Exit; - if ( FT_QALLOC( cur->widths, num_glyphs ) || + if ( FT_QALLOC( cur->widths, num_glyphs ) || FT_STREAM_READ( cur->widths, num_glyphs ) ) goto Exit; diff --git a/src/sfnt/ttload.h b/src/sfnt/ttload.h index 439b4df3e..d1a61ca7f 100644 --- a/src/sfnt/ttload.h +++ b/src/sfnt/ttload.h @@ -5,7 +5,7 @@ /* Load the basic TrueType tables, i.e., tables that can be either in */ /* TTF or OTF fonts (specification). */ /* */ -/* Copyright 1996-2001, 2002 by */ +/* Copyright 1996-2001, 2002, 2005 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ diff --git a/src/sfnt/ttsbit.c b/src/sfnt/ttsbit.c index c449ddd87..610b63bcc 100644 --- a/src/sfnt/ttsbit.c +++ b/src/sfnt/ttsbit.c @@ -4,7 +4,7 @@ /* */ /* TrueType and OpenType embedded bitmap support (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* 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, */ @@ -584,12 +584,11 @@ } } - /* now set up the root fields to indicate the strikes - */ + /* now set up the root fields to indicate the strikes */ if ( face->num_sbit_strikes ) { FT_ULong n; - FT_Face root = FT_FACE(face); + FT_Face root = FT_FACE( face ); if ( FT_NEW_ARRAY( root->available_sizes, face->num_sbit_strikes ) ) @@ -608,9 +607,9 @@ /* assume 72dpi */ bsize->height = - (FT_Short)( ( height * strike->y_ppem + fupem/2 ) / fupem ); + (FT_Short)( ( height * strike->y_ppem + fupem / 2 ) / fupem ); bsize->width = - (FT_Short)( ( avg * strike->y_ppem + fupem/2 ) / fupem ); + (FT_Short)( ( avg * strike->y_ppem + fupem / 2 ) / fupem ); bsize->size = strike->y_ppem << 6; bsize->x_ppem = strike->x_ppem << 6; bsize->y_ppem = strike->y_ppem << 6; @@ -1514,6 +1513,7 @@ return error; } +#endif /* !OPTIMIZE_MEMORY */ + /* END */ -#endif /* !OPTIMIZE_MEMORY */ diff --git a/src/sfnt/ttsbit0.c b/src/sfnt/ttsbit0.c index 2f7095c5e..74bb7892a 100644 --- a/src/sfnt/ttsbit0.c +++ b/src/sfnt/ttsbit0.c @@ -1,10 +1,11 @@ /***************************************************************************/ /* */ -/* ttsbit.c */ +/* ttsbit0.c */ /* */ /* TrueType and OpenType embedded bitmap support (body). */ +/* This is a heap-optimized version. */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004 by */ +/* Copyright 2005 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -84,12 +85,11 @@ }; - FT_LOCAL_DEF( FT_Error ) tt_face_load_sbit_strikes( TT_Face face, FT_Stream stream ) { - FT_Error error = 0; + FT_Error error = SFNT_Err_Ok; FT_Memory memory = stream->memory; FT_Fixed version; FT_ULong num_strikes, table_size; @@ -98,6 +98,7 @@ FT_Byte* p_limit; FT_UInt nn, count; + face->sbit_num_strikes = 0; /* this table is optional */ @@ -109,7 +110,7 @@ if ( table_size < 8 ) { - FT_ERROR(( "%s: table too short !\n", "tt_face_load_sbit_strikes" )); + FT_ERROR(( "%s: table too short!\n", "tt_face_load_sbit_strikes" )); error = SFNT_Err_Invalid_File_Format; goto Exit; } @@ -122,30 +123,32 @@ p = face->sbit_table; p_limit = p + table_size; - version = FT_NEXT_ULONG(p); - num_strikes = FT_NEXT_ULONG(p); + version = FT_NEXT_ULONG( p ); + num_strikes = FT_NEXT_ULONG( p ); - if ( version != 0x00020000 || num_strikes >= 0x10000UL ) + if ( version != 0x00020000UL || num_strikes >= 0x10000UL ) { - FT_ERROR(( "%s: invalid table version !\n", "tt_face_load_sbit_strikes" )); + FT_ERROR(( "%s: invalid table version!\n", + "tt_face_load_sbit_strikes" )); error = SFNT_Err_Invalid_File_Format; goto Fail; } - /* count the number of strikes available in the table. we're a bit - * paranoid there and don't trust the data. - */ + /* + * Count the number of strikes available in the table. We are a bit + * paranoid there and don't trust the data. + */ count = (FT_UInt)num_strikes; - if ( 8+48UL*count > table_size ) - count = (FT_UInt)( (p_limit - p)/48 ); + if ( 8 +48UL * count > table_size ) + count = (FT_UInt)( ( p_limit - p ) / 48 ); face->sbit_num_strikes = count; - /* now allocate the root array of F_Bitmap_Size records, - * populate them, and that's all there is to it. Unfortunately, - * it's not possible to indicate bit depths in the FT_Bitmap_Size - * record. What were we thinking ? - */ + /* + * Now allocate the root array of FT_Bitmap_Size records and + * populate them. Unfortunately, it isn't possible to indicate bit + * depths in the FT_Bitmap_Size record. This is a design error. + */ { FT_Memory memory = face->root.stream->memory; FT_UInt em_size = (FT_UInt) face->header.Units_Per_EM; @@ -155,6 +158,7 @@ FT_Short avgwidth = face->os2.xAvgCharWidth; + if ( FT_NEW_ARRAY( face->root.available_sizes, count ) ) goto Fail; @@ -163,14 +167,15 @@ FT_Bitmap_Size* bsize = face->root.available_sizes + nn; FT_UInt x_ppem, y_ppem; + x_ppem = p[44]; y_ppem = p[45]; bsize->x_ppem = (FT_Pos)(x_ppem << 6); bsize->y_ppem = (FT_Pos)(y_ppem << 6); - bsize->height = (FT_Short)( height*y_ppem + em_size/2 ) / em_size; - bsize->width = (FT_Short)( avgwidth*y_ppem + em_size/2 ) / em_size; + bsize->height = (FT_Short)( height*y_ppem + em_size / 2 ) / em_size; + bsize->width = (FT_Short)( avgwidth*y_ppem + em_size / 2 ) / em_size; bsize->size = bsize->y_ppem; p += 48; @@ -178,7 +183,6 @@ face->root.face_flags |= FT_FACE_FLAG_FIXED_SIZES; face->root.num_fixed_sizes = count; - } Exit: @@ -196,6 +200,7 @@ { FT_Stream stream = face->root.stream; + FT_FRAME_RELEASE( face->sbit_table ); face->sbit_table_size = 0; face->sbit_num_strikes = 0; @@ -212,13 +217,15 @@ FT_Byte* p; FT_Byte* p_limit; - if ( x_ppem > 255 || + + if ( x_ppem > 255 || y_ppem < 1 || y_ppem > 255 ) return SFNT_Err_Invalid_PPem; p = face->sbit_table + 8; p_limit = p + face->sbit_table_size; count = face->sbit_num_strikes; + for ( nn = 0; nn < count; nn++ ) { if ( x_ppem == (FT_UInt)p[44] && y_ppem == (FT_UInt)p[45] ) @@ -233,7 +240,6 @@ } - typedef struct { TT_Face face; @@ -265,16 +271,17 @@ FT_Stream stream = face->root.stream; FT_ULong ebdt_size; + error = face->goto_table( face, TTAG_EBDT, stream, &ebdt_size ); if ( error ) error = face->goto_table( face, TTAG_bdat, stream, &ebdt_size ); - if (error) + if ( error ) goto Exit; - decoder->face = face; - decoder->stream = stream; - decoder->bitmap = &face->root.glyph->bitmap; - decoder->metrics = metrics; + decoder->face = face; + decoder->stream = stream; + decoder->bitmap = &face->root.glyph->bitmap; + decoder->metrics = metrics; decoder->metrics_loaded = 0; decoder->bitmap_allocated = 0; @@ -285,14 +292,14 @@ decoder->eblc_base = face->sbit_table; decoder->eblc_limit = face->sbit_table + face->sbit_table_size; - /* now find the strike corresponding to the index - */ + /* now find the strike corresponding to the index */ { - FT_Byte* p = decoder->eblc_base + 8 + 48*strike_index; + FT_Byte* p = decoder->eblc_base + 8 + 48 * strike_index; + - decoder->strike_index_array = FT_NEXT_ULONG(p); + decoder->strike_index_array = FT_NEXT_ULONG( p ); p += 4; - decoder->strike_index_count = FT_NEXT_ULONG(p); + decoder->strike_index_count = FT_NEXT_ULONG( p ); p += 34; decoder->bit_depth = *p; } @@ -305,52 +312,52 @@ static void tt_sbit_decoder_done( TT_SBitDecoder decoder ) { - FT_UNUSED(decoder); + FT_UNUSED( decoder ); } - static FT_Error tt_sbit_decoder_alloc_bitmap( TT_SBitDecoder decoder ) { - FT_Error error = 0; + FT_Error error = SFNT_Err_Ok; FT_UInt width, height; FT_Bitmap* map = decoder->bitmap; FT_Long size; + if ( !decoder->metrics_loaded ) { - error = FT_Err_Invalid_Argument; + error = SFNT_Err_Invalid_Argument; goto Exit; } width = decoder->metrics->width; height = decoder->metrics->height; - map->width = (int) width; - map->rows = (int) height; + map->width = (int)width; + map->rows = (int)height; switch ( decoder->bit_depth ) { case 1: - map->pixel_mode = FT_PIXEL_MODE_MONO; - map->pitch = ( map->width + 7 ) >> 3; - break; + map->pixel_mode = FT_PIXEL_MODE_MONO; + map->pitch = ( map->width + 7 ) >> 3; + break; case 2: - map->pixel_mode = FT_PIXEL_MODE_GRAY2; - map->pitch = ( map->width + 3 ) >> 2; - break; + map->pixel_mode = FT_PIXEL_MODE_GRAY2; + map->pitch = ( map->width + 3 ) >> 2; + break; case 4: - map->pixel_mode = FT_PIXEL_MODE_GRAY4; - map->pitch = ( map->width + 1 ) >> 1; - break; + map->pixel_mode = FT_PIXEL_MODE_GRAY4; + map->pitch = ( map->width + 1 ) >> 1; + break; case 8: - map->pixel_mode = FT_PIXEL_MODE_GRAY; - map->pitch = map->width; - break; + map->pixel_mode = FT_PIXEL_MODE_GRAY; + map->pitch = map->width; + break; default: error = SFNT_Err_Invalid_File_Format; @@ -364,7 +371,7 @@ goto Exit; /* exit successfully! */ error = ft_glyphslot_alloc_bitmap( decoder->face->root.glyph, size ); - if (error) + if ( error ) goto Exit; decoder->bitmap_allocated = 1; @@ -383,28 +390,29 @@ FT_Byte* p = *pp; TT_SBit_Metrics metrics = decoder->metrics; - if ( p+5 > limit ) + + if ( p + 5 > limit ) goto Fail; if ( !decoder->metrics_loaded ) { metrics->height = p[0]; metrics->width = p[1]; - metrics->horiBearingX = (FT_Char) p[2]; - metrics->horiBearingY = (FT_Char) p[3]; + metrics->horiBearingX = (FT_Char)p[2]; + metrics->horiBearingY = (FT_Char)p[3]; metrics->horiAdvance = p[4]; } p += 5; if ( big ) { - if ( p+3 > limit ) + if ( p + 3 > limit ) goto Fail; if ( !decoder->metrics_loaded ) { - metrics->vertBearingX = (FT_Char) p[0]; - metrics->vertBearingY = (FT_Char) p[1]; + metrics->vertBearingX = (FT_Char)p[0]; + metrics->vertBearingY = (FT_Char)p[1]; metrics->vertAdvance = p[2]; } @@ -416,14 +424,11 @@ return 0; Fail: - return FT_Err_Invalid_Argument; + return SFNT_Err_Invalid_Argument; } - - - - /* forward declaration */ + /* forward declaration */ static FT_Error tt_sbit_decoder_load_image( TT_SBitDecoder decoder, FT_UInt glyph_index, @@ -437,8 +442,6 @@ FT_Int y_pos ); - - static FT_Error tt_sbit_decoder_load_byte_aligned( TT_SBitDecoder decoder, FT_Byte* p, @@ -446,21 +449,21 @@ FT_Int x_pos, FT_Int y_pos ) { - FT_Error error = 0; + FT_Error error = SFNT_Err_Ok; FT_Byte* line; FT_Int bit_height, bit_width, pitch, width, height, h; FT_Bitmap* bitmap; FT_UInt rval; + if ( !decoder->bitmap_allocated ) { error = tt_sbit_decoder_alloc_bitmap( decoder ); - if (error) + if ( error ) goto Exit; } - /* check that we can write the glyph into the bitmap - */ + /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; @@ -469,22 +472,21 @@ width = decoder->metrics->width; height = decoder->metrics->height; - if ( x_pos < 0 || x_pos+width > bit_width || - y_pos < 0 || y_pos+height > bit_height ) + if ( x_pos < 0 || x_pos + width > bit_width || + y_pos < 0 || y_pos + height > bit_height ) { - error = FT_Err_Invalid_File_Format; + error = SFNT_Err_Invalid_File_Format; goto Exit; } - if ( p+((width+7)>>3)*height > limit ) + if ( p + ( ( width + 7 ) >> 3 ) * height > limit ) { - error = FT_Err_Invalid_File_Format; + error = SFNT_Err_Invalid_File_Format; goto Exit; } - /* now do the blit - */ - line += y_pos*pitch + (x_pos >> 3); + /* now do the blit */ + line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; if ( x_pos == 0 ) /* the easy one */ @@ -494,14 +496,15 @@ FT_Byte* write = line; FT_Int w; + for ( w = width; w >= 8; w -= 8 ) { - write[0] = (FT_Byte)(write[0] | *p++); + write[0] = (FT_Byte)( write[0] | *p++ ); write += 1; } if ( w > 0 ) - write[0] = (FT_Byte)(write[0] | (*p++ & (0xFF00 >> w))); + write[0] = (FT_Byte)( write[0] | ( *p++ & ( 0xFF00U >> w ) ) ); } } else /* x_pos > 0 */ @@ -512,18 +515,19 @@ FT_Int w; FT_UInt wval = 0; + for ( w = width; w >= 8; w -= 8 ) { - wval = (FT_UInt)(wval | *p++); - write[0] = (FT_Byte)(write[0] | (wval >> x_pos)); + wval = (FT_UInt)( wval | *p++ ); + write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) ); write += 1; wval <<= 8; } if ( w > 0 ) - wval = (FT_UInt)(wval | (*p++ & (0xFF00 >> w))); + wval = (FT_UInt)(wval | ( *p++ & ( 0xFF00U >> w ) ) ); - write[0] = (FT_Byte)(write[0] | (wval >> x_pos)); + write[0] = (FT_Byte)( write[0] | ( wval >> x_pos ) ); } } @@ -539,21 +543,21 @@ FT_Int x_pos, FT_Int y_pos ) { - FT_Error error = 0; + FT_Error error = SFNT_Err_Ok; FT_Byte* line; FT_Int bit_height, bit_width, pitch, width, height, h; FT_Bitmap* bitmap; FT_UInt32 rval; + if ( !decoder->bitmap_allocated ) { error = tt_sbit_decoder_alloc_bitmap( decoder ); - if (error) + if ( error ) goto Exit; } - /* check that we can write the glyph into the bitmap - */ + /* check that we can write the glyph into the bitmap */ bitmap = decoder->bitmap; bit_width = bitmap->width; bit_height = bitmap->rows; @@ -562,24 +566,23 @@ width = decoder->metrics->width; height = decoder->metrics->height; - if ( x_pos < 0 || x_pos+width > bit_width || - y_pos < 0 || y_pos+height > bit_height ) + if ( x_pos < 0 || x_pos + width > bit_width || + y_pos < 0 || y_pos + height > bit_height ) { - error = FT_Err_Invalid_File_Format; + error = SFNT_Err_Invalid_File_Format; goto Exit; } - if ( p+((width+7)>>3)*height > limit ) + if ( p + ( ( width + 7 ) >> 3 ) * height > limit ) { - error = FT_Err_Invalid_File_Format; + error = SFNT_Err_Invalid_File_Format; goto Exit; } - /* now do the blit - */ - line += y_pos*pitch + (x_pos >> 3); + /* now do the blit */ + line += y_pos * pitch + ( x_pos >> 3 ); x_pos &= 7; - rval = 0x10000; + rval = 0x10000UL; for ( h = height; h > 0; h--, line += pitch ) { @@ -587,19 +590,20 @@ FT_UInt32 wval = 0x100 << x_pos; FT_Int w; + for ( w = width; w >= 8; w -= 8 ) { - if ( rval & 0x10000 ) + if ( rval & 0x10000UL ) rval = 0x100 | *p++; - wval |= (rval & 0x80); + wval |= rval & 0x80; wval <<= 1; rval <<= 1; - if ( wval & 0x10000 ) + if ( wval & 0x10000UL ) { - write[0] = (FT_Byte)(write[0] | (wval >> 8)); + write[0] = (FT_Byte)( write[0] | ( wval >> 8 ) ); write += 1; wval = 0x100; } @@ -610,7 +614,7 @@ while ( wval > 0x1FF ) wval >>= 1; - write[0] = (FT_Byte)(write[0] | wval); + write[0] = (FT_Byte)( write[0] | wval ); } } @@ -630,21 +634,23 @@ FT_UInt num_components, nn; - if ( p+2 > limit ) + if ( p + 2 > limit ) goto Fail; - num_components = FT_NEXT_USHORT(p); - if ( p+4*num_components > limit ) + num_components = FT_NEXT_USHORT( p ); + if ( p + 4 * num_components > limit ) goto Fail; for ( nn = 0; nn < num_components; nn++ ) { - FT_UInt gindex = FT_NEXT_USHORT(p); - FT_Byte dx = FT_NEXT_BYTE(p); - FT_Byte dy = FT_NEXT_BYTE(p); + FT_UInt gindex = FT_NEXT_USHORT( p ); + FT_Byte dx = FT_NEXT_BYTE( p ); + FT_Byte dy = FT_NEXT_BYTE( p ); + /* NB: a recursive call */ - error = tt_sbit_decoder_load_image( decoder, gindex, x_pos+dx, y_pos+dy ); + error = tt_sbit_decoder_load_image( decoder, gindex, + x_pos + dx, y_pos + dy ); if ( error ) break; } @@ -653,7 +659,7 @@ return error; Fail: - error = FT_Err_Invalid_File_Format; + error = SFNT_Err_Invalid_File_Format; goto Exit; } @@ -672,35 +678,38 @@ FT_Byte* p_limit; FT_Byte* data; - /* seek into the EBDT table now - */ + + /* seek into the EBDT table now */ if ( glyph_start + glyph_size > decoder->ebdt_size ) { - error = FT_Err_Invalid_Argument; + error = SFNT_Err_Invalid_Argument; goto Exit; } if ( FT_STREAM_SEEK( decoder->ebdt_start + glyph_start ) || - FT_FRAME_EXTRACT( glyph_size, data ) ) + FT_FRAME_EXTRACT( glyph_size, data ) ) goto Exit; p = data; p_limit = p + glyph_size; - /* read the data, depending on the glyph format - */ + /* read the data, depending on the glyph format */ switch ( glyph_format ) { - case 1: case 2: case 8: + case 1: + case 2: + case 8: error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 0 ); break; - case 6: case 7: case 9: + case 6: + case 7: + case 9: error = tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ); break; default: - error = 0; + error = SFNT_Err_Ok; } if ( error ) @@ -709,29 +718,33 @@ { TT_SBitDecoder_LoadFunc loader; + switch ( glyph_format ) { - case 1: case 6: - loader = tt_sbit_decoder_load_byte_aligned; - break; + case 1: + case 6: + loader = tt_sbit_decoder_load_byte_aligned; + break; - case 2: case 5: case 7: - loader = tt_sbit_decoder_load_bit_aligned; - break; + case 2: + case 5: + case 7: + loader = tt_sbit_decoder_load_bit_aligned; + break; case 8: - if ( p+1 > p_limit ) - goto Fail; + if ( p + 1 > p_limit ) + goto Fail; - p += 1; /* skip padding */ - /* fall-through */ + p += 1; /* skip padding */ + /* fall-through */ case 9: - loader = tt_sbit_decoder_load_compound; - break; + loader = tt_sbit_decoder_load_compound; + break; default: - goto Fail; + goto Fail; } error = loader( decoder, p, p_limit, x_pos, y_pos ); @@ -751,22 +764,25 @@ FT_Int x_pos, FT_Int y_pos ) { - /* first, we find the correct strike range that applies to this - * glyph index. - */ + /* + * First, we find the correct strike range that applies to this + * glyph index. + */ + FT_Byte* p = decoder->eblc_base + decoder->strike_index_array; FT_Byte* p_limit = decoder->eblc_limit; FT_ULong num_ranges = decoder->strike_index_count; FT_UInt start, end, offset, index_format, image_format; FT_ULong image_start, image_end, image_offset; - if ( p+8*num_ranges > p_limit ) + + if ( p + 8 * num_ranges > p_limit ) goto NoBitmap; for ( ; num_ranges > 0; num_ranges-- ) { - start = FT_NEXT_USHORT(p); - end = FT_NEXT_USHORT(p); + start = FT_NEXT_USHORT( p ); + end = FT_NEXT_USHORT( p ); if ( glyph_index >= start && glyph_index <= end ) goto FoundRange; @@ -776,128 +792,131 @@ goto NoBitmap; FoundRange: - p = decoder->eblc_base + decoder->strike_index_array + FT_NEXT_ULONG(p); - if ( p+8 > p_limit ) + p = decoder->eblc_base + decoder->strike_index_array + FT_NEXT_ULONG( p ); + if ( p + 8 > p_limit ) goto NoBitmap; - /* now, we're going to find the glyph's location and extend within - * the ebdt table - */ - index_format = FT_NEXT_USHORT(p); - image_format = FT_NEXT_USHORT(p); - image_offset = FT_NEXT_ULONG(p); + /* now find the glyph's location and extend within the ebdt table */ + index_format = FT_NEXT_USHORT( p ); + image_format = FT_NEXT_USHORT( p ); + image_offset = FT_NEXT_ULONG ( p ); switch ( index_format ) { - case 1: /* 4-byte offsets relative to 'image_offset' */ - { - p += 4*(glyph_index-start); - if ( p+8 > p_limit ) - goto NoBitmap; + case 1: /* 4-byte offsets relative to `image_offset' */ + { + p += 4 * ( glyph_index - start ); + if ( p + 8 > p_limit ) + goto NoBitmap; - image_start = FT_NEXT_ULONG(p); - image_end = FT_NEXT_ULONG(p); + image_start = FT_NEXT_ULONG( p ); + image_end = FT_NEXT_ULONG( p ); - if ( image_start == image_end ) /* missing glyph */ - goto NoBitmap; - } - break; + if ( image_start == image_end ) /* missing glyph */ + goto NoBitmap; + } + break; case 2: /* big metrics, constant image size */ - { - FT_ULong image_size; + { + FT_ULong image_size; - if ( p+12 > p_limit ) - goto NoBitmap; - image_size = FT_NEXT_ULONG(p); + if ( p + 12 > p_limit ) + goto NoBitmap; - if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) - goto NoBitmap; + image_size = FT_NEXT_ULONG( p ); - image_start = image_offset + image_size*(glyph_index-start); - image_end = image_start + image_size; - } - break; + if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) + goto NoBitmap; + + image_start = image_offset + image_size * ( glyph_index - start ); + image_end = image_start + image_size; + } + break; case 3: /* 2-byte offsets relative to 'image_offset' */ - { - p += 2*(glyph_index-start); - if ( p+4 > p_limit ) - goto NoBitmap; + { + p += 2 * ( glyph_index - start ); + if ( p + 4 > p_limit ) + goto NoBitmap; - image_start = FT_NEXT_USHORT(p); - image_end = FT_NEXT_USHORT(p); + image_start = FT_NEXT_USHORT( p ); + image_end = FT_NEXT_USHORT( p ); - if ( image_start == image_end ) /* missing glyph */ - goto NoBitmap; - } - break; + if ( image_start == image_end ) /* missing glyph */ + goto NoBitmap; + } + break; case 4: /* sparse glyph array with (glyph,offset) pairs */ - { - FT_ULong mm, num_glyphs; + { + FT_ULong mm, num_glyphs; + - if ( p+4 > p_limit ) - goto NoBitmap; + if ( p + 4 > p_limit ) + goto NoBitmap; - num_glyphs = FT_NEXT_ULONG(p); - if ( p+(num_glyphs+1)*4 > p_limit ) - goto NoBitmap; + num_glyphs = FT_NEXT_ULONG( p ); + if ( p + ( num_glyphs + 1 ) * 4 > p_limit ) + goto NoBitmap; - for ( mm = 0; mm < num_glyphs; mm++ ) + for ( mm = 0; mm < num_glyphs; mm++ ) + { + FT_UInt gindex = FT_NEXT_USHORT( p ); + + + if ( gindex == glyph_index ) { - FT_UInt gindex = FT_NEXT_USHORT(p); - - if ( gindex == glyph_index ) - { - image_start = FT_NEXT_USHORT(p); - p += 2; - image_end = FT_PEEK_USHORT(p); - break; - } - p += 2; + image_start = FT_NEXT_USHORT( p ); + p += 2; + image_end = FT_PEEK_USHORT( p ); + break; } - - if ( mm >= num_glyphs ) - goto NoBitmap; + p += 2; } - break; + + if ( mm >= num_glyphs ) + goto NoBitmap; + } + break; case 5: /* constant metrics with sparse glyph codes */ - { - FT_ULong image_size, mm, num_glyphs; + { + FT_ULong image_size, mm, num_glyphs; - if ( p+16 > p_limit ) - goto NoBitmap; - image_size = FT_NEXT_ULONG(p); + if ( p + 16 > p_limit ) + goto NoBitmap; - if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) - goto NoBitmap; + image_size = FT_NEXT_ULONG( p ); - num_glyphs = FT_NEXT_ULONG(p); - if ( p + 2*num_glyphs > p_limit ) - goto NoBitmap; + if ( tt_sbit_decoder_load_metrics( decoder, &p, p_limit, 1 ) ) + goto NoBitmap; - for ( mm = 0; mm < num_glyphs; mm++ ) - { - FT_UInt gindex = FT_NEXT_USHORT(p); + num_glyphs = FT_NEXT_ULONG( p ); + if ( p + 2 * num_glyphs > p_limit ) + goto NoBitmap; - if ( gindex == glyph_index ) - break; - } + for ( mm = 0; mm < num_glyphs; mm++ ) + { + FT_UInt gindex = FT_NEXT_USHORT( p ); - if ( mm >= num_glyphs ) - goto NoBitmap; - image_start = image_offset + image_size*mm; - image_end = image_start + image_size; + if ( gindex == glyph_index ) + break; } - break; + + if ( mm >= num_glyphs ) + goto NoBitmap; + + image_start = image_offset + image_size*mm; + image_end = image_start + image_size; + } + break; default: - goto NoBitmap; + goto NoBitmap; } if ( image_start > image_end ) @@ -906,20 +925,18 @@ image_end -= image_start; image_start = image_offset + image_start; - return tt_sbit_decoder_load_bitmap( decoder, image_format, image_offset + image_start, image_end, x_pos, y_pos ); + NoBitmap: - return FT_Err_Invalid_Argument; + return SFNT_Err_Invalid_Argument; } - - FT_LOCAL( FT_Error ) tt_face_load_sbit_image( TT_Face face, FT_ULong strike_index, @@ -932,6 +949,7 @@ TT_SBitDecoderRec decoder[1]; FT_Error error; + error = tt_sbit_decoder_init( decoder, face, strike_index, metrics ); if ( !error ) { @@ -941,3 +959,5 @@ return error; } + +/* EOF */ |