freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] parthw-cleaned 279ad58: [gf] Minor fixes.


From: Parth Wazurkar
Subject: [freetype2] parthw-cleaned 279ad58: [gf] Minor fixes.
Date: Fri, 29 Jun 2018 04:52:31 -0400 (EDT)

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

    [gf] Minor fixes.
---
 modules.cfg      |   2 +-
 src/gf/gf.h      |   1 +
 src/gf/gfdrivr.c |  68 +++++++++++++++++++-----------
 src/gf/gfdrivr.h |  33 ++++++++-------
 src/gf/gflib.c   | 125 +++++++++++++++++++++++++------------------------------
 src/gf/rules.mk  |  16 +++----
 6 files changed, 126 insertions(+), 119 deletions(-)

diff --git a/modules.cfg b/modules.cfg
index 79be2b9..3337e91 100644
--- a/modules.cfg
+++ b/modules.cfg
@@ -68,7 +68,7 @@ FONT_MODULES += pcf
 FONT_MODULES += bdf
 
 # GF font driver.
-#FONT_MODULES += gf
+FONT_MODULES += gf
 
 # SFNT files support.  If used without `truetype' or `cff', it supports
 # bitmap-only fonts within an SFNT wrapper.
diff --git a/src/gf/gf.h b/src/gf/gf.h
index b88f730..e624b95 100644
--- a/src/gf/gf.h
+++ b/src/gf/gf.h
@@ -23,6 +23,7 @@
 #include <ft2build.h>
 #include FT_INTERNAL_OBJECTS_H
 #include FT_INTERNAL_STREAM_H
+#include FT_SYSTEM_H
 
 
 FT_BEGIN_HEADER
diff --git a/src/gf/gfdrivr.c b/src/gf/gfdrivr.c
index a60948f..cfd7ef9 100644
--- a/src/gf/gfdrivr.c
+++ b/src/gf/gfdrivr.c
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
- * gfdrivr.h
+ * gfdrivr.c
  *
  *   FreeType font driver for TeX's GF FONT files
  *
@@ -20,7 +20,8 @@
 #include FT_INTERNAL_DEBUG_H
 #include FT_INTERNAL_STREAM_H
 #include FT_INTERNAL_OBJECTS_H
-
+#include FT_TRUETYPE_IDS_H
+#include FT_SERVICE_FONT_FORMAT_H
 
 #include "gf.h"
 #include "gfdrivr.h"
@@ -50,10 +51,11 @@
                  FT_Pointer  init_data )
   {
     GF_CMap  cmap = (GF_CMap)gfcmap;
+    GF_Face  face = (GF_Face)FT_CMAP_FACE( cmap );
     FT_UNUSED( init_data );
 
-    cmap->bc     = 0;
-    cmap->ec     = 255;
+    cmap->bc     = face->gf_glyph->code_min;
+    cmap->ec     = face->gf_glyph->code_max;
 
     return FT_Err_Ok;
   }
