shithub: freetype+ttf2subf

Download patch

ref: ebf5585dd09c44c8bb94d955c28c85e4952045de
parent: 5d02b8a1513e4e234bf270ab13df1898403e0607
author: Werner Lemberg <[email protected]>
date: Tue Mar 15 20:49:54 EST 2005

Formatting.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,25 +1,48 @@
 2005-03-15  David Turner  <[email protected]>
 
-    * src/bdf/bdflib.c: removing compiler warnings
+	* src/bdf/bdflib.c: Remove compiler warnings.
+	(hash_rehash, hash_init): Don't call FT_MEM_ZERO.
+	(_bdf_list_t): Add `memory' field.
+	(_bdf_list_init, _bdf_list_done, _bdf_list_ensure): New functions.
+	(_bdf_shift, _bdf_join): Rename to...
+	(_bdf_list_shift, _bdf_list_join): This.
+	(_bdf_split): Renamed to...
+	(_bdf_list_split): This.  Use new functions.
+	(bdf_internal_readstream): Removed.
+	(NO_SKIP): New macro.
+	(_bdf_readstream): Rewritten.
+	(bdf_create_property, _bdf_add_comment): Improve allocation.
+	(_bdf_set_default_spacing, _bdf_parse_glyphs): Updated.  Improve
+	allocation.
+	(_bdf_parse_properties, _bdf_parse_start): Updated.
+	(bdf_load_font): Updated to use new functions.
 
-    * docs/CHANGES: updating
-    
-    * src/type1/t1parse.c (T1_New_Parser), src/type42/t42parse.c
-    (t42_parser_init): modifying functions to check the font header before
-    allocating anything on the heap.
+	* src/type1/t1parse.c (check_type1_format): New function.
+	(T1_New_Parser): Use it to check font header before allocating
+	anything on the heap.
 
-    * internal/freetype/ftmemory.h: introducing the new macros FT_ARRAY_MAX
-    and FT_ARRAY_CHECK
-    
-    * src/pcf/pcfread.c, src/pcf/pcfutil.c: minor fixes and simplifications.
-    try to protect the PCF driver from doing stupid things with broken fonts.
+	* src/type42/t42parse.c	(t42_parser_init): Modify functions to check
+	the font header before allocating anything on the heap.
 
-    * src/lzw/ftlzw.c (FT_Stream_OpenLZW): modified the function to check
-    the LZW header before doing anything else. This helps avoid un-necessary
-    heap allocations (400 Kb of heap memory for the LZW decoder ! Oh my !)
+	* include/freetype/internal/ftmemory.h (FT_ARRAY_MAX,
+	FT_ARRAY_CHECK): New macros.
 
-    * src/gzip/ftgzip.c (FT_Stream_OpenGZip): ditto for the .gz decoder,
-    though the code savings is smaller.
+	* src/base/ftstream.c (FT_Stream_TryRead): New function.
+	* include/freetype/internal/ftstream.h: Updated.
+
+	* src/pcf/pcfread.c (pcf_read_TOC), src/pcf/pcfutil.c
+	(BitOrderInvert, TwoByteSwap, FourByteSwap): Minor fixes and
+	simplifications.  Try to protect the PCF driver from doing stupid
+	things with broken fonts.
+
+	* src/lzw/ftlzw.c (FT_Stream_OpenLZW): Check the LZW header before
+	doing anything else.  This avoids unnecessary heap allocations
+	(400KByte of heap memory for the LZW decoder).
+
+	* src/gzip/ftgzip.c (FT_Stream_OpenGZip): Ditto for the gzip
+	decoder, although the code savings are smaller.
+
+	* docs/CHANGES: Updated.
 
 2005-03-10  David Turner  <[email protected]>
 
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -19,28 +19,28 @@
 
     - FreeType didn't properly parse empty Type 1 glyphs.
     
-    - An unbounded dynamic buffer growth was fixed in the PFR loader
+    - An unbound dynamic buffer growth was fixed in the PFR loader.
     
-    - Several bugs were fixed in the cache sub-system.
+    - Several bugs have been fixed in the cache sub-system.
 
-    - Fixed bug #12263: incorrect behaviour when resizing to distinct but
-      very close character pixel sizes through FT_Set_Char_Size
+    - FreeType behaved incorrectly when resizing two distinct but very
+      close character pixel sizes through `FT_Set_Char_Size' (Savannah
+      bug #12263).
       
