freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] parthw-wip d5a0a07: [gf] Removed indentation errors.


From: Parth Wazurkar
Subject: [freetype2] parthw-wip d5a0a07: [gf] Removed indentation errors.
Date: Sat, 2 Jun 2018 07:03:26 -0400 (EDT)

branch: parthw-wip
commit d5a0a07faa085f9510cdf9200c65ba98d57681cc
Author: Parth Wazurkar <address@hidden>
Commit: Parth Wazurkar <address@hidden>

    [gf] Removed indentation errors.
---
 src/gf/gfdrivr.c | 437 ++++++++++++++++++++++++++++++-
 src/gf/gfdrivr.h |  34 +--
 src/gf/gflib.c   | 780 ++++++++++++++++++++++++++++---------------------------
 3 files changed, 838 insertions(+), 413 deletions(-)

diff --git a/src/gf/gfdrivr.c b/src/gf/gfdrivr.c
index b7e4664..0d4571b 100644
--- a/src/gf/gfdrivr.c
+++ b/src/gf/gfdrivr.c
@@ -40,8 +40,8 @@
   typedef struct  GF_CMapRec_
   {
     FT_CMapRec        cmap;            
-               FT_UInt32                               bc;                     
        /*Beginning Character*/
-               FT_UInt32         ec;                           /*End 
Character*/
+    FT_UInt32                          bc;                             /* 
Beginning Character */
+    FT_UInt32         ec;                              /* End Character */
   } GF_CMapRec, *GF_CMap;
 
 
