freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] parthw-cleaned ec029f2: [tfm] Fixes.


From: Parth Wazurkar
Subject: [freetype2] parthw-cleaned ec029f2: [tfm] Fixes.
Date: Sun, 29 Jul 2018 02:06:27 -0400 (EDT)

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

    [tfm] Fixes.
---
 include/freetype/internal/tfm.h |  6 ++--
 src/gf/gfdrivr.c                | 51 +++++++++++++++++++++-------
 src/gf/gflib.c                  |  2 --
 src/tfm/tfmobjs.c               | 73 ++++++++++++++++++++++++-----------------
 4 files changed, 85 insertions(+), 47 deletions(-)

diff --git a/include/freetype/internal/tfm.h b/include/freetype/internal/tfm.h
index 2e2c5c9..24e43d9 100644
--- a/include/freetype/internal/tfm.h
+++ b/include/freetype/internal/tfm.h
@@ -46,9 +46,9 @@ FT_BEGIN_HEADER
   typedef struct  TFM_FontInfoRec_
   {
     /* Font Info */
-    FT_ULong       cs;
+    FT_ULong       cs; /* Check Sum */
     /* Metrics */
-    FT_ULong       ds;
+    FT_ULong       ds; /* Design Size */
     FT_UInt        design_size;
     FT_UInt        slant;
     FT_UInt        begin_char, end_char;
@@ -59,6 +59,8 @@ FT_BEGIN_HEADER
 
   } TFM_FontInfoRec, *TFM_FontInfo;
 
+  #define RDS2PT(rds)    (tfm->design_size * ((FT_Long)(rds)/(FT_Long)(1<<20)))
+
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
diff --git a/src/gf/gfdrivr.c b/src/gf/gfdrivr.c
index fbbc7aa..da985dc 100644
--- a/src/gf/gfdrivr.c
+++ b/src/gf/gfdrivr.c
@@ -165,10 +165,22 @@
     GF_Glyph    go=NULL;
     FT_UInt16   i,count;
 
+    TFM_Service tfm;
+
     FT_UNUSED( num_params );
     FT_UNUSED( params );
 
 
+    face->tfm = FT_Get_Module_Interface( FT_FACE_LIBRARY( face ),
+                                           "tfm" );
+    tfm = (TFM_Service)face->tfm;
+    if ( !tfm )
+    {
+      FT_ERROR(( "GF_Face_Init: cannot access `tfm' module\n" ));
+      error = FT_THROW( Missing_Module );
+      goto Exit;
+    }
+
     FT_TRACE2(( "GF driver\n" ));
 
     /* load font */
@@ -468,21 +480,36 @@
     if ( FT_NEW( fi ) )
       goto Exit;
 
+    FT_TRACE4(( "TFM_Read_Metrics: Invoking TFM_Service.\n" ));
+
     tfm = (TFM_Service)face->tfm;
