diff --git a/src/gf/gflib.c b/src/gf/gflib.c index c0ad307e9..31bd2eca2 100644 --- a/src/gf/gflib.c +++ b/src/gf/gflib.c @@ -21,6 +21,10 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_OBJECTS_H +#include FT_SYSTEM_H +#include FT_CONFIG_CONFIG_H +#include FT_ERRORS_H +#include FT_TYPES_H #include "gf.h" #include "gfdrivr.h" @@ -36,6 +40,8 @@ #undef FT_COMPONENT #define FT_COMPONENT trace_gflib +unsigned char bit_table[] = { + 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; /************************************************************************** * @@ -43,105 +49,57 @@ * */ - long gf_read_intn(FILE*,int); - unsigned long gf_read_uintn(FILE*,int); - void gf_skip_n(FILE*,int); - -#define READ_INT1(fp) (INT1)gf_read_intn((fp), 1) -#define READ_UINT1(fp) (UINT1)gf_read_uintn((fp), 1) -#define READ_INT2(fp) (INT2)gf_read_intn((fp), 2) -#define READ_UINT2(fp) (UINT2)gf_read_uintn((fp), 2) -#define READ_INT3(fp) (INT3)gf_read_intn((fp), 3) -#define READ_UINT3(fp) (UINT3)gf_read_uintn((fp), 3) -#define READ_INT4(fp) (INT4)gf_read_intn((fp), 4) -#define READ_UINT4(fp) (UINT4)gf_read_uintn((fp), 4) -#define READ_INTN(fp,n) (INT4)gf_read_intn((fp), (n)) -#define READ_UINTN(fp,n) (UINT4)gf_read_uintn((fp), (n)) -#define SKIP_N(fp,k) gf_skip_n((fp), (k)) + long gf_read_intn(FT_Stream,int); + unsigned long gf_read_uintn(FT_Stream,int); +#define READ_UINT1( stream ) (UINT1)gf_read_uintn( stream, 1) +#define READ_UINTN( stream,n) (UINT4)gf_read_uintn( stream, n) +#define READ_INT1( stream ) (INT1)gf_read_intn( stream, 1) +#define READ_INT4( stream ) (INT4)gf_read_intn( stream, 4) /* * Reading a Number from file */ unsigned long - gf_read_uintn(FILE* fp, int size) + gf_read_uintn(FT_Stream stream, int size) { - unsigned long v; - + unsigned long v,k; + FT_Error error = FT_Err_Ok; + FT_Byte tp; v = 0L; while (size >= 1) { - v = v*256L + (unsigned long)getc(fp); + FT_READ_BYTE(tp); + k =(unsigned long)tp; + v = v*256L + k; --size; } return v; } long - gf_read_intn(FILE* fp, int size) + gf_read_intn(FT_Stream stream, int size) { long v; - - v = (long)getc(fp) & 0xffL; + FT_Byte tp; + FT_Error error= FT_Err_Ok; + unsigned long z ; + FT_READ_BYTE(tp); + z= (unsigned long)tp; + v = (long)z & 0xffL; if (v & 0x80L) v = v - 256L; --size; while (size >= 1) { - v = v*256L + (unsigned long)getc(fp); + FT_READ_BYTE(tp); + z= (unsigned long)tp; + v = v*256L + z; --size; } - return v; } - void - gf_skip_n(FILE* fp, int size) - { - - while (size > 0) - { - (void)getc(fp); - --size; - } - - } - - unsigned long - gf_get_uintn(unsigned char *p, int size) - { - unsigned long v; - - v = 0L; - while (size >= 1) - { - v = v*256L + (unsigned long) *(p++); - --size; - } - - return v; - } - - long - gf_get_intn(unsigned char *p, int size) - { - long v; - - v = (long)*(p++) & 0xffL; - if (v & 0x80L) - v = v - 256L; - --size; - while (size >= 1) - { - v = v*256L + (unsigned long) *(p++); - --size; - } - - return v; - } - - - /************************************************************************** * * API. @@ -149,7 +107,7 @@ */ FT_LOCAL_DEF( FT_Error ) - gf_read_glyph(FT_FILE* fp, GF_BITMAP bm) + gf_read_glyph(FT_Stream stream, GF_Bitmap bm) { long m, n; int paint_sw; @@ -158,30 +116,33 @@ long w, h, d; int m_b, k; unsigned char *ptr; + FT_Error error = FT_Err_Ok; + FT_Face face = FT_FACE_STREAM( stream ); + FT_Memory memory = FT_FACE_MEMORY( face ); - switch (READ_UINT1(fp)) + switch (READ_UINT1( stream )) { case GF_BOC: - SKIP_N(fp, 4); - SKIP_N(fp, 4); - min_m = READ_INT4(fp); - max_m = READ_INT4(fp); - min_n = READ_INT4(fp); - max_n = READ_INT4(fp); + FT_STREAM_SKIP( 4 ); + FT_STREAM_SKIP( 4 ); + min_m = READ_INT4( stream ); + max_m = READ_INT4( stream ); + min_n = READ_INT4( stream ); + max_n = READ_INT4( stream ); break; case GF_BOC1: - SKIP_N(fp, 1); - del_m = (INT4)READ_UINT1(fp); - max_m = (INT4)READ_UINT1(fp); - del_n = (INT4)READ_UINT1(fp); - max_n = (INT4)READ_UINT1(fp); + FT_STREAM_SKIP( 1 ); + del_m = (INT4)READ_UINT1( stream ); + max_m = (INT4)READ_UINT1( stream ); + del_n = (INT4)READ_UINT1( stream ); + max_n = (INT4)READ_UINT1( stream ); min_m = max_m - del_m; min_n = max_n - del_n; break; default: - goto Exit; + goto Fail; } w = max_m - min_m + 1; @@ -189,16 +150,16 @@ if ((w < 0) || (h < 0)) { error = FT_THROW( Invalid_File_Format ); - goto Exit; + goto Fail; } if ((bm->bitmap = (unsigned char*)malloc(h*((w+7)/8))) == NULL) { error = FT_THROW( Invalid_File_Format ); - goto Exit; + goto Fail; } - memclr(bm->bitmap, h*((w+7)/8)); + memset(bm->bitmap, 0, h*((w+7)/8)); bm->raster = (w+7)/8; bm->bbx_width = w; bm->bbx_height = h; @@ -212,7 +173,7 @@ m = min_m; n = max_n; paint_sw = 0; - while ((instr = (int)READ_UINT1(fp)) != GF_EOC) + while ((instr = (int)READ_UINT1( stream )) != GF_EOC) { if (instr == GF_PAINT_0) { @@ -236,7 +197,7 @@ case GF_PAINT1: case GF_PAINT2: case GF_PAINT3: - d = (UINT4)READ_UINTN(fp, (instr - GF_PAINT1 + 1)); + d = (UINT4)READ_UINTN( stream, (instr - GF_PAINT1 + 1)); Paint: if (paint_sw == 0) @@ -272,7 +233,7 @@ case GF_SKIP2: case GF_SKIP3: m = min_m; - n = n - (UINT4)READ_UINTN(fp, (instr - GF_SKIP1 + 1)) - 1; + n = n - (UINT4)READ_UINTN( stream, (instr - GF_SKIP1 + 1)) - 1; paint_sw = 0; break; @@ -280,12 +241,12 @@ case GF_XXX2: case GF_XXX3: case GF_XXX4: - k = READ_UINTN(fp, instr - GF_XXX1 + 1); - SKIP_N(fp, k); + k = READ_UINTN( stream, instr - GF_XXX1 + 1); + FT_STREAM_SKIP( k ); break; case GF_YYY: - SKIP_N(fp, 4); + FT_STREAM_SKIP( 4 ); break; case GF_NO_OP: @@ -300,6 +261,9 @@ } } + Fail: + return -1; + Exit: return error; } @@ -307,10 +271,11 @@ FT_LOCAL_DEF( FT_Error ) gf_load_font( FT_Stream stream, - GF_Face face ) + FT_Memory extmemory, + GF_Glyph *goptr ) { - GF_GLYPH go; - GF_BITMAP bm; + GF_Glyph go; + GF_Bitmap bm; UINT1 instr, d; UINT4 ds, check_sum, hppp, vppp; INT4 min_m, max_m, min_n, max_n; @@ -319,18 +284,24 @@ double dx, dy; long ptr_post, ptr_p, ptr, optr, gptr; int bc, ec, nchars, i; - FT_Error error = FT_Err_Ok; - - FT_FILE *fp = stream->descriptor.pointer + FT_Error error = FT_Err_Ok, error1; + FT_Memory memory = extmemory; /* needed for FT_NEW */ + FT_ULong offset; + FT_Byte tp; go = NULL; nchars = -1; /* seek to post_post instr. */ - ft_fseek(fp, -1, SEEK_END); + /* fseek(fp, -1, SEEK_END); */ + FT_STREAM_SEEK( stream->size - 1 ); - while ((d = READ_UINT1(fp)) == 223) - fseek(fp, -2, SEEK_CUR); + while ( d= READ_UINT1( stream ) == 223) + FT_STREAM_SEEK( stream->pos -2 ); + /* fseek(fp, -2, SEEK_CUR); */ + + FT_STREAM_SEEK( stream->pos -1 ); + d= READ_UINT1( stream ); if (d != GF_ID) { @@ -338,42 +309,46 @@ goto ErrExit; } - fseek(fp, -6, SEEK_CUR); + /* fseek(fp, -6, SEEK_CUR); */ + FT_STREAM_SEEK( stream->pos -6 ); /* check if the code is post_post */ - if (READ_UINT1(fp) != GF_POST_POST) + if (READ_UINT1( stream ) != GF_POST_POST) { error = FT_THROW( Invalid_File_Format ); goto ErrExit; } /* read pointer to post instr. */ - if ((ptr_post = READ_UINT4(fp)) == -1) + FT_READ_ULONG( ptr_post ); + if (ptr_post == -1) { error = FT_THROW( Invalid_File_Format ); goto ErrExit; } /* goto post instr. and read it */ - fseek(fp, ptr_post, SEEK_SET); - if (READ_UINT1(fp) != GF_POST) + /* fseek(fp, ptr_post, SEEK_SET); */ + FT_STREAM_SEEK( ptr_post ); + if (READ_UINT1( stream ) != GF_POST) { error = FT_THROW( Invalid_File_Format ); goto ErrExit; } - ptr_p = READ_UINT4(fp); - ds = READ_UINT4(fp); - check_sum = READ_UINT4(fp); - hppp = READ_UINT4(fp); - vppp = READ_UINT4(fp); - min_m = READ_INT4(fp); - max_m = READ_INT4(fp); - min_n = READ_INT4(fp); - max_n = READ_INT4(fp); + FT_READ_ULONG( ptr_p ) ; + FT_READ_ULONG( ds ) ; + FT_READ_ULONG( check_sum ); + FT_READ_ULONG( hppp ) ; + FT_READ_ULONG( vppp ) ; + min_m = READ_INT4( stream ); + max_m = READ_INT4( stream ); + min_n = READ_INT4( stream ); + max_n = READ_INT4( stream ); + #if 0 gptr = ftell(fp); - + #endif #if 0 /* read min & max char code */ @@ -412,10 +387,12 @@ #endif nchars = ec - bc + 1; - FT_ALLOC(go, GF_GlyphRec) + /*go= malloc(sizeof(GF_GlyphRec));*/ + if( FT_ALLOC(go, sizeof(GF_GlyphRec)) ) goto ErrExit; - FT_ALLOC_MULT(go->bm_table, GF_BitmapRec, nchars) + /*go->bm_table = (GF_Bitmap)malloc(nchars* sizeof(GF_BitmapRec));*/ + if( FT_ALLOC_MULT(go->bm_table, sizeof(GF_BitmapRec), nchars) ) goto ErrExit; for (i = 0; i < nchars; i++) @@ -438,45 +415,46 @@ for ( ; ; ) { - if ((instr = READ_UINT1(fp)) == GF_POST_POST) + if ((instr = READ_UINT1( stream )) == GF_POST_POST) break; switch ((int)instr) { - - case GF_CHAR_LOC: - code = READ_UINT1(fp); - dx = (double)READ_INT4(fp)/(double)(1<<16); - dy = (double)READ_INT4(fp)/(double)(1<<16); - w = READ_INT4(fp); - ptr = READ_INT4(fp); - break; - - case GF_CHAR_LOC0: - code = READ_UINT1(fp); - dx = (double)READ_INT1(fp); - dy = (double)0; - w = READ_INT4(fp); - ptr = READ_INT4(fp); - break; - - default: - error = FT_THROW( Invalid_File_Format ); - goto ErrExit; - + case GF_CHAR_LOC: + code = READ_UINT1( stream ); + dx = (double)READ_INT4( stream )/(double)(1<<16); + dy = (double)READ_INT4( stream )/(double)(1<<16); + w = READ_INT4( stream ); + ptr = READ_INT4( stream ); + break; + case GF_CHAR_LOC0: + code = READ_UINT1( stream ); + dx = (double)READ_INT1( stream ); + dy = (double)0; + w = READ_INT4( stream ); + ptr = READ_INT4( stream ); + break; + default: + error = FT_THROW( Invalid_File_Format ); + goto ErrExit; } - optr = ft_ftell(fp); - ft_fseek(fp, ptr, SEEK_SET); + /* optr = ft_ftell(fp); */ + optr = stream->pos; + /* ft_fseek(fp, ptr, SEEK_SET); */ + FT_STREAM_SEEK( ptr ); bm = &go->bm_table[code - bc]; - if (gf_read_glyph(fp, bm) < 0) + if (gf_read_glyph( stream, bm ) < 0) goto ErrExit; bm->mv_x = dx; bm->mv_y = dy; - ft_fseek(fp, optr, SEEK_SET); + /* ft_fseek(fp, optr, SEEK_SET); */ + FT_STREAM_SEEK( optr ); } - return go; + *goptr = go; + + return error; ErrExit: printf("*ERROR\n"); @@ -495,8 +473,9 @@ FT_LOCAL_DEF( void ) - gf_free_font( GF_Glyph gf_glyph ) + gf_free_font( GF_Glyph go, FT_Memory memory ) { + int i=0, nchars =sizeof(go->bm_table); if (go != NULL) { if (go->bm_table != NULL)