@@ -49,7 +49,7 @@
   gf_cmap_init(  FT_CMap     gfcmap,
                  FT_Pointer  init_data )
   {
-               GF_CMap  cmap = (GF_CMap)gfcmap;
+    GF_CMap  cmap = (GF_CMap)gfcmap;
     FT_UNUSED( init_data );
 
     cmap->bc     = 0;
@@ -62,7 +62,7 @@
   FT_CALLBACK_DEF( void )
   gf_cmap_done( FT_CMap  gfcmap )
   {
-               GF_CMap  cmap = (GF_CMap)gfcmap;
+    GF_CMap  cmap = (GF_CMap)gfcmap;
 
     cmap->bc     =  0;
     cmap->ec     = -1;
@@ -74,10 +74,10 @@
   gf_cmap_char_index(  FT_CMap    gfcmap,
                        FT_UInt32  char_code )
   {
-               FT_UInt  gindex = 0;
-               GF_CMap  cmap   = (GF_CMap)gfcmap;
+    FT_UInt  gindex = 0;
+    GF_CMap  cmap   = (GF_CMap)gfcmap;
                
-               char_code -= cmap->bc;
+    char_code -= cmap->bc;
    
     if ( char_code < cmap->ec - cmap->bc + 1 )
       gindex = (FT_UInt)( char_code );
@@ -89,7 +89,7 @@
   gf_cmap_char_next(  FT_CMap     gfcmap,
                       FT_UInt32  *achar_code )
   {
-               FT_UInt    gindex = 0;
+    FT_UInt    gindex = 0;
     FT_UInt32  result = 0;
     FT_UInt32  char_code = *achar_code + 1;
 
@@ -130,7 +130,17 @@
   FT_CALLBACK_DEF( void )
   GF_Face_Done( FT_Face        gfface )         /* GF_Face */
   {
-               //TO-DO
+    GF_Face    face = (GF_Face)gfface;
+    FT_Memory  memory;
+
+    if ( !face )
+      return;
+
+    memory = FT_FACE_MEMORY( face );
+
+    gf_free_font( face->gf_glyph );
+
+    FT_FREE( face- );
   }
 
 
@@ -141,15 +151,420 @@
                  FT_Int         num_params,
                  FT_Parameter*  params )
   {
-               //TO-DO
+    FT_Error       error  = FT_Err_Ok;
+    GF_Face        face   = (GF_Face)gfface;
+    FT_Memory      memory = FT_FACE_MEMORY( face );
+
+    FT_TRACE2(( "GF driver\n" ));
+
+    if ( FT_STREAM_SEEK( 0 ) )
+      goto Exit;
+
+    error = gf_load_font( stream, face );
+    if ( FT_ERR_EQ( error, Missing_Startfont_Field ) )
+    {
+      FT_TRACE2(( "  not a BDF file\n" ));
+      goto Fail;
+    }
+    else if ( error )
+      goto Exit;
+
+    /* we have a bdf font: let's construct the face object */
+    face->bdffont = font;
+
+    {
+
+      FT_TRACE4(( "  number of glyphs: allocated %d (used %d)\n",
+                  font->glyphs_size,
+                  font->glyphs_used ));
+
+      bdfface->num_faces  = 1;
+      bdfface->face_index = 0;
+
+      bdfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+                             FT_FACE_FLAG_HORIZONTAL  |
+                             FT_FACE_FLAG_FAST_GLYPHS;
+
+      /* the number of glyphs (with one slot for the undefined glyph */
+      /* at position 0 and all unencoded glyphs)                     */
+      bdfface->num_glyphs = (FT_Long)( font->glyphs_size + 1 );
+
+      bdfface->num_fixed_sizes = 1;
+      if ( FT_NEW_ARRAY( bdfface->available_sizes, 1 ) )
+        goto Exit;
+
+
+      /* encoding table */
+      {
+        bdf_glyph_t*   cur = font->glyphs;
+        unsigned long  n;
+
+
+        if ( FT_NEW_ARRAY( face->en_table, font->glyphs_size ) )
+          goto Exit;
+
+        face->default_glyph = 0;
+        for ( n = 0; n < font->glyphs_size; n++ )
+        {
+          (face->en_table[n]).enc = cur[n].encoding;
+          FT_TRACE4(( "  idx %d, val 0x%lX\n", n, cur[n].encoding ));
+          (face->en_table[n]).glyph = (FT_UShort)n;
+
+          if ( cur[n].encoding == font->default_char )
+          {
+            if ( n < FT_UINT_MAX )
+              face->default_glyph = (FT_UInt)n;
+            else
+              FT_TRACE1(( "BDF_Face_Init:"
+                          " idx %d is too large for this system\n", n ));
+          }
+        }
+      }
+
+      /* charmaps */
+      {
+        bdf_property_t  *charset_registry, *charset_encoding;
+        FT_Bool          unicode_charmap  = 0;
+
+
+        charset_registry =
+          bdf_get_font_property( font, "CHARSET_REGISTRY" );
+        charset_encoding =
+          bdf_get_font_property( font, "CHARSET_ENCODING" );
+        if ( charset_registry && charset_encoding )
+        {
+          if ( charset_registry->format == BDF_ATOM &&
+               charset_encoding->format == BDF_ATOM &&
+               charset_registry->value.atom         &&
+               charset_encoding->value.atom         )
+          {
+            const char*  s;
+
+
+            if ( FT_STRDUP( face->charset_encoding,
+                            charset_encoding->value.atom ) ||
+                 FT_STRDUP( face->charset_registry,
+                            charset_registry->value.atom ) )
+              goto Exit;
+
+            /* Uh, oh, compare first letters manually to avoid dependency */
+            /* on locales.                                                */
+            s = face->charset_registry;
+            if ( ( s[0] == 'i' || s[0] == 'I' ) &&
+                 ( s[1] == 's' || s[1] == 'S' ) &&
+                 ( s[2] == 'o' || s[2] == 'O' ) )
+            {
+              s += 3;
+              if ( !ft_strcmp( s, "10646" )                      ||
+                   ( !ft_strcmp( s, "8859" ) &&
+                     !ft_strcmp( face->charset_encoding, "1" ) ) )
+                unicode_charmap = 1;
+              /* another name for ASCII */
+              else if ( !ft_strcmp( s, "646.1991" )                 &&
+                        !ft_strcmp( face->charset_encoding, "IRV" ) )
+                unicode_charmap = 1;
+            }
+
+            {
+              FT_CharMapRec  charmap;
+
+
+              charmap.face        = FT_FACE( face );
+              charmap.encoding    = FT_ENCODING_NONE;
+              /* initial platform/encoding should indicate unset status? */
+              charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
+              charmap.encoding_id = TT_APPLE_ID_DEFAULT;
+
+              if ( unicode_charmap )
+              {
+                charmap.encoding    = FT_ENCODING_UNICODE;
+                charmap.platform_id = TT_PLATFORM_MICROSOFT;
+                charmap.encoding_id = TT_MS_ID_UNICODE_CS;
+              }
+
+              error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
+            }
+
+            goto Exit;
+          }
+        }
+
+        /* otherwise assume Adobe standard encoding */
+
+        {
+          FT_CharMapRec  charmap;
+
+
+          charmap.face        = FT_FACE( face );
+          charmap.encoding    = FT_ENCODING_ADOBE_STANDARD;
+          charmap.platform_id = TT_PLATFORM_ADOBE;
+          charmap.encoding_id = TT_ADOBE_ID_STANDARD;
+
+          error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL );
+
+          /* Select default charmap */
+          if ( bdfface->num_charmaps )
+            bdfface->charmap = bdfface->charmaps[0];
+        }
+      }
+    }
+
+  Exit:
+    return error;
+
+  Fail:
+    BDF_Face_Done( bdfface );
+    return FT_THROW( Unknown_File_Format );
   }
 
+/***************************************************************************************************************************/
+
+    FNT_Face   face   = (FNT_Face)fntface;
+    FT_Error   error;
+    FT_Memory  memory = FT_FACE_MEMORY( face );
+    FT_Int     face_index;
+
+    FT_UNUSED( num_params );
+    FT_UNUSED( params );
+
+
+    FT_TRACE2(( "Windows FNT driver\n" ));
+
+    face_index = FT_ABS( face_instance_index ) & 0xFFFF;
+
+    /* try to load font from a DLL */
+    error = fnt_face_get_dll_font( face, face_instance_index );
+    if ( !error && face_instance_index < 0 )
+      goto Exit;
+
+    if ( FT_ERR_EQ( error, Unknown_File_Format ) )
+    {
+      /* this didn't work; try to load a single FNT font */
+      FNT_Font  font;
+
+      if ( FT_NEW( face->font ) )
+        goto Exit;
+
+      fntface->num_faces = 1;
+
+      font           = face->font;
+      font->offset   = 0;
+      font->fnt_size = stream->size;
+
+      error = fnt_font_load( font, stream );
+
+      if ( !error )
+      {
+        if ( face_instance_index < 0 )
+          goto Exit;
+
+        if ( face_index > 0 )
+          error = FT_THROW( Invalid_Argument );
+      }
+    }
+
+    if ( error )
+      goto Fail;
+
+    /* sanity check */
+    if ( !face->font->header.pixel_height )
+    {
+      FT_TRACE2(( "invalid pixel height\n" ));
+      error = FT_THROW( Invalid_File_Format );
+      goto Fail;
+    }
+
+    /* we now need to fill the root FT_Face fields */
+    /* with relevant information                   */
+    {
+      FT_Face   root = FT_FACE( face );
+      FNT_Font  font = face->font;
+      FT_ULong  family_size;
+
+
+      root->face_index = face_index;
+
+      root->face_flags |= FT_FACE_FLAG_FIXED_SIZES |
+                          FT_FACE_FLAG_HORIZONTAL;
+
+      if ( font->header.avg_width == font->header.max_width )
+        root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH;
+
+      if ( font->header.italic )
+        root->style_flags |= FT_STYLE_FLAG_ITALIC;
+
+      if ( font->header.weight >= 800 )
+        root->style_flags |= FT_STYLE_FLAG_BOLD;
+
+      /* set up the `fixed_sizes' array */
+      if ( FT_NEW_ARRAY( root->available_sizes, 1 ) )
+        goto Fail;
+
+      root->num_fixed_sizes = 1;
+
+      {
+        FT_Bitmap_Size*  bsize = root->available_sizes;
+        FT_UShort        x_res, y_res;
+
+
+        bsize->width  = (FT_Short)font->header.avg_width;
+        bsize->height = (FT_Short)( font->header.pixel_height +
+                                    font->header.external_leading );
+        bsize->size   = font->header.nominal_point_size << 6;
+
+        x_res = font->header.horizontal_resolution;
+        if ( !x_res )
+          x_res = 72;
+
+        y_res = font->header.vertical_resolution;
+        if ( !y_res )
+          y_res = 72;
+
+        bsize->y_ppem = FT_MulDiv( bsize->size, y_res, 72 );
+        bsize->y_ppem = FT_PIX_ROUND( bsize->y_ppem );
+
+        /*
+         * this reads:
+         *
+         * the nominal height is larger than the bbox's height
+         *
+         * => nominal_point_size contains incorrect value;
+         *    use pixel_height as the nominal height
+         */
+        if ( bsize->y_ppem > ( font->header.pixel_height << 6 ) )
+        {
+          FT_TRACE2(( "use pixel_height as the nominal height\n" ));
+
+          bsize->y_ppem = font->header.pixel_height << 6;
+          bsize->size   = FT_MulDiv( bsize->y_ppem, 72, y_res );
+        }
+
+        bsize->x_ppem = FT_MulDiv( bsize->size, x_res, 72 );
+        bsize->x_ppem = FT_PIX_ROUND( bsize->x_ppem );
+      }
+
+      {
+        FT_CharMapRec  charmap;
+
+
+        charmap.encoding    = FT_ENCODING_NONE;
+        /* initial platform/encoding should indicate unset status? */
+        charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
+        charmap.encoding_id = TT_APPLE_ID_DEFAULT;
+        charmap.face        = root;
+
+        if ( font->header.charset == FT_WinFNT_ID_MAC )
+        {
+          charmap.encoding    = FT_ENCODING_APPLE_ROMAN;
+          charmap.platform_id = TT_PLATFORM_MACINTOSH;
+/*        charmap.encoding_id = TT_MAC_ID_ROMAN; */
+        }
+
+        error = FT_CMap_New( fnt_cmap_class,
+                             NULL,
+                             &charmap,
+                             NULL );
+        if ( error )
+          goto Fail;
+      }
+
+      /* set up remaining flags */
+
+      if ( font->header.last_char < font->header.first_char )
+      {
+        FT_TRACE2(( "invalid number of glyphs\n" ));
+        error = FT_THROW( Invalid_File_Format );
+        goto Fail;
+      }
+
+      /* reserve one slot for the .notdef glyph at index 0 */
+      root->num_glyphs = font->header.last_char -
+                         font->header.first_char + 1 + 1;
+
+      if ( font->header.face_name_offset >= font->header.file_size )
+      {
+        FT_TRACE2(( "invalid family name offset\n" ));
+        error = FT_THROW( Invalid_File_Format );
+        goto Fail;
+      }
+      family_size = font->header.file_size - font->header.face_name_offset;
+      /* Some broken fonts don't delimit the face name with a final */
+      /* NULL byte -- the frame is erroneously one byte too small.  */
+      /* We thus allocate one more byte, setting it explicitly to   */
+      /* zero.                                                      */
+      if ( FT_ALLOC( font->family_name, family_size + 1 ) )
+        goto Fail;
+
+      FT_MEM_COPY( font->family_name,
+                   font->fnt_frame + font->header.face_name_offset,
+                   family_size );
+
+      font->family_name[family_size] = '\0';
+
+      if ( FT_REALLOC( font->family_name,
+                       family_size,
+                       ft_strlen( font->family_name ) + 1 ) )
+        goto Fail;
+
+      root->family_name = font->family_name;
+      root->style_name  = (char *)"Regular";
+
+      if ( root->style_flags & FT_STYLE_FLAG_BOLD )
+      {
+        if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
+          root->style_name = (char *)"Bold Italic";
+        else
+          root->style_name = (char *)"Bold";
+      }
+      else if ( root->style_flags & FT_STYLE_FLAG_ITALIC )
+        root->style_name = (char *)"Italic";
+    }
+    goto Exit;
+
+  Fail:
+    FNT_Face_Done( fntface );
+
+  Exit:
+    return error;
+  }
+
+/*****************************************************************************************************************************/
 
   FT_CALLBACK_DEF( FT_Error )
   GF_Size_Request(  FT_Size          size,
                     FT_Size_Request  req )
   {
-               //TO-DO
+               FNT_Face          face    = (FNT_Face)size->face;
+    FT_WinFNT_Header  header  = &face->font->header;
+    FT_Bitmap_Size*   bsize   = size->face->available_sizes;
+    FT_Error          error   = FT_ERR( Invalid_Pixel_Size );
+    FT_Long           height;
+
+
+    height = FT_REQUEST_HEIGHT( req );
+    height = ( height + 32 ) >> 6;
+
+    switch ( req->type )
+    {
+    case FT_SIZE_REQUEST_TYPE_NOMINAL:
+      if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) )
+        error = FT_Err_Ok;
+      break;
+
+    case FT_SIZE_REQUEST_TYPE_REAL_DIM:
+      if ( height == header->pixel_height )
+        error = FT_Err_Ok;
+      break;
+
+    default:
+      error = FT_THROW( Unimplemented_Feature );
+      break;
+    }
+
+    if ( error )
+      return error;
+    else
+      return FNT_Size_Select( size, 0 );
   }
 
 
