[tfm] Fixes.

This commit is contained in:
Parth Wazurkar 2018-07-30 23:40:43 +05:30
parent 4c8db5478b
commit 46ab8e2f4c
6 changed files with 79 additions and 52 deletions

View File

@ -140,6 +140,11 @@ AUX_MODULES += bzip2
# This module depends on `psnames'. # This module depends on `psnames'.
AUX_MODULES += psaux AUX_MODULES += psaux
# Auxiliary METAFONT driver component to share common code.
#
# TFM Module.
AUX_MODULES += tfm
# Support for PostScript glyph names. # Support for PostScript glyph names.
# #
# This module can be controlled in ftconfig.h # This module can be controlled in ftconfig.h

View File

@ -29,6 +29,7 @@ TFM_COMPILE := $(CC) $(ANSIFLAGS) \
# TFM driver sources (i.e., C files) # TFM driver sources (i.e., C files)
# #
TFM_DRV_SRC := $(TFM_DIR)/tfmmod.c \ TFM_DRV_SRC := $(TFM_DIR)/tfmmod.c \
$(TFM_DIR)/tfmobjs.c \
# TFM driver headers # TFM driver headers
# #

View File

@ -20,6 +20,7 @@
#include <ft2build.h> #include <ft2build.h>
#include "tfmmod.c" #include "tfmmod.c"
#include "tfmobjs.c"
/* END */ /* END */

View File

@ -18,6 +18,7 @@
#include <ft2build.h> #include <ft2build.h>
#include "tfmmod.h" #include "tfmmod.h"
#include "tfmobjs.h"
static static
@ -25,7 +26,6 @@
{ {
tfm_init, /* init */ tfm_init, /* init */
tfm_parse_metrics, /* parse metrics */ tfm_parse_metrics, /* parse metrics */
tfm_parse_kerns, /* parse kerns */
tfm_close, /* done */ tfm_close, /* done */
}; };

View File