@@ -89,6 +91,7 @@
   gf_cmap_char_next(  FT_CMap     gfcmap,
                       FT_UInt32  *achar_code )
   {
+    GF_CMap    cmap   = (GF_CMap)gfcmap;
     FT_UInt    gindex = 0;
     FT_UInt32  result = 0;
     FT_UInt32  char_code = *achar_code + 1;
@@ -131,7 +134,7 @@
   GF_Face_Done( FT_Face        gfface )         /* GF_Face */
   {
     GF_Face    face = (GF_Face)gfface;
-    FT_Memory  memory;
+    FT_Memory  memory= FT_FACE_MEMORY( gfface );
 
 
     if ( !face )
@@ -139,7 +142,8 @@
 
     memory = FT_FACE_MEMORY( face );
 
-    gf_free_font( face->gf_glyph );
+    gf_free_font( face->gf_glyph, memory );
+    /* FT_FREE(  ); */
   }
 
 
@@ -154,6 +158,7 @@
     FT_Error    error;
     FT_Memory   memory = FT_FACE_MEMORY( face );
     GF_Glyph    go;
+    int i,count;
 
     face->gf_glyph = &go ;
     FT_UNUSED( num_params );
@@ -171,9 +176,20 @@
 
     gfface->num_faces       = 1;
     gfface->face_index      = 0;
-    gfface->face_flags |    = FT_FACE_FLAG_FIXED_SIZES | 
FT_FACE_FLAG_HORIZONTAL ;
+    gfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+                             FT_FACE_FLAG_HORIZONTAL ;
+    /*
+     * XXX: TO-DO: gfface->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+     * XXX: I have to check for this.
+     */
     gfface->family_name     = NULL;
-    gfface->num_glyphs      = (FT_Long)(go->code_max - go->code_min + 1 );
+    count=0;
+    for (i = 0; i < 256; i++)
+    {
+      if(go->bm_table[i].bitmap != NULL)
+        count++;
+    }
+    gfface->num_glyphs      = (FT_Long)count;
     gfface->num_fixed_sizes = 1;
 
     if ( FT_NEW_ARRAY( gfface->available_sizes, 1 ) )
@@ -185,7 +201,7 @@
 
         bsize->width  = (FT_Short) face->gf_glyph->font_bbx_w ;
         bsize->height = (FT_Short) face->gf_glyph->font_bbx_h ;
-        bsize->size   = (FT_Short) face->gf_glyph->ds ; /* Preliminary to be 
checked for 26.6 fractional points*/
+        bsize->size   = (FT_Short) face->gf_glyph->ds         ; /* Preliminary 
to be checked for 26.6 fractional points*/
 
         /*x_res =  ;  To be Checked for x_resolution and y_resolution
         y_res =  ;*/
@@ -204,7 +220,7 @@
         /* initial platform/encoding should indicate unset status? */
         charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;  /*Preliminary */
         charmap.encoding_id = TT_APPLE_ID_DEFAULT;
-        charmap.face        = root;
+        charmap.face        = face;
 
         error = FT_CMap_New( &gf_cmap_class, NULL, &charmap, NULL );
 
@@ -213,7 +229,7 @@
       }
 
   Fail:
-    GF_Face_Done( gfface );
+    GF_Face_Done( gfface );/**/
 
   Exit:
     return error;
@@ -286,7 +302,10 @@
     FT_Face      face   = FT_FACE( gf );
     FT_Error     error  = FT_Err_Ok;
     FT_Bitmap*   bitmap = &slot->bitmap;
-    GF_BitmapRec glyph ;
+    GF_BitmapRec bm ;
+    GF_Glyph    go;
+
+    go = gf->gf_glyph;
 
     FT_UNUSED( load_flags );
 
@@ -305,26 +324,25 @@
 
     FT_TRACE1(( "GF_Glyph_Load: glyph index %d\n", glyph_index ));
 
-    #if 0
-    if ( glyph_index > 0 )
-      glyph_index--;
-    else
-      glyph_index = /*  */;
-    #endif
-
     if ( glyph_index < 0 )
       glyph_index = 0;
 
+    if ((glyph_index < go->code_min) || (go->code_max < glyph_index))
+    {
+      error = FT_THROW( Invalid_Argument );
+      goto Exit;
+    }
+
     /* slot, bitmap => freetype, glyph => gflib */
-    glyph = gf->gf_glyph->bm_table[glyph_index];
+    bm = gf->gf_glyph->bm_table[glyph_index];
 
-    bitmap->rows  = bm.mv_y ; /* Prelimiary */
-    bitmap->width = bm.mv_x ; /* Prelimiary */
-    /* bitmap->pitch =  ; */
+    bitmap->rows  = bm.mv_y   ; /* Prelimiary */
+    bitmap->width = bm.mv_x   ; /* Prelimiary */
+    bitmap->pitch = bm.raster ; /* Prelimiary */
 
     /* note: we don't allocate a new array to hold the bitmap; */
     /*       we can simply point to it                         */
