freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] parthw-cleaned 9e73451: [tfm] Fixes.


From: Parth Wazurkar
Subject: [freetype2] parthw-cleaned 9e73451: [tfm] Fixes.
Date: Thu, 26 Jul 2018 17:09:54 -0400 (EDT)

branch: parthw-cleaned
commit 9e73451cb9b1d98a9a760d12a874b2a2fc7d1a6b
Author: Parth Wazurkar <address@hidden>
Commit: Parth Wazurkar <address@hidden>

    [tfm] Fixes.
---
 include/freetype/internal/tfm.h |   3 -
 modules.cfg                     |   5 ++
 src/tfm/rules.mk                |   1 +
 src/tfm/tfm.c                   |   1 +
 src/tfm/tfmmod.c                |   2 +-
 src/tfm/tfmobjs.c               | 121 +++++++++++++++++++++-------------------
 src/tfm/tfmobjs.h               |   5 +-
 7 files changed, 74 insertions(+), 64 deletions(-)

diff --git a/include/freetype/internal/tfm.h b/include/freetype/internal/tfm.h
index 7289e67..2e2c5c9 100644
--- a/include/freetype/internal/tfm.h
+++ b/include/freetype/internal/tfm.h
@@ -118,9 +118,6 @@ FT_BEGIN_HEADER
     FT_Error
     (*parse_metrics)( TFM_Parser  parser );
 
-    FT_Error
-    (*parse_kern)( TFM_Parser  parser );
-
     void
     (*done)( TFM_Parser  parser );
 
diff --git a/modules.cfg b/modules.cfg
index 3337e91..61042c0 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 394a2a0..4311745 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 055ed5c..51738b2 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 9f2aaf9..f987fa4 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 d725a4d..529ad58 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_FT_ULong( stream )    (FT_Byte)tfm_read_uintn( stream, 4)
+#define READ_FT_Long( 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,6 +133,7 @@
   {
     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;
@@ -157,7 +163,7 @@
     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 +171,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);
     }
@@ -178,8 +184,8 @@
       tfm->type_aux    = READ_INT2(fp);    /* ofm_level */
       if ((tfm->type_aux < 0) || (1 < tfm->type_aux))
         tfm->type_aux = 0;  /* broken, maybe */
-      lf               = READ_UINT4(fp);
-      lh               = READ_UINT4(fp);
+      lf               = READ_FT_ULong(fp);
+      lh               = READ_FT_ULong(fp);
       if (tfm->type_aux == 0)
       {   /* level 0 OFM */
         offset_header    = 4*14;
@@ -202,18 +208,18 @@
     #if 0
     if (tfm->type == METRIC_TYPE_OFM)
     {
-      tfm->begin_char  = READ_UINT4(fp);
-      tfm->end_char    = READ_UINT4(fp);
-      nw   = READ_UINT4(fp);
-      nh   = READ_UINT4(fp);
-      nd   = READ_UINT4(fp);
-
-      ni   = READ_UINT4(fp);
-      nl   = READ_UINT4(fp);
-      nk   = READ_UINT4(fp);
-      neng = READ_UINT4(fp);
-      np   = READ_UINT4(fp);
-      dir  = READ_UINT4(fp);
+      tfm->begin_char  = READ_FT_ULong(fp);
+      tfm->end_char    = READ_FT_ULong(fp);
+      nw   = READ_FT_ULong(fp);
+      nh   = READ_FT_ULong(fp);
+      nd   = READ_FT_ULong(fp);
+
+      ni   = READ_FT_ULong(fp);
+      nl   = READ_FT_ULong(fp);
+      nk   = READ_FT_ULong(fp);
+      neng = READ_FT_ULong(fp);
+      np   = READ_FT_ULong(fp);
+      dir  = READ_FT_ULong(fp);
 
       if (((signed)(tfm->begin_char-1) > (signed)tfm->end_char) ||
         (tfm->end_char > 65535))
@@ -228,15 +234,15 @@
     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,8 +258,8 @@
     /* 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->cs          = READ_FT_ULong( stream );
+    fi->ds          = READ_FT_ULong( stream );
     fi->design_size = (double)(fi->ds)/(double)(1<<20);
 
     nc  = fi->end_char - fi->begin_char + 1;
@@ -262,10 +268,10 @@
     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 );
@@ -275,21 +281,21 @@
     if( FT_STREAM_SEEK( offset_char_info ) )
       goto Exit;
     for (i = 0; i < nci; i++)
-      ci[i] = READ_UINT4( stream );
+      ci[i] = READ_FT_ULong( stream );
 
     /* offset_param = ftell(fp) + 4*(nw + nh + nd + ni + nl + nk + neng); */
     offset_param = stream->pos + 4*(nw + nh + nd + ni + nl + nk + neng);
 
     for (i = 0; i < nw; i++)
-      w[i] = READ_INT4( stream );
+      w[i] = READ_FT_Long( stream );
     for (i = 0; i < nh; i++)
-      h[i] = READ_INT4( stream );
+      h[i] = READ_FT_Long( stream );
     for (i = 0; i < nd; i++)
-      d[i] = READ_INT4( stream );
+      d[i] = READ_FT_Long( 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 );
@@ -343,10 +349,10 @@
              (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 = fi->design_size * ((FT_ULong)bbxw / (FT_ULong)(1<<20));
+    fi->font_bbx_h = fi->design_size * ((FT_ULong)bbxh / (FT_ULong)(1<<20));
+    fi->font_bbx_xoff = fi->design_size * ((FT_ULong)xoff / (FT_ULong)(1<<20));
+    fi->font_bbx_yoff = fi->design_size * ((FT_ULong)yoff / (FT_ULong)(1<<20));
 
     #if 0
     if (tfm->type == METRIC_TYPE_JFM)
@@ -361,7 +367,7 @@
       }
       for (i = 0; i < tfm->nt; i++)
       {
-        v = READ_UINT4(fp);
+        v = READ_FT_ULong(fp);
         tfm->ct_kcode[i] = v/0x10000L;
         tfm->ct_ctype[i] = v%0x10000L;
       }
@@ -375,13 +381,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)fi->slant/(FT_ULong)(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 be55dc8..53bff11 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 );
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]