@ -17,10 +17,17 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H
#include FT_INTERNAL_STREAM_H
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_TFM_H
#include "tfmobjs.h" #include "tfmobjs.h"
#include "tfmmod.h" #include "tfmmod.h"
#include FT_INTERNAL_STREAM_H #include "tfmerr.h"
#include "tfmerrors.h"
/************************************************************************** /**************************************************************************
@ -42,9 +49,9 @@
long tfm_read_intn(FT_Stream,int); long tfm_read_intn(FT_Stream,int);
unsigned long tfm_read_uintn(FT_Stream,int); unsigned long tfm_read_uintn(FT_Stream,int);
#define READ_UINT2( stream ) (UINT1)tfm_read_uintn( stream, 2) #define READ_UINT2( stream ) (FT_Byte)tfm_read_uintn( stream, 2)
#define READ_UINT4( stream ) (UINT1)tfm_read_uintn( stream, 4) #define READ_UINT4( stream ) (FT_Byte)tfm_read_uintn( stream, 4)
#define READ_INT4( stream ) (INT4)tfm_read_intn( stream, 4) #define READ_INT4( stream ) (FT_Long)tfm_read_intn( stream, 4)
/* /*
* Reading a Number from file * Reading a Number from file
@ -103,8 +110,6 @@
FT_Memory memory, FT_Memory memory,
FT_Stream stream ) FT_Stream stream )
{ {
FT_Error error;
parser->memory = memory; parser->memory = memory;
parser->stream = stream; parser->stream = stream;
parser->FontInfo = NULL; parser->FontInfo = NULL;
@ -128,11 +133,12 @@
{ {
FT_Memory memory = parser->memory; FT_Memory memory = parser->memory;
TFM_FontInfo fi = parser->FontInfo; TFM_FontInfo fi = parser->FontInfo;
FT_Stream stream = parser->stream;
FT_Error error = FT_ERR( Syntax_Error ); FT_Error error = FT_ERR( Syntax_Error );
FT_ULong lf, lh, nc, nci, err; FT_ULong lf, lh, nc, nci;
FT_ULong offset_header, offset_char_info, offset_param; FT_ULong offset_header, offset_char_info, offset_param;
FT_ULong nw, nh, nd, ni, nl, nk, neng, np, dir; FT_ULong nw, nh, nd, ni, nl, nk, neng, np;
FT_Long *w, *h, *d; FT_Long *w, *h, *d;
FT_ULong *ci, v; FT_ULong *ci, v;
@ -146,18 +152,21 @@
fi->width = NULL; fi->width = NULL;
fi->height = NULL; fi->height = NULL;
fi->depth = NULL; fi->depth = NULL;
ci = NULL;
w = NULL;
h = NULL;
d = NULL;
fi->font_bbx_w = 0.0; fi->font_bbx_w = 0.0;
fi->font_bbx_h = 0.0; fi->font_bbx_h = 0.0;
fi->font_bbx_xoff = 0.0; fi->font_bbx_xoff = 0.0;
fi->font_bbx_yoff = 0.0; fi->font_bbx_yoff = 0.0;
err = 0;
/* rewind(fp); */ /* rewind(fp); */
if( FT_STREAM_SEEK( 0 ) ) if( FT_STREAM_SEEK( 0 ) )
return error; return error;
lf = (UINT4)READ_UINT2( stream ); lf = (FT_ULong)READ_UINT2( stream );
#if 0 #if 0
if ((lf == 11) || (lf == 9)) if ((lf == 11) || (lf == 9))
@ -165,9 +174,9 @@
/* JFM file of Japanese TeX by ASCII Coop. */ /* JFM file of Japanese TeX by ASCII Coop. */
tfm->type = METRIC_TYPE_JFM; tfm->type = METRIC_TYPE_JFM;
tfm->type_aux = (lf == 11)?METRIC_TYPE_JFM_AUX_H:METRIC_TYPE_JFM_AUX_V; tfm->type_aux = (lf == 11)?METRIC_TYPE_JFM_AUX_H:METRIC_TYPE_JFM_AUX_V;
tfm->nt = (UINT4)READ_UINT2(fp); tfm->nt = (FT_ULong)READ_UINT2(fp);
lf = (UINT4)READ_UINT2(fp); lf = (FT_ULong)READ_UINT2(fp);
lh = (UINT4)READ_UINT2(fp); lh = (FT_ULong)READ_UINT2(fp);
offset_header = 4*7; offset_header = 4*7;
offset_char_info = 4*(7+tfm->nt+lh); offset_char_info = 4*(7+tfm->nt+lh);
} }
@ -194,6 +203,7 @@
else else
{ } { }
#endif #endif
/* Traditional TeX Metric File */ /* Traditional TeX Metric File */
lh = (int)READ_UINT2( stream ); lh = (int)READ_UINT2( stream );
offset_header = 4*6; offset_header = 4*6;
@ -225,18 +235,19 @@
else else
{ } { }
#endif #endif
fi->begin_char = (int)READ_UINT2( stream ); fi->begin_char = (int)READ_UINT2( stream );
fi->end_char = (int)READ_UINT2( stream ); fi->end_char = (int)READ_UINT2( stream );
nw = (UINT4)READ_UINT2( stream ); nw = (FT_ULong)READ_UINT2( stream );
nh = (UINT4)READ_UINT2( stream ); nh = (FT_ULong)READ_UINT2( stream );
nd = (UINT4)READ_UINT2( stream ); nd = (FT_ULong)READ_UINT2( stream );
ni = (UINT4)READ_UINT2( stream ); ni = (FT_ULong)READ_UINT2( stream );
nl = (UINT4)READ_UINT2( stream ); nl = (FT_ULong)READ_UINT2( stream );
nk = (UINT4)READ_UINT2( stream ); nk = (FT_ULong)READ_UINT2( stream );
neng = (UINT4)READ_UINT2( stream ); neng = (FT_ULong)READ_UINT2( stream );
np = (UINT4)READ_UINT2( stream ); np = (FT_ULong)READ_UINT2( stream );
#if 0 #if 0
if (tfm->type == METRIC_TYPE_TFM) if (tfm->type == METRIC_TYPE_TFM)
@ -252,28 +263,34 @@
/* fseek(fp, offset_header, SEEK_SET); */ /* fseek(fp, offset_header, SEEK_SET); */
if (FT_STREAM_SEEK( offset_header ) ) if (FT_STREAM_SEEK( offset_header ) )
goto Exit; goto Exit;
fi->cs = READ_UINT4( stream ); fi->cs = READ_UINT4( stream ); /* Check Sum */
fi->ds = READ_UINT4( stream ); fi->ds = READ_UINT4( stream ); /* Design Size */
fi->design_size = (double)(fi->ds)/(double)(1<<20);
fi->design_size = (FT_ULong)((double)(fi->ds)/(double)(1<<20));
nc = fi->end_char - fi->begin_char + 1; nc = fi->end_char - fi->begin_char + 1;
nci = nc; nci = nc;
#if 0 #if 0
if (tfm->type == METRIC_TYPE_OFM) if (tfm->type == METRIC_TYPE_OFM)
nci *= 2; nci *= 2;
#endif #endif
ci = (UINT4*)calloc(nci, sizeof(UINT4));
w = (INT4*)calloc(nw, sizeof(UINT4)); ci = (FT_ULong*)calloc(nci, sizeof(FT_ULong));
h = (INT4*)calloc(nh, sizeof(UINT4)); w = (FT_Long*)calloc(nw, sizeof(FT_ULong));
d = (INT4*)calloc(nd, sizeof(UINT4)); h = (FT_Long*)calloc(nh, sizeof(FT_ULong));
d = (FT_Long*)calloc(nd, sizeof(FT_ULong));
if ((ci == NULL) || (w == NULL) || (h == NULL) || (d == NULL)) if ((ci == NULL) || (w == NULL) || (h == NULL) || (d == NULL))
{ {
error = FT_THROW( Invalid_Argument ); error = FT_THROW( Invalid_Argument );
goto Exit; goto Exit;
} }
/* fseek(fp, offset_char_info, SEEK_SET); */ /* fseek(fp, offset_char_info, SEEK_SET); */
if( FT_STREAM_SEEK( offset_char_info ) ) if( FT_STREAM_SEEK( offset_char_info ) ) /* Skip over coding scheme and font family name */
goto Exit; goto Exit;
for (i = 0; i < nci; i++) for (i = 0; i < nci; i++)
ci[i] = READ_UINT4( stream ); ci[i] = READ_UINT4( stream );
@ -287,18 +304,21 @@
for (i = 0; i < nd; i++) for (i = 0; i < nd; i++)
d[i] = READ_INT4( stream ); d[i] = READ_INT4( stream );
fi->width = (INT4*)calloc(nc, sizeof(INT4)); fi->width = (FT_Long*)calloc(nc, sizeof(FT_Long));
fi->height = (INT4*)calloc(nc, sizeof(INT4)); fi->height = (FT_Long*)calloc(nc, sizeof(FT_Long));
fi->depth = (INT4*)calloc(nc, sizeof(INT4)); fi->depth = (FT_Long*)calloc(nc, sizeof(FT_Long));
if ((fi->width == NULL) || (fi->height == NULL) || (fi->depth == NULL)) if ((fi->width == NULL) || (fi->height == NULL) || (fi->depth == NULL))
{ {
error = FT_THROW( Invalid_Argument ); error = FT_THROW( Invalid_Argument );
goto Exit; goto Exit;
} }
bbxw = 0; bbxw = 0;
bbxh = 0; bbxh = 0;
xoff = 0; xoff = 0;
yoff = 0; yoff = 0;
#if 0 #if 0
if (tfm->type == METRIC_TYPE_OFM) if (tfm->type == METRIC_TYPE_OFM)
{ {
@ -325,28 +345,28 @@
else else
{ } { }
#endif #endif
for (i = 0; i < nc; i++) for (i = 0; i < nc; i++)
{ {
v = ci[i] / 0x10000L; v = ci[i] / 0x10000L;
fi->depth[i] = d[v & 0xf]; v >>= 4; fi->depth[i] = d[v & 0xf]; v >>= 4;
fi->height[i] = h[v & 0xf]; v >>= 4; fi->height[i] = h[v & 0xf]; v >>= 4;
fi->width[i] = w[v & 0xff]; fi->width[i] = w[v & 0xff];
if (bbxw < fi->width[i]) if (bbxw < fi->width[i])
bbxw = fi->width[i]; bbxw = fi->width[i];
if (bbxh < (fi->height[i] + fi->depth[i])) if (bbxh < (fi->height[i] + fi->depth[i]))
bbxh = fi->height[i] + fi->depth[i]; bbxh = fi->height[i] + fi->depth[i];
if (yoff > -fi->depth[i]) if (yoff > -fi->depth[i])
yoff = -fi->depth[i]; yoff = -fi->depth[i];
#if 0
printf("** %.3f %.3f\n",
(double)tfm->height[i]/(double)(1<<20),
(double)tfm->depth[i]/(double)(1<<20));
#endif
} }
fi->font_bbx_w = fi->design_size * ((double)bbxw / (double)(1<<20));
fi->font_bbx_h = fi->design_size * ((double)bbxh / (double)(1<<20)); fi->font_bbx_w = (FT_ULong)(fi->design_size * ((double)bbxw / (double)(1<<20)));
fi->font_bbx_xoff = fi->design_size * ((double)xoff / (double)(1<<20)); fi->font_bbx_h = (FT_ULong)(fi->design_size * ((FT_ULong)bbxh / (double)(1<<20)));
fi->font_bbx_yoff = fi->design_size * ((double)yoff / (double)(1<<20)); fi->font_bbx_xoff = (FT_ULong)(fi->design_size * ((double)xoff / (double)(1<<20)));
fi->font_bbx_yoff = (FT_ULong)(fi->design_size * ((double)yoff / (double)(1<<20)));
#if 0 #if 0
if (tfm->type == METRIC_TYPE_JFM) if (tfm->type == METRIC_TYPE_JFM)
@ -375,13 +395,16 @@
return error; /* To be changed */ return error; /* To be changed */
if (FT_READ_ULONG(fi->slant) ) if (FT_READ_ULONG(fi->slant) )
return error; return error;
fi->slant = (double)fi->slant/(double)(1<<20); fi->slant = (FT_ULong)((double)fi->slant/(double)(1<<20));
Exit: Exit:
FT_FREE(ci); if( !ci || !w || !h || !d )
FT_FREE(w); {
FT_FREE(h); FT_FREE(ci);
FT_FREE(d); FT_FREE(w);
FT_FREE(h);
FT_FREE(d);
}
return error; return error;
} }

View File

@ -34,16 +34,13 @@ FT_BEGIN_HEADER
/* Initialise the TFM stream */ /* Initialise the TFM stream */
FT_LOCAL( FT_Error ) FT_LOCAL( FT_Error )
tfm_init( TFM_Parser parser, tfm_init( TFM_Parser parser,
FT_Memory memory FT_Memory memory,
FT_Stream stream ); FT_Stream stream );
/* Parse TFM metric data */ /* Parse TFM metric data */
FT_LOCAL( FT_Error ) FT_LOCAL( FT_Error )
tfm_parse_metrics( TFM_Parser parser ); tfm_parse_metrics( TFM_Parser parser );
FT_LOCAL( FT_Error )
tfm_parse_kerns( TFM_Parser parser );
FT_LOCAL( void ) FT_LOCAL( void )
tfm_close( TFM_Parser parser ); tfm_close( TFM_Parser parser );