-    ft_glyphslot_set_bitmap( slot, bm.bitmap );
+    ft_glyphslot_set_bitmap( slot, bm.bitmap ); /* TO CHECK for column and 
row? like winfont.*/
 
     slot->format      = FT_GLYPH_FORMAT_BITMAP;
     slot->bitmap_left = bm.off_x ; /* Prelimiary */
@@ -336,7 +354,7 @@
     slot->metrics.width        = (FT_Pos) ( bitmap->width * 64 )        ; /* 
Prelimiary */
     slot->metrics.height       = (FT_Pos) ( bitmap->rows * 64 )         ; /* 
Prelimiary */
 
-    ft_synthesize_vertical_metrics( &slot->metrics, bm.bbx_height * 64  );
+    ft_synthesize_vertical_metrics( &slot->metrics, bm.bbx_height * 64 );
 
   Exit:
     return error;
diff --git a/src/gf/gfdrivr.h b/src/gf/gfdrivr.h
index 07a7564..f32b3b0 100644
--- a/src/gf/gfdrivr.h
+++ b/src/gf/gfdrivr.h
@@ -28,32 +28,33 @@
 FT_BEGIN_HEADER
 
   /* BitmapRec for GF format specific glyphs  */
-  typedef struct GF_BitmapRec_ 
+  typedef struct GF_BitmapRec_
   {
-    int              bbx_width, bbx_height;   
-    int              off_x, off_y;            
-    int              mv_x,  mv_y;            
-    unsigned char    *bitmap;
-    int              raster;
+    FT_UInt              bbx_width, bbx_height;
+    FT_UInt              off_x, off_y;
+    FT_UInt              mv_x,  mv_y;
+    FT_Byte              *bitmap;
+    FT_UInt              raster;
+
   } GF_BitmapRec, *GF_Bitmap;
-       
 
-  typedef struct GF_Glyph_ 
+
+  typedef struct GF_GlyphRec_
   {
-    int         code_min, code_max; 
-    GF_BITMAP   bm_table;
-    double      ds, hppp, vppp;
-    int         font_bbx_w, font_bbx_h;
-    int         font_bbx_xoff, font_bbx_yoff;
-  } GF_Glyph, *GF_Glyph;
+    FT_UInt         code_min, code_max;
+    GF_Bitmap       bm_table;
+    double          ds, hppp, vppp;
+    FT_UInt         font_bbx_w, font_bbx_h;
+    FT_UInt         font_bbx_xoff, font_bbx_yoff;
+
+  } GF_GlyphRec, *GF_Glyph;
 
 
   typedef struct  GF_FaceRec_
   {
     FT_FaceRec        root;
     GF_Glyph          gf_glyph;
-    GF_BitmapRec      gf_bitmap;
-    
+
   } GF_FaceRec, *GF_Face;
 
 
diff --git a/src/gf/gflib.c b/src/gf/gflib.c
index 31bd2ec..aaab4ed 100644
--- a/src/gf/gflib.c
+++ b/src/gf/gflib.c
@@ -1,6 +1,6 @@
 /****************************************************************************
  *
- * gfdrivr.h
+ * gflib.c
  *
  *   FreeType font driver for TeX's GF FONT files
  *
@@ -107,7 +107,7 @@ unsigned char   bit_table[] = {
    */
 
   FT_LOCAL_DEF( FT_Error )