-    if ( tfm->init )
-    {
-      error = tfm->init( &parser,
-                         memory,
-                         stream );
 
-      if ( !error )
-      {
-        parser.FontInfo  = fi;
-        parser.user_data = gf_glyph;
+    /* Initialise TFM Service */
+    error = tfm->init( &parser,
+                       memory,
+                       stream );
 
-        error = tfm->parse_metrics( &parser );
-        tfm->done( &parser );
-      }
+    if ( !error )
+    {
+      FT_TRACE4(( "TFM_Read_Metrics: Initialised tfm metric data.\n" ));
+      parser.FontInfo  = fi;
+      parser.user_data = gf_glyph;
+
+      error = tfm->parse_metrics( &parser );
+      if( !error )
+        FT_TRACE4(( "TFM_Read_Metrics: parsing TFM metric information done.\n" 
));
+
+      FT_TRACE5(( "TFM_Read_Metrics: TFM Metric Information:\n"
+                  "                  Check Sum  : %ld\n"
+                  "                  Design Size: %ld\n"
+                  "                  Begin Char : %d\n"
+                  "                  End Char   : %d\n"
+                  "                  font_bbx_w : %d\n"
+                  "                  font_bbx_h : %d\n"
+                  "                  slant      : %d\n", parser.FontInfo->cs, 
parser.FontInfo->design_size, parser.FontInfo->begin_char,
+                                                         
parser.FontInfo->end_char, parser.FontInfo->font_bbx_w,
+                                                         
parser.FontInfo->font_bbx_h, parser.FontInfo->slant ));
+      tfm->done( &parser );
     }
 
     if ( !error )
diff --git a/src/gf/gflib.c b/src/gf/gflib.c
index 323190d..21921b0 100644
--- a/src/gf/gflib.c
+++ b/src/gf/gflib.c
@@ -334,7 +334,6 @@ FT_Byte  bit_table[] = {
     pre = READ_UINT1( stream );
     if (pre != GF_PRE)
     {
-      FT_ERROR(( "gf_load_font: missing GF_PRE(247) field\n" ));
       error = FT_THROW( Unknown_File_Format );
       goto Exit;
     }
@@ -342,7 +341,6 @@ FT_Byte  bit_table[] = {
     id = READ_UINT1( stream );
     if (id != GF_ID)
     {
-      FT_ERROR(( "gf_load_font: missing GF_ID(131) field\n" ));
       error = FT_THROW( Unknown_File_Format );
       goto Exit;
     }
diff --git a/src/tfm/tfmobjs.c b/src/tfm/tfmobjs.c
index 529ad58..71d9673 100644
--- a/src/tfm/tfmobjs.c
+++ b/src/tfm/tfmobjs.c
@@ -50,8 +50,8 @@
   unsigned long  tfm_read_uintn(FT_Stream,int);
 
 #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)
+#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
@@ -163,7 +163,7 @@
     if( FT_STREAM_SEEK( 0 ) )
       return error;
 
-    lf = (FT_ULong)READ_UINT2( stream );
+    lf = (FT_ULong)READ_UINT2( stream );printf("Hi I am here lf is %ld",lf);
 
     #if 0
     if ((lf == 11) || (lf == 9))
@@ -184,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_FT_ULong(fp);
-      lh               = READ_FT_ULong(fp);
+      lf               = READ_UINT4(fp);
+      lh               = READ_UINT4(fp);
       if (tfm->type_aux == 0)
       {   /* level 0 OFM */
         offset_header    = 4*14;
@@ -200,6 +200,7 @@
     else
     { }
     #endif
+
     /* Traditional TeX Metric File */
     lh               = (int)READ_UINT2( stream );
     offset_header    = 4*6;
@@ -208,18 +209,18 @@
     #if 0
     if (tfm->type == METRIC_TYPE_OFM)
     {
-      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);
+      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);
 
       if (((signed)(tfm->begin_char-1) > (signed)tfm->end_char) ||
         (tfm->end_char > 65535))
@@ -231,6 +232,7 @@
     else
     { }
     #endif
+
     fi->begin_char  = (int)READ_UINT2( stream );
     fi->end_char    = (int)READ_UINT2( stream );
 
@@ -258,53 +260,62 @@
     /* fseek(fp, offset_header, SEEK_SET); */
     if (FT_STREAM_SEEK( offset_header ) )
       goto Exit;
-    fi->cs          = READ_FT_ULong( stream );
-    fi->ds          = READ_FT_ULong( stream );
-    fi->design_size = (double)(fi->ds)/(double)(1<<20);
+    fi->cs          = READ_UINT4( stream ); /* Check Sum  */
+    fi->ds          = READ_UINT4( stream ); /* Dsign Size */
+
+    fi->design_size = (FT_ULong)(fi->ds)/(FT_ULong)(1<<20);
 
     nc  = fi->end_char - fi->begin_char + 1;
     nci = nc;
+
     #if 0
     if (tfm->type == METRIC_TYPE_OFM)
       nci *= 2;
     #endif
+
     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_FT_ULong( stream );
+      ci[i] = READ_UINT4( 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_FT_Long( stream );
+      w[i] = READ_INT4( stream );
     for (i = 0; i < nh; i++)
-      h[i] = READ_FT_Long( stream );
+      h[i] = READ_INT4( stream );
     for (i = 0; i < nd; i++)
-      d[i] = READ_FT_Long( stream );
+      d[i] = READ_INT4( stream );
 
     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)
     {
@@ -331,24 +342,24 @@
     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 * ((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));
@@ -367,7 +378,7 @@
       }
       for (i = 0; i < tfm->nt; i++)
       {
-        v = READ_FT_ULong(fp);
+        v = READ_UINT4(fp);
         tfm->ct_kcode[i] = v/0x10000L;
         tfm->ct_ctype[i] = v%0x10000L;
       }



reply via email to

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