[gf] Cleanup commit.

* Rename `gf' files' header.
* Remove all the unnecessary typedefs and
switch to FT specific ones.
* Remove unnecessary comments.
This commit is contained in:
Parth Wazurkar 2018-07-17 14:55:39 +05:30
parent cde0317724
commit 62a92ff723
4 changed files with 75 additions and 87 deletions

View File

@ -2,7 +2,7 @@
*
* gf.h
*
* FreeType font driver for TeX's GF FONT files
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
@ -61,15 +61,6 @@ FT_BEGIN_HEADER
#define toint(x) (int)(((x)>0)?(x+0.5):(x-0.5))
typedef char INT1;
typedef unsigned char UINT1;
typedef int INT2;
typedef unsigned int UINT2;
typedef long INT3;
typedef unsigned long UINT3;
typedef long INT4;
typedef unsigned long UINT4;
FT_END_HEADER

View File

@ -2,7 +2,7 @@
*
* gfdrivr.c
*
* FreeType font driver for TeX's GF FONT files
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.

View File

@ -2,7 +2,7 @@
*
* gfdrivr.h
*
* FreeType font driver for TeX's GF FONT files
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.

View File

@ -2,7 +2,7 @@
*
* gflib.c
*
* FreeType font driver for TeX's GF FONT files
* FreeType font driver for METAFONT GF FONT files
*
* Copyright 1996-2018 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
@ -40,7 +40,7 @@
#undef FT_COMPONENT
#define FT_COMPONENT trace_gflib
unsigned char bit_table[] = {
FT_Byte bit_table[] = {
0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
/**************************************************************************
@ -49,57 +49,62 @@ unsigned char bit_table[] = {
*
*/
long gf_read_intn(FT_Stream,int);
unsigned long gf_read_uintn(FT_Stream,int);
FT_Long gf_read_intn(FT_Stream, FT_Int);
FT_ULong gf_read_uintn(FT_Stream, FT_Int);
#define READ_UINT1( stream ) (UINT1)gf_read_uintn( stream, 1)
#define READ_UINT2( stream ) (UINT1)gf_read_uintn( stream, 2)
#define READ_UINT3( stream ) (UINT1)gf_read_uintn( stream, 3)
#define READ_UINT4( stream ) (UINT1)gf_read_uintn( stream, 4)
#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)
#define READ_UINT1( stream ) (FT_Byte)gf_read_uintn( stream, 1)
#define READ_UINT2( stream ) (FT_Byte)gf_read_uintn( stream, 2)
#define READ_UINT3( stream ) (FT_Byte)gf_read_uintn( stream, 3)
#define READ_UINT4( stream ) (FT_Byte)gf_read_uintn( stream, 4)
#define READ_UINTN( stream,n) (FT_ULong)gf_read_uintn( stream, n)
#define READ_INT1( stream ) (FT_String)gf_read_intn( stream, 1)
#define READ_INT4( stream ) (FT_Long)gf_read_intn( stream, 4)
/*
* Reading a Number from file
*/
unsigned long
gf_read_uintn(FT_Stream stream, int size)
FT_ULong
gf_read_uintn(FT_Stream stream, FT_Int size)
{
unsigned long v,k;
FT_Error error;
FT_Byte tp;
FT_ULong v,k;
FT_Error error;
FT_Byte tp;
v = 0L;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0; /* To be changed */
k =(unsigned long)tp;
return 0;
k = (FT_ULong)tp;
v = v*256L + k;
--size;
}
return v;
}
long
gf_read_intn(FT_Stream stream, int size)
FT_Long
gf_read_intn(FT_Stream stream, FT_Int size)
{
long v;
FT_Byte tp;
FT_Error error;
unsigned long z ;
FT_Long v;
FT_Byte tp;
FT_Error error;
FT_ULong z;
if ( FT_READ_BYTE(tp) )
return 0;/* To be changed */
z= (unsigned long)tp;
v = (long)z & 0xffL;
return 0;
z = (FT_ULong)tp;
v = (FT_Long)z & 0xffL;
if (v & 0x80L)
v = v - 256L;
--size;
while (size >= 1)
{
if ( FT_READ_BYTE(tp) )
return 0;/* To be changed */
z= (unsigned long)tp;
return 0;
z = (FT_ULong)tp;
v = v*256L + z;
--size;
}
@ -113,21 +118,23 @@ unsigned char bit_table[] = {
*/
FT_LOCAL_DEF( FT_Error )
gf_read_glyph(FT_Stream stream, GF_Bitmap bm, FT_Memory memory)
gf_read_glyph( FT_Stream stream,
GF_Bitmap bm,
FT_Memory memory )
{
long m, n;
int paint_sw;
int instr,inst;
INT4 min_m, max_m, min_n, max_n, del_m, del_n;
long w, h, d;
int m_b, k;
unsigned char *ptr;
FT_Long m, n;
FT_Int paint_sw;
FT_Int instr,inst;
FT_Long min_m, max_m, min_n, max_n, del_m, del_n;
FT_Long w, h, d;
FT_Int m_b, k;
FT_Byte *ptr;
FT_Error error = FT_Err_Ok;
for ( ; ; )
{
inst = READ_UINT1( stream );
switch ((int)inst)
switch ((FT_Int)inst)
{
case GF_BOC:
if ( FT_STREAM_SKIP( 4 ) )
@ -143,31 +150,31 @@ unsigned char bit_table[] = {
case GF_BOC1:
if ( FT_STREAM_SKIP( 1 ) )
return -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 );
del_m = (FT_Long)READ_UINT1( stream );
max_m = (FT_Long)READ_UINT1( stream );
del_n = (FT_Long)READ_UINT1( stream );
max_n = (FT_Long)READ_UINT1( stream );
min_m = max_m - del_m;
min_n = max_n - del_n;
goto BOC;
break;
case GF_XXX1:
k = (UINT4)READ_UINT1( stream );
k = (FT_ULong)READ_UINT1( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX2:
k = (UINT4)READ_UINT2( stream );
k = (FT_ULong)READ_UINT2( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX3:
k = (UINT4)READ_UINT3( stream );
k = (FT_ULong)READ_UINT3( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
case GF_XXX4:
k = (UINT4)READ_UINT4( stream );
k = (FT_ULong)READ_UINT4( stream );
if ( FT_STREAM_SKIP( k ) )
return -1;
break;
@ -183,6 +190,7 @@ unsigned char bit_table[] = {
}
return 0;
BOC:
if(error != FT_Err_Ok)
return -1;
@ -196,7 +204,7 @@ unsigned char bit_table[] = {
}
/* allocate and build bitmap */
if ((bm->bitmap = (unsigned char*)malloc(h*((w+7)/8))) == NULL)
if ((bm->bitmap = (FT_Byte*)malloc(h*((w+7)/8))) == NULL)
{
error = FT_THROW( Invalid_File_Format );
return -1;
@ -216,7 +224,7 @@ unsigned char bit_table[] = {
m = min_m;
n = max_n;
paint_sw = 0;
while ((instr = (int)READ_UINT1( stream )) != GF_EOC)
while ((instr = (FT_Int)READ_UINT1( stream )) != GF_EOC)
{
if (instr == GF_PAINT_0)
{
@ -235,12 +243,12 @@ unsigned char bit_table[] = {
}
else
{
switch ((int)instr)
switch ((FT_Int)instr)
{
case GF_PAINT1:
case GF_PAINT2:
case GF_PAINT3:
d = (UINT4)READ_UINTN( stream, (instr - GF_PAINT1 + 1));
d = (FT_ULong)READ_UINTN( stream, (instr - GF_PAINT1 + 1));
Paint:
if (paint_sw == 0)
{
@ -273,7 +281,7 @@ unsigned char bit_table[] = {
case GF_SKIP2:
case GF_SKIP3:
m = min_m;
n = n - (UINT4)READ_UINTN( stream, (instr - GF_SKIP1 + 1)) - 1;
n = n - (FT_ULong)READ_UINTN( stream, (instr - GF_SKIP1 + 1)) - 1;
paint_sw = 0;
break;
case GF_XXX1:
@ -301,22 +309,19 @@ unsigned char bit_table[] = {
return 0;
}
FT_LOCAL_DEF( FT_Error )
gf_load_font( FT_Stream stream,
FT_Memory extmemory,
GF_Glyph *goptr )
gf_load_font( FT_Stream stream,
FT_Memory extmemory,
GF_Glyph *goptr )
{
GF_Glyph go;
GF_Bitmap bm;
UINT1 instr, d, pre, id, k;
UINT4 ds, check_sum, hppp, vppp;
INT4 min_m, max_m, min_n, max_n;
INT4 w;
UINT4 code;
FT_Byte instr, d, pre, id, k, code;
FT_ULong ds, check_sum, hppp, vppp;
FT_Long min_m, max_m, min_n, max_n, w;
FT_UInt dx, dy;
long ptr_post, ptr_p, ptr, optr;
int bc, ec, nchars, i;
FT_Long ptr_post, ptr_p, ptr, optr;
FT_Int bc, ec, nchars, i;
FT_Error error = FT_Err_Ok;
FT_Memory memory = extmemory; /* needed for FT_NEW */
@ -347,7 +352,6 @@ unsigned char bit_table[] = {
goto Exit;
/* seek to post_post instr. */
/* fseek(fp, -1, SEEK_END); */
if( FT_STREAM_SEEK( stream->size - 1 ) )
goto Exit;
if( FT_STREAM_SEEK( stream->size - 1 ) )
@ -357,7 +361,6 @@ unsigned char bit_table[] = {
{
if( FT_STREAM_SEEK( stream->pos -2 ) )
goto Exit;
/* fseek(fp, -2, SEEK_CUR); */
}
@ -374,7 +377,6 @@ unsigned char bit_table[] = {
FT_TRACE2(( "gf_load_font: GF_ID(131) found\n" ));
/* fseek(fp, -6, SEEK_CUR); */
if(FT_STREAM_SEEK( stream->pos -6 ))
goto Exit;
@ -400,7 +402,6 @@ unsigned char bit_table[] = {
}
/* goto post instr. and read it */
/* fseek(fp, ptr_post, SEEK_SET); */
if(FT_STREAM_SEEK( ptr_post ))
goto Exit;
@ -427,7 +428,7 @@ unsigned char bit_table[] = {
min_n = READ_INT4( stream );
max_n = READ_INT4( stream );
if( ptr_p < 0 ) /* Defined to use ptr_p */
if( ptr_p < 0 ) /* Defined to use ptr_p */
{
FT_ERROR(( "gf_load_font: invalid pointer in postamble\n" ));
goto Exit;
@ -439,7 +440,7 @@ unsigned char bit_table[] = {
goto Exit;
}
#if 0
gptr = ftell(fp);
gptr = ftell(fp);
#endif
#if 0
@ -479,11 +480,10 @@ unsigned char bit_table[] = {
#endif
nchars = ec - bc + 1;
/*go= malloc(sizeof(GF_GlyphRec));*/
if( FT_ALLOC(go, sizeof(GF_GlyphRec)) )
goto Exit;
/*go->bm_table = (GF_Bitmap)malloc(nchars* sizeof(GF_BitmapRec));*/
if( FT_ALLOC_MULT(go->bm_table, sizeof(GF_BitmapRec), nchars) )
goto Exit;
@ -511,7 +511,7 @@ unsigned char bit_table[] = {
{
if ((instr = READ_UINT1( stream )) == GF_POST_POST)
break;
switch ((int)instr)
switch ((FT_Int)instr)
{
case GF_CHAR_LOC:
code = READ_UINT1( stream );
@ -534,16 +534,14 @@ unsigned char bit_table[] = {
}
/*
if( w > max_m)
if( w > max_m) Defined to use w
{
FT_ERROR(( "gf_load_font: invalid width in charloc\n" ));
goto Exit;
}
*/
/* optr = ft_ftell(fp); */
optr = stream->pos;
/* ft_fseek(fp, ptr, SEEK_SET); */
if( FT_STREAM_SEEK( ptr ) )
goto Exit;
@ -553,7 +551,6 @@ unsigned char bit_table[] = {
bm->mv_x = dx;
bm->mv_y = dy;
/* ft_fseek(fp, optr, SEEK_SET); */
if(FT_STREAM_SEEK( optr ))
goto Exit;
}