diff --git a/src/gf/gfdrivr.h b/src/gf/gfdrivr.h
index 64d5784..40066c5 100644
--- a/src/gf/gfdrivr.h
+++ b/src/gf/gfdrivr.h
@@ -27,25 +27,25 @@
 
 FT_BEGIN_HEADER
 
-       /* BitmapRec for GF format specific glyphs  */
-       typedef struct GF_BitmapRec_ 
-       {
-               int              bbx_width, bbx_height;   
-               int              off_x, off_y;            
-               int              mv_x,  mv_y;            
-               unsigned char    *bitmap;
-               int              raster;
-       } GF_BitmapRec, *GF_Bitmap;
+  /* BitmapRec for GF format specific glyphs  */
+  typedef struct GF_BitmapRec_ 
+  {
+    int              bbx_width, bbx_height;   
+    int              off_x, off_y;            
+    int              mv_x,  mv_y;            
+    unsigned char    *bitmap;
+    int              raster;
+  } GF_BitmapRec, *GF_Bitmap;
        
 
-       typedef struct GF_Glyph_ 
-       {
-               int         code_min, code_max; 
-               VF_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;
+  typedef struct GF_Glyph_ 
+  {
+    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;
 
 
   typedef struct  GF_FaceRec_
diff --git a/src/gf/gflib.c b/src/gf/gflib.c
index 78b9c02..d3e4691 100644
--- a/src/gf/gflib.c
+++ b/src/gf/gflib.c
@@ -42,9 +42,9 @@
   /*                                                                       */
   /*************************************************************************/
 
-       long           gf_read_intn(FILE*,int); 
-       unsigned long  gf_read_uintn(FILE*,int);
-       void           gf_skip_n(FILE*,int);
+  long           gf_read_intn(FILE*,int);      
+  unsigned long  gf_read_uintn(FILE*,int);
+  void           gf_skip_n(FILE*,int);
 
 #define READ_INT1(fp)    (INT1)gf_read_intn((fp), 1)
 #define READ_UINT1(fp)   (UINT1)gf_read_uintn((fp), 1)
@@ -62,81 +62,82 @@
 /*
  * Reading a Number from file
  */
-       unsigned long
-       gf_read_uintn(FILE* fp, int size)
-       {
-               unsigned long  v;
-
-               v = 0L;
-               while (size >= 1)
-               {
-                 v = v*256L + (unsigned long)getc(fp);
-                 --size;
-               }
-               return v;
-       }
-
-       long
-       gf_read_intn(FILE* fp, int size)
-       {
-               long           v;
-
-               v = (long)getc(fp) & 0xffL;
-               if (v & 0x80L)
-                 v = v - 256L;
-               --size;
-               while (size >= 1){
-                 v = v*256L + (unsigned long)getc(fp);
-                 --size;
+  unsigned long
+  gf_read_uintn(FILE* fp, int size)
+  {
+    unsigned long  v;
+
+    v = 0L;
+    while (size >= 1)
+    {
+      v = v*256L + (unsigned long)getc(fp);
+      --size;
+    }
+    return v;
+  }
+
+  long
+  gf_read_intn(FILE* fp, int size)
+  {
+    long           v;
+
+    v = (long)getc(fp) & 0xffL;
+    if (v & 0x80L)
+      v = v - 256L;
+    --size;
+    while (size >= 1)
+    {
+      v = v*256L + (unsigned long)getc(fp);
+      --size;
                }
 
-               return v;
-       }
+    return v;
+  }
 
   void
-       gf_skip_n(FILE* fp, int size)
-       {
-               
-               while (size > 0)
-               {
-                 (void)getc(fp);
-                 --size;
-               }
-               
-       }
-
-       unsigned long
-       gf_get_uintn(unsigned char *p, int size)
-       {
-               unsigned long  v;
-
-               v = 0L;
-               while (size >= 1)
-               {
-                 v = v*256L + (unsigned long) *(p++);
-                 --size;
-               }
+  gf_skip_n(FILE* fp, int size)
+  {
+       
+    while (size > 0)
+    {
+      (void)getc(fp);
+      --size;
+    }
+    
+  }
 
-       return v;
-       }
-
-       long
-       gf_get_intn(unsigned char *p, int size)
-       {
-               long           v;
-
-               v = (long)*(p++) & 0xffL;
-               if (v & 0x80L)
-                 v = v - 256L;
-               --size;
-               while (size >= 1)
-               {
-                 v = v*256L + (unsigned long) *(p++);
-                 --size;
-               }
+  unsigned long
+  gf_get_uintn(unsigned char *p, int size)
+  {
+    unsigned long  v;
 
-               return v;
-       }
+    v = 0L;
+    while (size >= 1)
+    {
+      v = v*256L + (unsigned long) *(p++);
+      --size;
+    }
+
+    return v;
+  }
+
+  long
+  gf_get_intn(unsigned char *p, int size)
+  {
+    long           v;
+
+    v = (long)*(p++) & 0xffL;
+    if (v & 0x80L)
+      v = v - 256L;
+    --size;
+    while (size >= 1)
+    {
+      v = v*256L + (unsigned long) *(p++);
+      --size;
+    }
+
+    return v;
+  }
 
 
 
@@ -147,351 +148,360 @@
   /*************************************************************************/
 
   FT_LOCAL_DEF( FT_Error )
-       gf_read_glyph(FT_FILE* fp, GF_BITMAP bm)
-       {
-               long           m, n;
-               int            paint_sw;
-               int            instr;
-               INT4           min_m, max_m, min_n, max_n, del_m, del_n;
-               long           w, h, d;
-               int            m_b, k;
-               unsigned char  *ptr;
-
-               switch (READ_UINT1(fp))
-               {
-                       case GF_BOC:
-                               SKIP_N(fp, 4);
-                               SKIP_N(fp, 4);
-                               min_m = READ_INT4(fp);
-                               max_m = READ_INT4(fp);
-                               min_n = READ_INT4(fp);
-                               max_n = READ_INT4(fp);
-                               break;
-                       case GF_BOC1:
-                               SKIP_N(fp, 1);
-                               del_m = (INT4)READ_UINT1(fp);
-                               max_m = (INT4)READ_UINT1(fp);
-                               del_n = (INT4)READ_UINT1(fp);
-                               max_n = (INT4)READ_UINT1(fp);
-                               min_m = max_m - del_m;
-                               min_n = max_n - del_n;
-                               break;
-                       default:
-                               return -1;
-               }
-
-               w = max_m - min_m + 1;
-               h = max_n - min_n + 1;
-               if ((w < 0) || (h < 0))
-               {
-                 vf_error = VF_ERR_ILL_FONT_FILE;
-                 return -1;
-               }
-
-               if ((bm->bitmap = (unsigned char*)malloc(h*((w+7)/8))) == NULL)
-               {
-                 vf_error = VF_ERR_NO_MEMORY;
-                 return -1;
-               }
+  gf_read_glyph(FT_FILE* fp, GF_BITMAP bm)
+  {
+    long           m, n;
+    int            paint_sw;
+    int            instr;
+    INT4           min_m, max_m, min_n, max_n, del_m, del_n;
+    long           w, h, d;
+    int            m_b, k;
+    unsigned char  *ptr;
+
+    switch (READ_UINT1(fp))
+    {
+      case GF_BOC:
+        SKIP_N(fp, 4);
+        SKIP_N(fp, 4);
+        min_m = READ_INT4(fp);
+        max_m = READ_INT4(fp);
+        min_n = READ_INT4(fp);
+        max_n = READ_INT4(fp);
+        break;
+      case GF_BOC1:
+        SKIP_N(fp, 1);
+        del_m = (INT4)READ_UINT1(fp);
+        max_m = (INT4)READ_UINT1(fp);
+        del_n = (INT4)READ_UINT1(fp);
+        max_n = (INT4)READ_UINT1(fp);
+        min_m = max_m - del_m;
+        min_n = max_n - del_n;
+        break;
+      default:
+        return -1;
+    }
+
+    w = max_m - min_m + 1;
+    h = max_n - min_n + 1;
+    if ((w < 0) || (h < 0))
+    {
+      vf_error = VF_ERR_ILL_FONT_FILE;
+      return -1;
+    }
+
+    if ((bm->bitmap = (unsigned char*)malloc(h*((w+7)/8))) == NULL)
+    {
+      vf_error = VF_ERR_NO_MEMORY;
+      return -1;
+    }
                
-               memclr(bm->bitmap, h*((w+7)/8));
-               bm->raster     = (w+7)/8;
-               bm->bbx_width  = w;
-               bm->bbx_height = h;
-               bm->off_x      = -min_m;
-               bm->off_y      = max_n;
-       #if 0
-               bm->mv_x       = -min_m;
-               bm->mv_y       = max_n;
-       #endif
-
-               m        = min_m;
-               n        = max_n;
-               paint_sw = 0;
-               while ((instr = (int)READ_UINT1(fp)) != GF_EOC)
-               {
-                 if (instr == GF_PAINT_0)
-                 {
-                   paint_sw = 1 - paint_sw;
-                 } 
-                 else if ((GF_NEW_ROW_0 <= instr) && (instr <= GF_NEW_ROW_164))
-                 {
-                   m        = min_m + (instr - GF_NEW_ROW_0);
-                   n        = n - 1;
-                   paint_sw = 1;
-                 } 
-                 else if ((GF_PAINT_1 <= instr) && (instr <= GF_PAINT_63))
-                 {
-                   d = (instr - GF_PAINT_1 + 1);
-                   goto Paint;
-                 } 
-                 else 
-                 {
-                   switch ((int)instr)
-                   {
-                                 case GF_PAINT1:
-                                 case GF_PAINT2:
-                                 case GF_PAINT3:
-                                       d = (UINT4)READ_UINTN(fp, (instr - 
GF_PAINT1 + 1));
-                                       Paint:
-                                       if (paint_sw == 0)
-                                       {
-                                               m = m + d;
-                                       } 
-                                       else 
-                                       {
-                                               ptr = &bm->bitmap[(max_n - n) * 
bm->raster + (m - min_m)/8];
-                                               m_b = (m - min_m) % 8;
-                                               while (d > 0)
-                                               {
-                                               *ptr |= bit_table[m_b];
-                                               m++;
-                                               if (++m_b >= 8)
-                                               {
-                                                               m_b = 0;
-                                                               ++ptr;
-                                                       }
-                                               d--;
-                                               }
-                                       }
-                                       paint_sw = 1 - paint_sw;
-                                       break;
+    memclr(bm->bitmap, h*((w+7)/8));
+    bm->raster     = (w+7)/8;
+    bm->bbx_width  = w;
+    bm->bbx_height = h;
+    bm->off_x      = -min_m;
+    bm->off_y      = max_n;
+    #if 0
+      bm->mv_x       = -min_m;
+      bm->mv_y       = max_n;
+    #endif
+
+    m        = min_m;
+    n        = max_n;
+    paint_sw = 0;
+    while ((instr = (int)READ_UINT1(fp)) != GF_EOC)
+    {
+      if (instr == GF_PAINT_0)
+      {
+        paint_sw = 1 - paint_sw;
+      } 
+      else if ((GF_NEW_ROW_0 <= instr) && (instr <= GF_NEW_ROW_164))
+      {
+        m        = min_m + (instr - GF_NEW_ROW_0);
+        n        = n - 1;
+        paint_sw = 1;
+      } 
+      else if ((GF_PAINT_1 <= instr) && (instr <= GF_PAINT_63))
+      {
+        d = (instr - GF_PAINT_1 + 1);
+        goto Paint;
+      } 
+      else 
+      {
+        switch ((int)instr)
+        {
+          case GF_PAINT1:
+          case GF_PAINT2:
+          case GF_PAINT3:
+          d = (UINT4)READ_UINTN(fp, (instr - GF_PAINT1 + 1));
+          Paint:
+          if (paint_sw == 0)
+          {
+            m = m + d; 
+          } 
+          else 
+          {
+            ptr = &bm->bitmap[(max_n - n) * bm->raster + (m - min_m)/8];
+            m_b = (m - min_m) % 8;
+            while (d > 0)
+            {
+              *ptr |= bit_table[m_b];
+              m++;
+              if (++m_b >= 8)
+              {
+                m_b = 0; 
+                ++ptr;
+              }
+              d--;
+            }
+          }
+          paint_sw = 1 - paint_sw;
+          break;
                                        
-                       case GF_SKIP0:
-                                       m = min_m;
-                                       n = n - 1;
-                                       paint_sw = 0;
-                                       break;
+                                       case GF_SKIP0:
+          m = min_m;
+          n = n - 1;
+          paint_sw = 0;
+          break;
                                        
-                                       case GF_SKIP1:
-                                       case GF_SKIP2:
-                                       case GF_SKIP3:
-                                       m = min_m;
-                                       n = n - (UINT4)READ_UINTN(fp, (instr - 
GF_SKIP1 + 1)) - 1;
-                                       paint_sw = 0;
-                                       break;
+          case GF_SKIP1:
+          case GF_SKIP2:
+          case GF_SKIP3:
+          m = min_m;
+          n = n - (UINT4)READ_UINTN(fp, (instr - GF_SKIP1 + 1)) - 1;
+          paint_sw = 0;
+          break;
                                        
-                                       case GF_XXX1:
-                                       case GF_XXX2:
-                                       case GF_XXX3:
-                                       case GF_XXX4:
-                                       k = READ_UINTN(fp, instr - GF_XXX1 + 1);
-                                       SKIP_N(fp, k);
-                                       break;
+          case GF_XXX1:
+          case GF_XXX2:
+          case GF_XXX3:
+          case GF_XXX4:
+          k = READ_UINTN(fp, instr - GF_XXX1 + 1);
+          SKIP_N(fp, k);
+          break;
                                        
-                                       case GF_YYY:
-                                       SKIP_N(fp, 4);
-                                       break;
+          case GF_YYY:
+          SKIP_N(fp, 4);
+          break;
                                        
-                                       case GF_NO_OP:
-                                       break;
+          case GF_NO_OP:
+          break;
                                                        
-                                       default:
-                                       vf_free(bm->bitmap);
-                                       bm->bitmap = NULL;
-                                       vf_error = VF_ERR_ILL_FONT_FILE;
-                                       return -1;
-                               }
-                       }
-               }
-
-               return 0;
-       }
+          default:
+          vf_free(bm->bitmap);
+          bm->bitmap = NULL;
+          vf_error = VF_ERR_ILL_FONT_FILE;
+          return -1;
+         }
+      }
+    }
+
+    return 0; 
+  }
 
 
   FT_LOCAL_DEF( FT_Error )
   gf_load_font(  FT_Stream       stream,
                  GF_Face         face  )
   {
-               GF_GLYPH    go;
-       GF_BITMAP   bm;
-       UINT1       instr, d;
-               UINT4       ds, check_sum, hppp, vppp;
-               INT4        min_m, max_m, min_n, max_n;
-               INT4        w;
-               UINT4       code;
-               double      dx, dy;
-               long        ptr_post, ptr_p, ptr, optr, gptr;
-               int         bc, ec, nchars, i;
-               FT_FILE *fp = stream->descriptor.pointer
-               go = NULL;
-               nchars = -1;
-
-               /* seek to post_post instr. */
-               ft_fseek(fp, -1, SEEK_END);
+    GF_GLYPH    go;
+    GF_BITMAP   bm;
+    UINT1       instr, d;
+    UINT4       ds, check_sum, hppp, vppp;
+    INT4        min_m, max_m, min_n, max_n;
+    INT4        w;
+    UINT4       code;
+    double      dx, dy;
+    long        ptr_post, ptr_p, ptr, optr, gptr;
+    int         bc, ec, nchars, i;
+    FT_FILE *fp = stream->descriptor.pointer
+    go = NULL;
+    nchars = -1;
+
+    /* seek to post_post instr. */
+    ft_fseek(fp, -1, SEEK_END);
                
-               while ((d = READ_UINT1(fp)) == 223)
-                       fseek(fp, -2, SEEK_CUR);
+    while ((d = READ_UINT1(fp)) == 223)
+      fseek(fp, -2, SEEK_CUR);
                
-               if (d != GF_ID)
-               {
-                 vf_error = VF_ERR_ILL_FONT_FILE;
-                 goto ErrExit;
-               }
+    if (d != GF_ID)
+    {
+      vf_error = VF_ERR_ILL_FONT_FILE;
+      goto ErrExit;
+    }
                
-               fseek(fp, -6, SEEK_CUR);
-
-               /* check if the code is post_post */
-               if (READ_UINT1(fp) != GF_POST_POST)
-               {
-                 vf_error = VF_ERR_ILL_FONT_FILE;
-                 goto ErrExit;
-               }
-
-               /* read pointer to post instr. */
-               if ((ptr_post = READ_UINT4(fp)) == -1)
-               {
-                 vf_error = VF_ERR_ILL_FONT_FILE;
-                 goto ErrExit;
-               }
-
-               /* goto post instr. and read it */
-               fseek(fp, ptr_post, SEEK_SET);
-               if (READ_UINT1(fp) != GF_POST)
-               {
-                 vf_error = VF_ERR_ILL_FONT_FILE;
-                 goto ErrExit;
-               }
+    fseek(fp, -6, SEEK_CUR);
+
+    /* check if the code is post_post */
+    if (READ_UINT1(fp) != GF_POST_POST)
+    {
+      vf_error = VF_ERR_ILL_FONT_FILE;
+      goto ErrExit;
+    }
+
+    /* read pointer to post instr. */
+    if ((ptr_post = READ_UINT4(fp)) == -1)
+    {
+      vf_error = VF_ERR_ILL_FONT_FILE;
+      goto ErrExit;
+    }
+
+    /* goto post instr. and read it */
+    fseek(fp, ptr_post, SEEK_SET);
+    if (READ_UINT1(fp) != GF_POST)
+    {
+      vf_error = VF_ERR_ILL_FONT_FILE;
+      goto ErrExit;
+    }
                
-               ptr_p     = READ_UINT4(fp);
-               ds        = READ_UINT4(fp);
-               check_sum = READ_UINT4(fp);
-               hppp      = READ_UINT4(fp);
-               vppp      = READ_UINT4(fp);
-               min_m     = READ_INT4(fp);
-               max_m     = READ_INT4(fp);
-               min_n     = READ_INT4(fp);
-               max_n     = READ_INT4(fp);
-
-               gptr = ftell(fp);
-
-       #if 0
-               /* read min & max char code */
-               bc = 256;
-               ec = -1;
-               for (;;){
-                 instr = READ_UINT1(fp);
-                 if (instr == GF_POST_POST){
-                   break;
-                 } else if (instr == GF_CHAR_LOC){
-                   code = READ_UINT1(fp);
-                   (void)SKIP_N(fp, 16);
-                 } else if (instr == GF_CHAR_LOC0){
-                   code = READ_UINT1(fp);
-                   (void)SKIP_N(fp, 9);
-                 } else {
-                   vf_error = VF_ERR_ILL_FONT_FILE;
-                   goto ErrExit;
-                 }
-                 if (code < bc)
-                   bc = code;
-                 if (code > ec)
-                   ec = code;
-               }
-       #else
-               bc = 0;
-               ec = 255;
-       #endif
+    ptr_p     = READ_UINT4(fp);
+    ds        = READ_UINT4(fp);
+    check_sum = READ_UINT4(fp);
+    hppp      = READ_UINT4(fp);
+    vppp      = READ_UINT4(fp);
+    min_m     = READ_INT4(fp);
+    max_m     = READ_INT4(fp);
+    min_n     = READ_INT4(fp);
+    max_n     = READ_INT4(fp);
+
+    gptr = ftell(fp);
+
+
+    #if 0
+      /* read min & max char code */
+      bc = 256;
+      ec = -1;
+      for (  ;  ;  )
+      {
+        instr = READ_UINT1(fp);
+        if (instr == GF_POST_POST)
+        {
+          break;
+        } 
+        else if (instr == GF_CHAR_LOC)
+        {
+          code = READ_UINT1(fp);
+          (void)SKIP_N(fp, 16);
+        } 
+        else if (instr == GF_CHAR_LOC0)
+        {
+          code = READ_UINT1(fp);
+          (void)SKIP_N(fp, 9);
+        } 
+        else 
+        {
+          vf_error = VF_ERR_ILL_FONT_FILE;
+          goto ErrExit;
+        }
+        if (code < bc)
+          bc = code;
+        if (code > ec)
+          ec = code;
+      }
+    #else
+                 bc = 0;
+                 ec = 255;
+    #endif
 
                nchars = ec - bc + 1;
-               ALLOC_IF_ERR(go, struct s_gf_glyph)
-               {
-                 vf_error = VF_ERR_NO_MEMORY;
-                 goto ErrExit;
-               }
-               ALLOCN_IF_ERR(go->bm_table, struct vf_s_bitmap, nchars)
-               {
-                 vf_error = VF_ERR_NO_MEMORY;
-                 goto ErrExit;
-               }
-
-               for (i = 0; i < nchars; i++)
-                       go->bm_table[i].bitmap = NULL;
+    ALLOC_IF_ERR(go, struct s_gf_glyph)
+    {
+      vf_error = VF_ERR_NO_MEMORY;
+      goto ErrExit;
+    }
+    ALLOCN_IF_ERR(go->bm_table, struct vf_s_bitmap, nchars)
+    {
+      vf_error = VF_ERR_NO_MEMORY;
+      goto ErrExit;
+    }
+
+    for (i = 0; i < nchars; i++)
+      go->bm_table[i].bitmap = NULL;
                  
-               go->ds   = (double)ds/(1<<20);
-               go->hppp = (double)hppp/(1<<16);
-               go->vppp = (double)vppp/(1<<16);
-               go->font_bbx_w = max_m - min_m;
-               go->font_bbx_h = max_n - min_n;
-               go->font_bbx_xoff = min_m;
-               go->font_bbx_yoff = min_n;
-               go->code_min = bc;
-               go->code_max = ec;
-
-               /* read glyph */
-       #if 0
-               fseek(fp, gptr, SEEK_SET);
-       #endif
-               for (;;)
-               {
-                 if ((instr = READ_UINT1(fp)) == GF_POST_POST)
-                   break;
-                 switch ((int)instr)
-                 {
+    go->ds   = (double)ds/(1<<20);
+    go->hppp = (double)hppp/(1<<16);
+    go->vppp = (double)vppp/(1<<16);
+    go->font_bbx_w = max_m - min_m;
+    go->font_bbx_h = max_n - min_n;
+    go->font_bbx_xoff = min_m;
+    go->font_bbx_yoff = min_n;
+    go->code_min = bc;
+    go->code_max = ec;
+
+    /* read glyph */
+    #if 0
+      fseek(fp, gptr, SEEK_SET);
+    #endif
+    for (  ;  ;  )
+    {
+      if ((instr = READ_UINT1(fp)) == GF_POST_POST)
+        break;
+      switch ((int)instr)
+      {
                  
-                 case GF_CHAR_LOC:
-                   code = READ_UINT1(fp);
-                   dx   = (double)READ_INT4(fp)/(double)(1<<16);
-                   dy   = (double)READ_INT4(fp)/(double)(1<<16);
-                   w    = READ_INT4(fp);
-                   ptr  = READ_INT4(fp);
-                   break;
+        case GF_CHAR_LOC:
+          code = READ_UINT1(fp);
+          dx   = (double)READ_INT4(fp)/(double)(1<<16);
+          dy   = (double)READ_INT4(fp)/(double)(1<<16);
+          w    = READ_INT4(fp);
+          ptr  = READ_INT4(fp);
+          break;
                    
-                 case GF_CHAR_LOC0:
-                   code = READ_UINT1(fp);
-                   dx   = (double)READ_INT1(fp);
-                   dy   = (double)0;
-                   w    = READ_INT4(fp);
-                   ptr  = READ_INT4(fp);
-                   break;
+        case GF_CHAR_LOC0:
+          code = READ_UINT1(fp);
+          dx   = (double)READ_INT1(fp);
+          dy   = (double)0;
+          w    = READ_INT4(fp);
+          ptr  = READ_INT4(fp);
+          break;
                    
-                 default:
-                   vf_error = VF_ERR_ILL_FONT_FILE;
-                   goto ErrExit;
+        default:
+          vf_error = VF_ERR_ILL_FONT_FILE;
+          goto ErrExit;
                    
-                 }
-                 optr = ftell(fp);
-                 fseek(fp, ptr, SEEK_SET);
+      }
+      optr = ftell(fp);
+      fseek(fp, ptr, SEEK_SET);
                  
-                 bm = &go->bm_table[code - bc];
-                 if (gf_read_glyph(fp, bm) < 0)
-                   goto ErrExit;
+      bm = &go->bm_table[code - bc];
+      if (gf_read_glyph(fp, bm) < 0)
+        goto ErrExit;
                    
-                 bm->mv_x = dx;
-                 bm->mv_y = dy;
-                 fseek(fp, optr, SEEK_SET);
-               }
-               return go;
+      bm->mv_x = dx;
+      bm->mv_y = dy;
+      fseek(fp, optr, SEEK_SET);
+    }
+    return go;
                
-       ErrExit:
-       printf("*ERROR\n");
-               if (go != NULL)
-               {
-                 if (go->bm_table != NULL)
-                 {
-                   for (i = 0; i < nchars; i++)
-                                       vf_free(go->bm_table[i].bitmap);
-                 }
-                 vf_free(go->bm_table);
-               }
-               vf_free(go);
-               return NULL;
-       }
+               ErrExit:
+      printf("*ERROR\n");
+      if (go != NULL)
+      {
+        if (go->bm_table != NULL)
+        {
+          for (i = 0; i < nchars; i++)
+            vf_free(go->bm_table[i].bitmap);
+        }
+        vf_free(go->bm_table);
+      }
+      vf_free(go);
+      return NULL;
+  }
 
 
   FT_LOCAL_DEF( void )
   gf_free_font( GF_Glyph  gf_glyph )
   {
-               if (go != NULL)
-               {
-                 if (go->bm_table != NULL)
-                 {
-                   for (i = 0; i < nchars; i++)
-                                       vf_free(go->bm_table[i].bitmap);
-                 }
-                 vf_free(go->bm_table);
-               }
-               vf_free(go);
+    if (go != NULL)
+    {
+      if (go->bm_table != NULL)
+      {
+        for (i = 0; i < nchars; i++)
+          vf_free(go->bm_table[i].bitmap);
+      }
+      vf_free(go->bm_table);
+    }
+    vf_free(go);
   }
 
 



reply via email to

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