-  gf_read_glyph(FT_Stream stream, GF_Bitmap bm)
+  gf_read_glyph(FT_Stream stream, GF_Bitmap bm, FT_Memory memory)
   {
     long           m, n;
     int            paint_sw;
@@ -116,33 +116,31 @@ unsigned char   bit_table[] = {
     long           w, h, d;
     int            m_b, k;
     unsigned char  *ptr;
-    FT_Error    error  = FT_Err_Ok;
-    FT_Face     face   = FT_FACE_STREAM( stream );
-    FT_Memory   memory = FT_FACE_MEMORY( face );
+    FT_Error       error  = FT_Err_Ok;
 
     switch (READ_UINT1( stream ))
     {
-      case GF_BOC:
-        FT_STREAM_SKIP( 4 );
-        FT_STREAM_SKIP( 4 );
-        min_m = READ_INT4( stream );
-        max_m = READ_INT4( stream );
-        min_n = READ_INT4( stream );
-        max_n = READ_INT4( stream );
-        break;
-
-      case GF_BOC1:
-        FT_STREAM_SKIP( 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 );
-        min_m = max_m - del_m;
-        min_n = max_n - del_n;
-        break;
-
-      default:
-        goto Fail;
+    case GF_BOC:
+      FT_STREAM_SKIP( 4 );
+      FT_STREAM_SKIP( 4 );
+      min_m = READ_INT4( stream );
+      max_m = READ_INT4( stream );
+      min_n = READ_INT4( stream );
+      max_n = READ_INT4( stream );
+      break;
+
+    case GF_BOC1:
+      FT_STREAM_SKIP( 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 );
+      min_m = max_m - del_m;
+      min_n = max_n - del_n;
+      break;
+
+    default:
+      return -1;
     }
 
     w = max_m - min_m + 1;
@@ -150,13 +148,13 @@ unsigned char   bit_table[] = {
     if ((w < 0) || (h < 0))
     {
       error = FT_THROW( Invalid_File_Format );
-      goto Fail;
+      return -1;
     }
 
     if ((bm->bitmap = (unsigned char*)malloc(h*((w+7)/8))) == NULL)
     {
       error = FT_THROW( Invalid_File_Format );
-      goto Fail;
+      return -1;
     }
 
     memset(bm->bitmap, 0, h*((w+7)/8));
@@ -194,11 +192,10 @@ unsigned char   bit_table[] = {
       {
         switch ((int)instr)
         {
-          case GF_PAINT1:
-          case GF_PAINT2:
-          case GF_PAINT3:
+        case GF_PAINT1:
+        case GF_PAINT2:
+        case GF_PAINT3:
           d = (UINT4)READ_UINTN( stream, (instr - GF_PAINT1 + 1));
-
           Paint:
             if (paint_sw == 0)
             {
@@ -222,50 +219,39 @@ unsigned char   bit_table[] = {
             }
             paint_sw = 1 - paint_sw;
           break;
-
-                                       case GF_SKIP0:
+        case GF_SKIP0:
           m = min_m;
           n = n - 1;
           paint_sw = 0;
           break;
-
-          case GF_SKIP1:
-          case GF_SKIP2:
-          case GF_SKIP3:
+        case GF_SKIP1:
+        case GF_SKIP2:
+        case GF_SKIP3:
           m = min_m;
           n = n - (UINT4)READ_UINTN( stream, (instr - GF_SKIP1 + 1)) - 1;
           paint_sw = 0;
           break;
-
-          case GF_XXX1:
-          case GF_XXX2:
-          case GF_XXX3:
-          case GF_XXX4:
+        case GF_XXX1:
+        case GF_XXX2:
+        case GF_XXX3:
+        case GF_XXX4:
           k = READ_UINTN( stream, instr - GF_XXX1 + 1);
           FT_STREAM_SKIP( k );
           break;
-
-          case GF_YYY:
+        case GF_YYY:
           FT_STREAM_SKIP( 4 );
           break;
-
-          case GF_NO_OP:
+        case GF_NO_OP:
           break;
-
-          default:
+        default:
           FT_FREE(bm->bitmap);
           bm->bitmap = NULL;
           error = FT_THROW( Invalid_File_Format );
-          goto Exit;
+          return -1;
          }
       }
     }
-
-    Fail:
-      return -1;
-
-    Exit:
-      return error;
+    return 0;
   }
 
 
@@ -444,7 +430,7 @@ unsigned char   bit_table[] = {
       FT_STREAM_SEEK( ptr );
 
       bm = &go->bm_table[code - bc];
-      if (gf_read_glyph( stream, bm ) < 0)
+      if (gf_read_glyph( stream, bm, memory ) < 0)
         goto ErrExit;
 
       bm->mv_x = dx;
@@ -453,7 +439,6 @@ unsigned char   bit_table[] = {
       FT_STREAM_SEEK( optr );
     }
     *goptr          = go;
-
   return error;
 
                ErrExit:
@@ -462,30 +447,32 @@ unsigned char   bit_table[] = {
       {
         if (go->bm_table != NULL)
         {
-          for (i = 0; i < nchars; i++)
-            FT_FREE(go->bm_table[i].bitmap);
+          for (i = 0; i < nchars; i++){}
+            /* FT_FREE(go->bm_table[i].bitmap); */
         }
-        FT_FREE(go->bm_table);
+        /* FT_FREE(go->bm_table); */
       }
-      FT_FREE(go);
-      return NULL;
+      /* FT_FREE(go); */
   }
 
 
   FT_LOCAL_DEF( void )
-  gf_free_font( GF_Glyph  go, FT_Memory memory )
+  gf_free_font( FT_Face gfface, FT_Memory memory )
   {
-    int i=0, nchars =sizeof(go->bm_table);
+    GF_Face    gf = (GF_Face)gfface;
+    GF_Glyph   go;
+    go = gf->gf_glyph;
+    int i=0, nchars =gfface->num_glyphs;
     if (go != NULL)
     {
       if (go->bm_table != NULL)
       {
-        for (i = 0; i < nchars; i++)
-          FT_FREE(go->bm_table[i].bitmap);
+        for (i = 0; i < nchars; i++){}
+          /* FT_FREE(go->bm_table[i].bitmap); */
       }
-      FT_FREE(go->bm_table);
+      /* FT_FREE(go->bm_table); */
     }
-    FT_FREE(go);
+    /* FT_FREE(go); */
   }
 
 
diff --git a/src/gf/rules.mk b/src/gf/rules.mk
index 4f13803..a261541 100644
--- a/src/gf/rules.mk
+++ b/src/gf/rules.mk
@@ -26,27 +26,27 @@ GF_COMPILE := $(CC) $(ANSIFLAGS)                            
\
 
 # gf driver sources (i.e., C files)
 #
-BDF_DRV_SRC := $(BDF_DIR)/gflib.c \
-               $(BDF_DIR)/gfdrivr.c
+GF_DRV_SRC := $(GF_DIR)/gflib.c \
+               $(GF_DIR)/gfdrivr.c
 
 
 # gf driver headers
 #
-GF_DRV_H :=  $(BDF_DIR)/gf.h \
-             $(BDF_DIR)/gfdrivr.h \
-             $(BDF_DIR)/gferror.h
+GF_DRV_H :=  $(GF_DIR)/gf.h \
+             $(GF_DIR)/gfdrivr.h \
+             $(GF_DIR)/gferror.h
 
 # gf driver object(s)
 #
 #   GF_DRV_OBJ_M is used during `multi' builds
 #   GF_DRV_OBJ_S is used during `single' builds
 #
-GF_DRV_OBJ_M := $(GF_DRV_SRC:$(BDF_DIR)/%.c=$(OBJ_DIR)/%.$O)
+GF_DRV_OBJ_M := $(GF_DRV_SRC:$(GF_DIR)/%.c=$(OBJ_DIR)/%.$O)
 GF_DRV_OBJ_S := $(OBJ_DIR)/gf.$O
 
 # gf driver source file for single build
 #
-GF_DRV_SRC_S := $(BDF_DIR)/gf.c
+GF_DRV_SRC_S := $(GF_DIR)/gf.c
 
 
 # gf driver - single object
@@ -57,7 +57,7 @@ $(GF_DRV_OBJ_S): $(GF_DRV_SRC_S) $(GF_DRV_SRC) $(FREETYPE_H) 
$(GF_DRV_H)
 
 # gf driver - multiple objects
 #
-$(OBJ_DIR)/%.$O: $(GF_DIR)/%.c $(FREETYPE_H) $(BDF_DRV_H)
+$(OBJ_DIR)/%.$O: $(GF_DIR)/%.c $(FREETYPE_H) $(GF_DRV_H)
        $(GF_COMPILE) $T$(subst /,$(COMPILER_SEP),$@ $<)
 
 



reply via email to

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