summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParth Wazurkar <parthwazurkar@gmail.com>2018-07-30 23:40:43 +0530
committerParth Wazurkar <parthwazurkar@gmail.com>2018-07-30 23:47:51 +0530
commitd3a78786b5a141657af8c6e1fcf21aab5940745a (patch)
tree1e0c4bd42451e4d06920a82d68080d4e0e39291b
parent8302c96c83be7b750d6080741448d0e26ab6efaa (diff)
downloadfreetype2-d3a78786b5a141657af8c6e1fcf21aab5940745a.tar.gz
[tfm] Fixes.
-rw-r--r--modules.cfg5
-rw-r--r--src/tfm/rules.mk1
-rw-r--r--src/tfm/tfm.c1
-rw-r--r--src/tfm/tfmmod.c2
-rw-r--r--src/tfm/tfmobjs.c117
-rw-r--r--src/tfm/tfmobjs.h5
6 files changed, 79 insertions, 52 deletions
diff --git a/modules.cfg b/modules.cfg
index 3337e91bd..61042c05e 100644
--- a/modules.cfg
+++ b/modules.cfg
@@ -140,6 +140,11 @@ AUX_MODULES += bzip2
# This module depends on `psnames'.
AUX_MODULES += psaux
+# Auxiliary METAFONT driver component to share common code.
+#
+# TFM Module.
+AUX_MODULES += tfm
+
# Support for PostScript glyph names.
#
# This module can be controlled in ftconfig.h
diff --git a/src/tfm/rules.mk b/src/tfm/rules.mk
index 394a2a04f..4311745c0 100644
--- a/src/tfm/rules.mk
+++ b/src/tfm/rules.mk
@@ -29,6 +29,7 @@ TFM_COMPILE := $(CC) $(ANSIFLAGS) \
# TFM driver sources (i.e., C files)
#
TFM_DRV_SRC := $(TFM_DIR)/tfmmod.c \
+ $(TFM_DIR)/tfmobjs.c \
# TFM driver headers
#
diff --git a/src/tfm/tfm.c b/src/tfm/tfm.c
index 055ed5ca0..51738b208 100644
--- a/src/tfm/tfm.c
+++ b/src/tfm/tfm.c
@@ -20,6 +20,7 @@
#include <ft2build.h>
#include "tfmmod.c"
+#include "tfmobjs.c"
/* END */
diff --git a/src/tfm/tfmmod.c b/src/tfm/tfmmod.c
index 9f2aaf967..f987fa4f4 100644
--- a/src/tfm/tfmmod.c
+++ b/src/tfm/tfmmod.c
@@ -18,6 +18,7 @@
#include <ft2build.h>
#include "tfmmod.h"
+#include "tfmobjs.h"
static
@@ -25,7 +26,6 @@
{
tfm_init, /* init */
tfm_parse_metrics, /* parse metrics */
- tfm_parse_kerns, /* parse kerns */
tfm_close, /* done */
};
diff --git a/src/tfm/tfmobjs.c b/src/tfm/tfmobjs.c
index d725a4d7c..69ec22e16 100644
--- a/src/tfm/tfmobjs.c
+++ b/src/tfm/tfmobjs.c
@@ -17,10 +17,17 @@
#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 "tfmmod.h"
-#include FT_INTERNAL_STREAM_H
-#include "tfmerrors.h"
+#include "tfmerr.h"
+
+
+
/**************************************************************************
@@ -42,9 +49,9 @@
long tfm_read_intn(FT_Stream,int);
unsigned long tfm_read_uintn(FT_Stream,int);
-#define READ_UINT2( stream ) (UINT1)tfm_read_uintn( stream, 2)
-#define READ_UINT4( stream ) (UINT1)tfm_read_uintn( stream, 4)
-#define READ_INT4( stream ) (INT4)tfm_read_intn( stream, 4)
+#define READ_UINT2( stream ) (FT_Byte)tfm_read_uintn( stream, 2)
+#define READ_UINT4( stream ) (FT_Byte)tfm_read_uintn( stream, 4)
+#define READ_INT4( stream ) (FT_Long)tfm_read_intn( stream, 4)
/*
* Reading a Number from file
@@ -103,8 +110,6 @@
FT_Memory memory,
FT_Stream stream )
{
- FT_Error error;
-
parser->memory = memory;
parser->stream = stream;
parser->FontInfo = NULL;
@@ -128,11 +133,12 @@
{
FT_Memory memory = parser->memory;
TFM_FontInfo fi = parser->FontInfo;
+ FT_Stream stream = parser->stream;
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 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_ULong *ci, v;
@@ -146,18 +152,21 @@
fi->width = NULL;
fi->height = NULL;
fi->depth = NULL;
+ ci = NULL;
+ w = NULL;
+ h = NULL;
+ d = NULL;
fi->font_bbx_w = 0.0;
fi->font_bbx_h = 0.0;
fi->font_bbx_xoff = 0.0;
fi->font_bbx_yoff = 0.0;
- err = 0;
/* rewind(fp); */
if( FT_STREAM_SEEK( 0 ) )
return error;
- lf = (UINT4)READ_UINT2( stream );
+ lf = (FT_ULong)READ_UINT2( stream );
#if 0
if ((lf == 11) || (lf == 9))
@@ -165,9 +174,9 @@
/* JFM file of Japanese TeX by ASCII Coop. */
tfm->type = METRIC_TYPE_JFM;
tfm->type_aux = (lf == 11)?METRIC_TYPE_JFM_AUX_H:METRIC_TYPE_JFM_AUX_V;
- tfm->nt = (UINT4)READ_UINT2(fp);
- lf = (UINT4)READ_UINT2(fp);
- lh = (UINT4)READ_UINT2(fp);
+ tfm->nt = (FT_ULong)READ_UINT2(fp);
+ lf = (FT_ULong)READ_UINT2(fp);
+ lh = (FT_ULong)READ_UINT2(fp);
offset_header = 4*7;
offset_char_info = 4*(7+tfm->nt+lh);
}
@@ -194,6 +203,7 @@
else
{ }
#endif
+
/* Traditional TeX Metric File */
lh = (int)READ_UINT2( stream );
offset_header = 4*6;
@@ -225,18 +235,19 @@
else
{ }
#endif
+
fi->begin_char = (int)READ_UINT2( stream );
fi->end_char = (int)READ_UINT2( stream );
- nw = (UINT4)READ_UINT2( stream );
- nh = (UINT4)READ_UINT2( stream );
- nd = (UINT4)READ_UINT2( stream );
+ nw = (FT_ULong)READ_UINT2( stream );
+ nh = (FT_ULong)READ_UINT2( stream );
+ nd = (FT_ULong)READ_UINT2( stream );
- ni = (UINT4)READ_UINT2( stream );
- nl = (UINT4)READ_UINT2( stream );
- nk = (UINT4)READ_UINT2( stream );
- neng = (UINT4)READ_UINT2( stream );
- np = (UINT4)READ_UINT2( stream );
+ ni = (FT_ULong)READ_UINT2( stream );
+ nl = (FT_ULong)READ_UINT2( stream );
+ nk = (FT_ULong)READ_UINT2( stream );
+ neng = (FT_ULong)READ_UINT2( stream );
+ np = (FT_ULong)READ_UINT2( stream );
#if 0
if (tfm->type == METRIC_TYPE_TFM)
@@ -252,28 +263,34 @@
/* fseek(fp, offset_header, SEEK_SET); */
if (FT_STREAM_SEEK( offset_header ) )
goto Exit;
- fi->cs = READ_UINT4( stream );
- fi->ds = READ_UINT4( stream );
- fi->design_size = (double)(fi->ds)/(double)(1<<20);
+ fi->cs = READ_UINT4( stream ); /* Check Sum */
+ fi->ds = READ_UINT4( stream ); /* Design Size */
+
+ fi->design_size = (FT_ULong)((double)(fi->ds)/(double)(1<<20));
nc = fi->end_char - fi->begin_char + 1;
nci = nc;
+
#if 0
if (tfm->type == METRIC_TYPE_OFM)
nci *= 2;
#endif
- ci = (UINT4*)calloc(nci, sizeof(UINT4));
- w = (INT4*)calloc(nw, sizeof(UINT4));
- h = (INT4*)calloc(nh, sizeof(UINT4));
- d = (INT4*)calloc(nd, sizeof(UINT4));
+
+ ci = (FT_ULong*)calloc(nci, sizeof(FT_ULong));
+ w = (FT_Long*)calloc(nw, sizeof(FT_ULong));
+ 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))
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
+
/* 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;
+
for (i = 0; i < nci; i++)
ci[i] = READ_UINT4( stream );
@@ -287,18 +304,21 @@
for (i = 0; i < nd; i++)
d[i] = READ_INT4( stream );
- fi->width = (INT4*)calloc(nc, sizeof(INT4));
- fi->height = (INT4*)calloc(nc, sizeof(INT4));
- fi->depth = (INT4*)calloc(nc, sizeof(INT4));
+ fi->width = (FT_Long*)calloc(nc, sizeof(FT_Long));
+ fi->height = (FT_Long*)calloc(nc, sizeof(FT_Long));
+ fi->depth = (FT_Long*)calloc(nc, sizeof(FT_Long));
+
if ((fi->width == NULL) || (fi->height == NULL) || (fi->depth == NULL))
{
error = FT_THROW( Invalid_Argument );
goto Exit;
}
+
bbxw = 0;
bbxh = 0;
xoff = 0;
yoff = 0;
+
#if 0
if (tfm->type == METRIC_TYPE_OFM)
{
@@ -325,28 +345,28 @@
else
{ }
#endif
+
for (i = 0; i < nc; i++)
{
v = ci[i] / 0x10000L;
fi->depth[i] = d[v & 0xf]; v >>= 4;
fi->height[i] = h[v & 0xf]; v >>= 4;
fi->width[i] = w[v & 0xff];
+
if (bbxw < fi->width[i])
bbxw = fi->width[i];
+
if (bbxh < (fi->height[i] + fi->depth[i]))
bbxh = fi->height[i] + fi->depth[i];
+
if (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_xoff = fi->design_size * ((double)xoff / (double)(1<<20));
- fi->font_bbx_yoff = fi->design_size * ((double)yoff / (double)(1<<20));
+
+ fi->font_bbx_w = (FT_ULong)(fi->design_size * ((double)bbxw / (double)(1<<20)));
+ fi->font_bbx_h = (FT_ULong)(fi->design_size * ((FT_ULong)bbxh / (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 (tfm->type == METRIC_TYPE_JFM)
@@ -375,13 +395,16 @@
return error; /* To be changed */
if (FT_READ_ULONG(fi->slant) )
return error;
- fi->slant = (double)fi->slant/(double)(1<<20);
+ fi->slant = (FT_ULong)((double)fi->slant/(double)(1<<20));
Exit:
- FT_FREE(ci);
- FT_FREE(w);
- FT_FREE(h);
- FT_FREE(d);
+ if( !ci || !w || !h || !d )
+ {
+ FT_FREE(ci);
+ FT_FREE(w);
+ FT_FREE(h);
+ FT_FREE(d);
+ }
return error;
}
diff --git a/src/tfm/tfmobjs.h b/src/tfm/tfmobjs.h
index be55dc84e..53bff119e 100644
--- a/src/tfm/tfmobjs.h
+++ b/src/tfm/tfmobjs.h
@@ -34,16 +34,13 @@ FT_BEGIN_HEADER
/* Initialise the TFM stream */
FT_LOCAL( FT_Error )
tfm_init( TFM_Parser parser,
- FT_Memory memory
+ FT_Memory memory,
FT_Stream stream );
/* Parse TFM metric data */
FT_LOCAL( FT_Error )
tfm_parse_metrics( TFM_Parser parser );
- FT_LOCAL( FT_Error )
- tfm_parse_kerns( TFM_Parser parser );
-
FT_LOCAL( void )
tfm_close( TFM_Parser parser );