-    - The auto-hinter didn't work when a font didn't have a Unicode charmap.
-      it even refused to load the glyphs !
+    - The auto-hinter didn't work properly for fonts without a Unicode
+      charmap -- it even refused to load the glyphs.
 
 
   II. IMPORTANT CHANGES
 
-    - a LOT of work has been done in order to drastically reduce the
-      amount of heap memory used by FreeType, especially when using
-      memory-mapped font files (which is the default on Unix systems
-      which support them). This should be good news for any Unix distribution
-      upgrading to this release of the font engine.
+    - Many fixes have been applied to drastically reduce the amount of
+      heap   memory   used   by   FreeType,   especially   when  using
+      memory-mapped font files  (which is the default on Unix  systems
+      which support them).
 
-    - The auto-hinter has been completely rewritten as a new module,
-      called the 'auto-fitter'. The latter is the new default auto-hinting
-      module. It also consumes a lot less memory than its predecessor.
+    - The auto-hinter  has been completely rewritten  as a new module,
+      called the `auto-fitter',  which is now the default auto-hinting
+      module.  It consumes a lot less memory than its predecessor.
 
     - George Williams  contributed code to read  kerning data from PFM
       files.
@@ -63,6 +63,7 @@
       an FT_Bitmap structure in 1bpp, 2bpp, 4bpp, or 8bpp format  into
       another 8bpp FT_Bitmap, probably using a different pitch.
 
+
   III. MISCELLANEOUS
 
     - The BDF driver  no longer converts  all returned bitmaps  with a
@@ -86,6 +87,9 @@
       This saves about 16Kb per process linked to FreeType. We also store
       the array in a novel compressed way that saves about 20 Kb of code
       as well.
+
+
+======================================================================
 
 LATEST CHANGES BETWEEN 2.1.9 and 2.1.8
 
--- a/include/freetype/internal/ftmemory.h
+++ b/include/freetype/internal/ftmemory.h
@@ -270,13 +270,16 @@
 #define FT_ARRAY_MOVE( dest, source, count )                        \
           FT_MEM_MOVE( dest, source, (count) * sizeof ( *(dest) ) )
 
-/* return the maximum number of adressable elements in an array
- * we limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
- * any problems
- */
-#define FT_ARRAY_MAX( ptr )    (FT_INT_MAX/sizeof( *(ptr) ))
 
-#define FT_ARRAY_CHECK( ptr, count )   ( (count) <= FT_ARRAY_MAX(ptr) )
+  /*
+   *  Return the maximum number of adressable elements in an array.
+   *  We limit ourselves to INT_MAX, rather than UINT_MAX, to avoid
+   *  any problems.
+   */
+#define FT_ARRAY_MAX( ptr )           ( FT_INT_MAX / sizeof ( *(ptr) ) )
+
+#define FT_ARRAY_CHECK( ptr, count )  ( (count) <= FT_ARRAY_MAX( ptr ) )
+
 
   /*************************************************************************/
   /*                                                                       */
--- a/include/freetype/internal/ftstream.h
+++ b/include/freetype/internal/ftstream.h
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    Stream handling (specification).                                     */
 /*                                                                         */
-/*  Copyright 1996-2001, 2002, 2004 by                                     */
+/*  Copyright 1996-2001, 2002, 2004, 2005 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -385,9 +385,8 @@
                     FT_Byte*   buffer,
                     FT_ULong   count );
 
- /* try to read bytes at the end of a stream, return
-  * the number of bytes really available
-  */
+  /* try to read bytes at the end of a stream; return number of bytes */
+  /* really available                                                 */
   FT_BASE( FT_ULong )
   FT_Stream_TryRead( FT_Stream  stream,
                      FT_Byte*   buffer,
--- a/src/base/ftstream.c
+++ b/src/base/ftstream.c
@@ -4,7 +4,7 @@
 /*                                                                         */
 /*    I/O stream support (body).                                           */
 /*                                                                         */
-/*  Copyright 2000-2001, 2002, 2004 by                                     */
+/*  Copyright 2000-2001, 2002, 2004, 2005 by                               */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
--- a/src/bdf/bdflib.c
+++ b/src/bdf/bdflib.c
@@ -1,6 +1,6 @@
 /*
  * Copyright 2000 Computing Research Labs, New Mexico State University
- * Copyright 2001, 2002, 2003, 2004 Francesco Zappa Nardelli
+ * Copyright 2001, 2002, 2003, 2004, 2005 Francesco Zappa Nardelli
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -392,19 +392,21 @@
   _bdf_list_init( _bdf_list_t*  list,
                   FT_Memory     memory )
   {
-    FT_ZERO(list);
+    FT_ZERO( list );
     list->memory = memory;
   }
 
+
   static void
   _bdf_list_done( _bdf_list_t*  list )
   {
     FT_Memory  memory = list->memory;
 
+
     if ( memory )
     {
       FT_FREE( list->field );
-      FT_ZERO(list);
+      FT_ZERO( list );
     }
   }
 
@@ -413,18 +415,20 @@
   _bdf_list_ensure( _bdf_list_t*  list,
                     int           num_items )
   {
-    FT_Error  error = 0;
+    FT_Error  error = BDF_Err_Ok;
 
+
     if ( num_items > (int)list->size )
     {
-      int  oldsize = list->size;
-      int  newsize = oldsize + (oldsize >> 1) + 4;
-      int  bigsize = FT_INT_MAX / sizeof(char*);
+      int        oldsize = list->size;
+      int        newsize = oldsize + ( oldsize >> 1 ) + 4;
+      int        bigsize = FT_INT_MAX / sizeof ( char* );
       FT_Memory  memory  = list->memory;
 
+
       if ( oldsize == bigsize )
       {
-        error = FT_Err_Out_Of_Memory;
+        error = BDF_Err_Out_Of_Memory;
         goto Exit;
       }
       else if ( newsize < oldsize || newsize > bigsize )
@@ -435,6 +439,7 @@
 
       list->size = newsize;
     }
+
   Exit:
     return error;
   }
@@ -493,13 +498,11 @@
   }
 
 
-
   /* An empty string for empty fields. */
 
   static const char  empty[1] = { 0 };      /* XXX eliminate this */
 
 
-
   static FT_Error
   _bdf_list_split( _bdf_list_t*   list,
                    char*          separators,
@@ -553,7 +556,7 @@
       /* Resize the list if necessary. */
       if ( list->used == list->size )
       {
-        error = _bdf_list_ensure( list, list->used+1 );
+        error = _bdf_list_ensure( list, list->used + 1 );
         if ( error )
           goto Exit;
       }
@@ -582,7 +585,7 @@
     /* Finally, NULL-terminate the list. */
     if ( list->used + final_empty >= list->size )
     {
-      error = _bdf_list_ensure( list, list->used+final_empty+1 );
+      error = _bdf_list_ensure( list, list->used + final_empty + 1 );
       if ( error )
         goto Exit;
     }
@@ -597,9 +600,9 @@
   }
 
 
-
 #define NO_SKIP  256  /* this value cannot be stored in a 'char' */
 
+
   static FT_Error
   _bdf_readstream( FT_Stream         stream,
                    _bdf_line_func_t  callback,
@@ -621,29 +624,28 @@
       goto Exit;
     }
 
-   /* initial size and allocation of the input buffer
-    */
+    /* initial size and allocation of the input buffer */
     buf_size = 1024;
 
     if ( FT_NEW_ARRAY( buf, buf_size ) )
       goto Exit;
 
-    cb         = callback;
-    lineno     = 1;
-    buf[0]     = 0;
-    start      = 0;
-    end        = 0;
-    avail      = 0;
-    cursor     = 0;
-    refill     = 1;
-    to_skip    = NO_SKIP;
-    bytes      = 0;  /* make compiler happy */
+    cb      = callback;
+    lineno  = 1;
+    buf[0]  = 0;
+    start   = 0;
+    end     = 0;
+    avail   = 0;
+    cursor  = 0;
+    refill  = 1;
+    to_skip = NO_SKIP;
+    bytes   = 0;        /* make compiler happy */
 
     for (;;)
     {
       if ( refill )
       {
-        bytes = (int) FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor,
+        bytes  = (int)FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor,
                                          (FT_ULong)(buf_size - cursor) );
         avail  = cursor + bytes;
         cursor = 0;
@@ -652,7 +654,7 @@
 
       end = start;
 
-      /* should we skip an optional character like \n or \r ? */
+      /* should we skip an optional character like \n or \r? */
       if ( start < avail && buf[start] == to_skip )
       {
         start  += 1;
@@ -664,9 +666,8 @@
       while ( end < avail && buf[end] != '\n' && buf[end] != '\r' )
         end++;
 
-     /* if we hit the end of the buffer, try shifting its content
-      * or even resizing it
-      */
+      /* if we hit the end of the buffer, try shifting its content */
+      /* or even resizing it                                       */
       if ( end >= avail )
       {
         if ( bytes == 0 )  /* last line in file doesn't end in \r or \n */
@@ -674,18 +675,18 @@
 
         if ( start == 0 )
         {
-         /* this line is definitely too long, try resizing the input buffer
-          * a bit to handle it.
-          */
+          /* this line is definitely too long; try resizing the input */
+          /* buffer a bit to handle it.                               */
           FT_ULong  new_size;
 
-          if ( buf_size >= 65536UL )  /* limit ourselves to 64 Kb */
+
+          if ( buf_size >= 65536UL )  /* limit ourselves to 64KByte */
           {
             error = BDF_Err_Invalid_Argument;
             goto Exit;
           }
 
-          new_size = buf_size*2;
+          new_size = buf_size * 2;
           if ( FT_RENEW_ARRAY( buf, buf_size, new_size ) )
             goto Exit;
 
@@ -696,7 +697,7 @@
         {
           bytes = avail - start;
 
-          FT_MEM_COPY( buf, buf+start, bytes );
+          FT_MEM_COPY( buf, buf + start, bytes );
 
           cursor = bytes;
           avail -= bytes;
@@ -713,7 +714,8 @@
       /* XXX: Use encoding independent value for 0x1a */
       if ( buf[start] != '#' && buf[start] != 0x1a && end > start )
       {
-        error = (*cb)( buf+start, end-start, lineno, (void*)&cb, client_data );
+        error = (*cb)( buf + start, end - start, lineno,
+                       (void*)&cb, client_data );
         if ( error )
           break;
       }
@@ -720,7 +722,7 @@
 
       lineno  += 1;
       buf[end] = (char)hold;
-      start    = end+1;
+      start    = end + 1;
 
       if ( hold == '\n' )
         to_skip = '\r';
--- a/src/gzip/ftgzip.c
+++ b/src/gzip/ftgzip.c
@@ -8,7 +8,7 @@
 /*  parse compressed PCF fonts, as found with many X11 server              */
 /*  distributions.                                                         */
 /*                                                                         */
-/*  Copyright 2002, 2003, 2004 by                                          */
+/*  Copyright 2002, 2003, 2004, 2005 by                                    */
 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
 /*                                                                         */
 /*  This file is part of the FreeType project, and may only be used,       */
@@ -561,9 +561,11 @@
     FT_Memory    memory = source->memory;
     FT_GZipFile  zip;
 
-   /* check the header right now, this prevents allocating un-necessary
-    * objects when we don't need them
-    */
+
+    /*
+     *  check the header right now; this prevents allocating un-necessary
+     *  objects when we don't need them
+     */
     error = ft_gzip_check_header( source );
     if ( error )
       goto Exit;
--- a/src/lzw/ftlzw.c
+++ b/src/lzw/ftlzw.c
@@ -8,7 +8,7 @@
 /*  be used to parse compressed PCF fonts, as found with many X11 server   */
 /*  distributions.                                                         */
 /*                                                                         */
-/*  Copyright 2004 by                                                      */
+/*  Copyright 2004, 2005 by                                                */
 /*  Albert Chin-A-Young.                                                   */
 /*                                                                         */
 /*  Based on code in src/gzip/ftgzip.c, Copyright 2004 by                  */
@@ -414,13 +414,14 @@
     FT_Memory   memory = source->memory;
     FT_LZWFile  zip;
 
-   /* check the header right now, this will prevent us from
-    * allocating a huge LZWFile object (400 Kb of heap memory !!)
-    * when not necessary.
-    *
-    * Did I mention that you should never use .Z compressed font
-    * file ?
-    */
+
+    /*
+     *  Check the header right now; this prevents allocation a huge
+     *  LZWFile object (400 KByte of heap memory) if not necessary.
+     *
+     *  Did I mention that you should never use .Z compressed font
+     *  file?
+     */
     error = ft_lzw_check_header( source );
     if ( error )
       goto Exit;
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -2,7 +2,7 @@
 
     FreeType font driver for pcf fonts
 
-  Copyright 2000, 2001, 2002, 2003, 2004 by
+  Copyright 2000, 2001, 2002, 2003, 2004, 2005 by
   Francesco Zappa Nardelli
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
--- a/src/pcf/pcfutil.c
+++ b/src/pcf/pcfutil.c
@@ -44,9 +44,10 @@
     {
       unsigned int  val = *buf;
       
-      val = ((val >> 1) & 0x55) | ((val << 1) & 0xAA);
-      val = ((val >> 2) & 0x33) | ((val << 2) & 0xCC);
-      val = ((val >> 4) & 0x0F) | ((val << 4) & 0xF0);
+
+      val = ( ( val >> 1 ) & 0x55 ) | ( ( val << 1 ) & 0xAA );
+      val = ( ( val >> 2 ) & 0x33 ) | ( ( val << 2 ) & 0xCC );
+      val = ( ( val >> 4 ) & 0x0F ) | ( ( val << 4 ) & 0xF0 );
       
       *buf = (unsigned char)val;
     }
--- a/src/type1/t1parse.c
+++ b/src/type1/t1parse.c
@@ -102,6 +102,7 @@
     FT_UShort  tag;
     FT_Long    size;
 
+
     if ( FT_STREAM_SEEK( 0 ) )
       goto Exit;
       
@@ -149,7 +150,7 @@
     parser->in_memory    = 0;
     parser->single_block = 0;
 
-   /* check the header format */
+    /* check the header format */
     error = check_type1_format( stream, "%!PS-AdobeFont-1", 16 );
     if ( error )
     {
@@ -216,8 +217,8 @@
     }
     else
     {
-      /* read segment in memory - yeah that sucks, but so does the format */
-      if ( FT_ALLOC( parser->base_dict, size )     ||
+      /* read segment in memory - this is clumsy, but so does the format */
+      if ( FT_ALLOC( parser->base_dict, size )       ||
            FT_STREAM_READ( parser->base_dict, size ) )
         goto Exit;
       parser->base_len = size;