shithub: freetype+ttf2subf

Download patch

ref: 42372fd4d89e54f840831e378449cdd2508b6aa5
parent: e2f4e52ac8a8bf0f806a69e8b1081d45d027cee7
author: David Turner <[email protected]>
date: Thu Mar 21 10:02:54 EST 2002

* src/psaux/t1cmap.h, src/psaux/t1cmap.c, src/type1/t1cmap.h,
        src/type1/t1cmap.c: updating and moving the Type 1 FT_CMap support
        from "src/type1" to "src/psaux" since it's going to be shared
        by the Type 1 and CID font drivers..

        * src/psaux/Jamfile, src/psaux/psaux.c, src/psaux/psauxmod.c,
        src/psaux/rules.mk, include/freetype/internal/psaux.h: added support
        for Type 1 FT_CMaps.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2002-03-21  David Turner    <[email protected]>
+
+        * src/base/ftobjs.c, src/pcf/pcfdriver.c, src/pcf/pcfread.c: updated
+        to new FT_CMap definitions
+
+        * src/psaux/t1cmap.h, src/psaux/t1cmap.c, src/type1/t1cmap.h,
+        src/type1/t1cmap.c: updating and moving the Type 1 FT_CMap support
+        from "src/type1" to "src/psaux" since it's going to be shared
+        by the Type 1 and CID font drivers..
+
+        * src/psaux/Jamfile, src/psaux/psaux.c, src/psaux/psauxmod.c,
+        src/psaux/rules.mk, include/freetype/internal/psaux.h: added support
+        for Type 1 FT_CMaps.
+
 2002-03-20  David Turner    <[email protected]>
 
         * src/base/ftgloadr.c (FT_GlyphLoader_CheckSubGlyphs): fixed a memory
--- a/include/freetype/internal/psaux.h
+++ b/include/freetype/internal/psaux.h
@@ -651,7 +651,26 @@
     
   } T1_DecoderRec;
 
+  /*************************************************************************/
+  /*************************************************************************/
+  /*****                                                               *****/
+  /*****                     TYPE1 CHARMAPS                            *****/
+  /*****                                                               *****/
+  /*************************************************************************/
+  /*************************************************************************/
 
+  typedef const struct T1_CMap_ClassesRec_*  T1_CMap_Classes;
+
+  typedef struct T1_CMap_ClassesRec_
+  {
+    FT_CMap_Class  standard;
+    FT_CMap_Class  expert;
+    FT_CMap_Class  custom;
+    FT_CMap_Class  unicode;
+  
+  } T1_CMap_ClassesRec;
+  
+
   /*************************************************************************/
   /*************************************************************************/
   /*****                                                               *****/
@@ -660,7 +679,7 @@
   /*************************************************************************/
   /*************************************************************************/
 
-  typedef struct  PSAux_Interface_
+  typedef struct  PSAux_ServiceRec_
   {
     const PS_Table_Funcs    ps_table_funcs;
     const PS_Parser_Funcs   ps_parser_funcs;
@@ -672,9 +691,12 @@
                    FT_Offset  length,
                    FT_UShort  seed );
 
-  } PSAux_Interface;
+    T1_CMap_Classes         t1_cmap_classes;
 
-  typedef PSAux_Interface*  PSAux_Service;
+  } PSAux_ServiceRec, *PSAux_Service;
+
+ /* backwards-compatible type definition */
+  typedef PSAux_ServiceRec   PSAux_Interface;
 
 FT_END_HEADER
 
--- a/src/pcf/pcfdriver.c
+++ b/src/pcf/pcfdriver.c
@@ -37,7 +37,199 @@
 
 #include "pcferror.h"
 
+#undef  FT_COMPONENT
+#define FT_COMPONENT  trace_pcfread
 
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+
+  typedef struct PCF_CMapRec_
+  {
+    FT_CMapRec    cmap;
+    FT_UInt       num_encodings;
+    PCF_Encoding  encodings;
+  
+  } PCF_CMapRec, *PCF_CMap;
+
+
+  FT_CALLBACK_DEF( FT_Error )
+  pcf_cmap_init( PCF_CMap   cmap )
+  {
+    PCF_Face   face   = (PCF_Face) FT_CMAP_FACE(cmap);
+    
+    cmap->num_encodings = (FT_UInt) face->nencodings;
+    cmap->encodings     = face->encodings;
+    
+    return FT_Err_Ok;
+  }
+
+  
+  FT_CALLBACK_DEF( void )
+  pcf_cmap_done( PCF_CMap  cmap )
+  {
+    cmap->encodings     = NULL;    
+    cmap->num_encodings = 0;
+  }
+                 
+
+  FT_CALLBACK_DEF( FT_UInt )
+  pcf_cmap_char_index( FT_CMap    cmap,
+                       FT_UInt32  charcode )
+  {
+    PCF_Encoding  encoding = cmap->encodings;
+    FT_UInt       min, max, mid;
+    FT_UInt       result = 0;
+    
+    min = 0;
+    max = cmap->num_encodings;
+    
+    while ( min < max )
+    {
+      FT_UInt32  code;
+      
+      mid  = ( min + max ) >> 1;
+      code = encodings[mid].enc;
+      
+      if ( charcode == code )
+      {
+        result = encodings[mid].glyph;
+        break;
+      }
+      
+      if ( charcode < code )
+        max = mid;
+      else
+        min = mid+1;
+    }
+    
+    return result;
+  }                       
+
+
+  FT_CALLBACK_DEF( FT_UInt )
+  pcf_cmap_char_next( PCF_CMap    cmap,
+                      FT_UInt32  *acharcode )
+  {
+    PCF_Encoding  encodings = cmap->encodings;
+    FT_UInt       min, max, mid;
+    FT_UInt32     charcode = *acharcode + 1;
+    FT_UInt       result   = 0;
+    
+    min = 0;
+    max = cmap->num_encodings;
+    
+    while ( min < max )
+    {
+      FT_UInt32  code;
+      
+      mid  = ( min + max ) >> 1;
+      code = encodings[mid].enc;
+      
+      if ( charcode == code )
+      {
+        result = encodings[mid].glyph;
+        goto Exit;
+      }
+      
+      if ( charcode < code )
+        max = mid;
+      else
+        min = mid+1;
+    }
+    
+    charcode = 0;
+    if ( ++min < cmap->num_encodings )
+    {
+      charcode = encodings[min].enc;
+      glyph    = encodings[min].glyph;
+    }
+    
+  Exit:
+    *acharcode = charcode;
+    return result;
+  }                      
+
+
+  FT_CALLBACK_TABLE const FT_CMap_ClassRec  pcf_cmap_class =
+  {
+    sizeof( PCF_CMapRec ),
+    (FT_CMap_InitFunc)       pcf_cmap_init,
+    (FT_CMap_DoneFunc)       pcf_cmap_done,
+    (FT_CMap_CharIndexFunc)  pcf_cmap_char_index,
+    (FT_CMap_CharNextFunc)   pcf_cmap_char_next
+  };
+
+#else /* !FT_CONFIG_OPTION_USE_CMAPS */
+
+  static FT_UInt
+  PCF_Char_Get_Index( FT_CharMap  charmap,
+                      FT_Long     char_code )
+  {
+    PCF_Face      face     = (PCF_Face)charmap->face;
+    PCF_Encoding  en_table = face->encodings;
+    int           low, high, mid;
+
+
+    FT_TRACE4(( "get_char_index %ld\n", char_code ));
+
+    low = 0;
+    high = face->nencodings - 1;
+    while ( low <= high )
+    {
+      mid = ( low + high ) / 2;
+      if ( char_code < en_table[mid].enc )
+        high = mid - 1;
+      else if ( char_code > en_table[mid].enc )
+        low = mid + 1;
+      else
+        return en_table[mid].glyph;
+    }
+
+    return 0;
+  }
+
+
+  static FT_Long
+  PCF_Char_Get_Next( FT_CharMap  charmap,
+                     FT_Long     char_code )
+  {
+    PCF_Face      face     = (PCF_Face)charmap->face;
+    PCF_Encoding  en_table = face->encodings;
+    int           low, high, mid;
+
+
+    FT_TRACE4(( "get_next_char %ld\n", char_code ));
+    
+    char_code++;
+    low  = 0;
+    high = face->nencodings - 1;
+
+    while ( low <= high )
+    {
+      mid = ( low + high ) / 2;
+      if ( char_code < en_table[mid].enc )
+        high = mid - 1;
+      else if ( char_code > en_table[mid].enc )
+        low = mid + 1;
+      else
+        return char_code;
+    }
+
+    if ( high < 0 )
+      high = 0;
+    
+    while ( high < face->nencodings )
+    {
+      if ( en_table[high].enc >= char_code )
+        return en_table[high].enc;
+      high++;
+    }
+
+    return 0;
+  }
+
+#endif /* !FT_CONFIG_OPTION_USE_CMAPS */
+
+
   /*************************************************************************/
   /*                                                                       */
   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
@@ -48,7 +240,7 @@
 #define FT_COMPONENT  trace_pcfdriver
 
 
-  static FT_Error
+  FT_CALLBACK_DEF( FT_Error )
   PCF_Face_Done( PCF_Face  face )
   {
     FT_Memory    memory = FT_FACE_MEMORY( face );
@@ -86,7 +278,7 @@
   }
 
 
-  static FT_Error
+  FT_CALLBACK_DEF( FT_Error )
   PCF_Face_Init( FT_Stream      stream,
                  PCF_Face       face,
                  FT_Int         face_index,
@@ -104,13 +296,75 @@
     if ( error )
       goto Fail;
 
-    return PCF_Err_Ok;
+    /* set-up charmap */
+    {
+      FT_String   *charset_registry, *charset_encoding;
+      FT_Face      root = FT_FACE(face);
+      FT_Bool      unicode_charmap  = 0;
 
+
+      charset_registry = face->charset_registry;
+      charset_encoding = face->charset_encoding;
+
+      if ( ( charset_registry != NULL ) &&
+           ( charset_encoding != NULL ) )
+      {
+        if ( !strcmp( face->charset_registry, "ISO10646" ) ||
+           ( !strcmp( face->charset_registry, "ISO8859" ) &&
+             !strcmp( face->charset_encoding, "1" ) ) )
+          unicode_charmap = 1;
+      }
+
+#ifdef FT_CONFIG_OPTION_USE_CMAPS
+      {
+        FT_CharMapRec  charmap;
+        
+        charmap.face        = FT_FACE(face);
+        charmap.encoding    = ft_encoding_none;
+        charmap.platform_id = 0;
+        charmap.encoding_id = 0;
+        
+        if ( unicode_charmap )
+        {
+          charmap.encoding    = ft_encoding_unicode;
+          charmap.platform_id = 3;
+          charmap.encoding_id = 1;
+        }
+        
+        error = FT_CMap_New( &pcf_cmap_class, NULL, &charmap, NULL );
+      }
+#else  /* !FT_CONFIG_OPTION_USE_CMAPS */
+
+      /* XXX: charmaps.  For now, report unicode for Unicode and Latin 1 */
+      root->charmaps     = &face->charmap_handle;
+      root->num_charmaps = 1;
+
+      face->charmap.encoding    = ft_encoding_none;
+      face->charmap.platform_id = 0;
+      face->charmap.encoding_id = 0;
+
+      if ( unicode_charmap )
+      {
+        face->charmap.encoding    = ft_encoding_unicode;
+        face->charmap.platform_id = 3;
+        face->charmap.encoding_id = 1;
+      }
+      
+      face->charmap.face   = root;
+      face->charmap_handle = &face->charmap;
+      root->charmap        = face->charmap_handle;
+
+#endif /* !FT_CONFIG_OPTION_USE_CMAPS */        
+        
+    }
+      
+  Exit:
+    return error;
+
   Fail:
     FT_TRACE2(( "[not a valid PCF file]\n" ));
-    PCF_Face_Done( face );
-
-    return PCF_Err_Unknown_File_Format; /* error */
+    error = PCF_Err_Unknown_File_Format;  /* error */
+    goto Exit;
   }
 
 
@@ -256,74 +510,6 @@
   }
 
 
-  static FT_UInt
-  PCF_Char_Get_Index( FT_CharMap  charmap,
-                      FT_Long     char_code )
-  {
-    PCF_Face      face     = (PCF_Face)charmap->face;
-    PCF_Encoding  en_table = face->encodings;
-    int           low, high, mid;
-
-
-    FT_TRACE4(( "get_char_index %ld\n", char_code ));
-
-    low = 0;
-    high = face->nencodings - 1;
-    while ( low <= high )
-    {
-      mid = ( low + high ) / 2;
-      if ( char_code < en_table[mid].enc )
-        high = mid - 1;
-      else if ( char_code > en_table[mid].enc )
-        low = mid + 1;
-      else
-        return en_table[mid].glyph;
-    }
-
-    return 0;
-  }
-
-
-  static FT_Long
-  PCF_Char_Get_Next( FT_CharMap  charmap,
-                     FT_Long     char_code )
-  {
-    PCF_Face      face     = (PCF_Face)charmap->face;
-    PCF_Encoding  en_table = face->encodings;
-    int           low, high, mid;
-
-
-    FT_TRACE4(( "get_next_char %ld\n", char_code ));
-    
-    char_code++;
-    low  = 0;
-    high = face->nencodings - 1;
-
-    while ( low <= high )
-    {
-      mid = ( low + high ) / 2;
-      if ( char_code < en_table[mid].enc )
-        high = mid - 1;
-      else if ( char_code > en_table[mid].enc )
-        low = mid + 1;
-      else
-        return char_code;
-    }
-
-    if ( high < 0 )
-      high = 0;
-    
-    while ( high < face->nencodings )
-    {
-      if ( en_table[high].enc >= char_code )
-        return en_table[high].enc;
-      high++;
-    }
-
-    return 0;
-  }
-
-
   FT_CALLBACK_TABLE_DEF
   const FT_Driver_ClassRec  pcf_driver_class =
   {
@@ -353,17 +539,26 @@
     (FT_Slot_InitFunc)0,
     (FT_Slot_DoneFunc)0,
 
-    (FT_Size_ResetPointsFunc) PCF_Set_Pixel_Size,
-    (FT_Size_ResetPixelsFunc)PCF_Set_Pixel_Size,
+    (FT_Size_ResetPointsFunc)  PCF_Set_Pixel_Size,
+    (FT_Size_ResetPixelsFunc)  PCF_Set_Pixel_Size,
 
-    (FT_Slot_LoadFunc)    PCF_Glyph_Load,
+    (FT_Slot_LoadFunc)         PCF_Glyph_Load,
+
+#ifndef FT_CONFIG_OPTION_USE_CMAPS    
     (FT_CharMap_CharIndexFunc) PCF_Char_Get_Index,
+#else
+    (FT_CharMap_CharNextFunc)  0,
+#endif
 
     (FT_Face_GetKerningFunc)   0,
-    (FT_Face_AttachFunc)   0,
+    (FT_Face_AttachFunc)       0,
     (FT_Face_GetAdvancesFunc)  0,
 
+#ifndef FT_CONFIG_OPTION_USE_CMAPS
     (FT_CharMap_CharNextFunc)  PCF_Char_Get_Next,
+#else
+    (FT_CharMap_CharNextFunc)  0
+#endif    
   };
 
 
--- a/src/pcf/pcfread.c
+++ b/src/pcf/pcfread.c
@@ -866,11 +866,11 @@
 
     error = pcf_read_TOC( stream, face );
     if ( error )
-      return error;
+      goto Exit;
 
     error = pcf_get_properties( stream, face );
     if ( error )
-      return error;;
+      goto Exit;
 
     /* Use the old accelerators if no BDF accelerators are in the file. */
     hasBDFAccelerators = pcf_has_table_type( face->toc.tables,
@@ -880,23 +880,23 @@
     {
       error = pcf_get_accel( stream, face, PCF_ACCELERATORS );
       if ( error )
-        goto Bail;
+        goto Exit;
     }
 
     /* metrics */
     error = pcf_get_metrics( stream, face );
     if ( error )
-      goto Bail;
+      goto Exit;
 
     /* bitmaps */
     error = pcf_get_bitmaps( stream, face );
     if ( error )
-      goto Bail;
+      goto Exit;
 
     /* encodings */
     error = pcf_get_encodings( stream, face );
     if ( error )
-      goto Bail;
+      goto Exit;
 
     /* BDF style accelerators (i.e. bounds based on encoded glyphs) */
     if ( hasBDFAccelerators )
@@ -903,7 +903,7 @@
     {
       error = pcf_get_accel( stream, face, PCF_BDF_ACCELERATORS );
       if ( error )
-        goto Bail;
+        goto Exit;
     }
 
     /* XXX: TO DO: inkmetrics and glyph_names are missing */
@@ -958,7 +958,7 @@
 
 
           if ( ALLOC( root->family_name, l * sizeof ( char ) ) )
-            goto Bail;
+            goto Exit;
           strcpy( root->family_name, prop->value.atom );
         }
       }
@@ -969,7 +969,7 @@
 
       root->num_fixed_sizes = 1;
       if ( ALLOC_ARRAY( root->available_sizes, 1, FT_Bitmap_Size ) )
-        goto Bail;
+        goto Exit;
 
       prop = pcf_find_property( face, "PIXEL_SIZE" );
       if ( prop != NULL )
@@ -977,12 +977,6 @@
         root->available_sizes->height = 
         root->available_sizes->width  = (FT_Short)( prop->value.integer );
 
-#if 0  /* average width property support removed until maturation */
-        prop = pcf_find_property( face, "AVERAGE_WIDTH" );
-        if ( prop != NULL )
-          root->available_sizes->width = (FT_Short)( prop->value.integer / 10 );
-#endif
-        
         size_set = 1;
       }
       else 
@@ -1003,13 +997,7 @@
               (FT_Short)( prop->value.integer *  
                           yres->value.integer / 720 ); 
 
-#if 0  /* average width property support removed until maturation */
-            if ( avgw != NULL )
               root->available_sizes->width =
-                (FT_Short)( avgw->value.integer / 10 );
-            else
-#endif            
-              root->available_sizes->width =
                 (FT_Short)( prop->value.integer *  
                             xres->value.integer / 720 );
                   
@@ -1020,28 +1008,19 @@
 
       if (size_set == 0 )
       {
-#if 0
-        printf( "PCF Warning: Pixel Size undefined, assuming 12\n");
-#endif
         root->available_sizes->width  = 12;
         root->available_sizes->height = 12;
       }
 
-      /* XXX: charmaps.  For now, report unicode for Unicode and Latin 1 */
-      root->charmaps     = &face->charmap_handle;
-      root->num_charmaps = 1;
-
-      face->charmap.encoding    = ft_encoding_none;
-      face->charmap.platform_id = 0;
-      face->charmap.encoding_id = 0;
-
+      /* set-up charset */
       {
         PCF_Property  charset_registry = 0, charset_encoding = 0;
-
-
+        FT_Bool       unicode_charmap  = 0;
+  
+  
         charset_registry = pcf_find_property( face, "CHARSET_REGISTRY" );
         charset_encoding = pcf_find_property( face, "CHARSET_ENCODING" );
-
+  
         if ( ( charset_registry != NULL ) &&
              ( charset_encoding != NULL ) )
         {
@@ -1051,34 +1030,29 @@
             if ( ALLOC( face->charset_encoding,
                         ( strlen( charset_encoding->value.atom ) + 1 ) *
                           sizeof ( char ) ) )
-              goto Bail;
+              goto Exit;
+              
             if ( ALLOC( face->charset_registry,
                         ( strlen( charset_registry->value.atom ) + 1 ) *
                           sizeof ( char ) ) )
-              goto Bail;
+              goto Exit;
+              
             strcpy( face->charset_registry, charset_registry->value.atom );
             strcpy( face->charset_encoding, charset_encoding->value.atom );
-
-            if ( !strcmp( face->charset_registry, "ISO10646" ) ||
-                 ( !strcmp( face->charset_registry, "ISO8859" ) &&
-                   !strcmp( face->charset_encoding, "1" ) ) )
-            {
-              face->charmap.encoding    = ft_encoding_unicode;
-              face->charmap.platform_id = 3;
-              face->charmap.encoding_id = 1;
-            }
           }
         }
       }
-
-      face->charmap.face   = root;
-      face->charmap_handle = &face->charmap;
-      root->charmap        = face->charmap_handle;
     }
-    return PCF_Err_Ok;
-
-  Bail:
-    return PCF_Err_Invalid_File_Format;
+    
+  Exit:
+    if (error)
+    {
+      /* this is done to respect the behaviour of the original */
+      /* PCF font driver..                                     */
+      error = PCF_Err_Invalid_File_Format;
+    }
+      
+    return error;
   }
 
 
--- a/src/psaux/Jamfile
+++ b/src/psaux/Jamfile
@@ -10,7 +10,7 @@
 
   if $(FT2_MULTI)
   {
-    _sources = psauxmod psobjs t1decode ;
+    _sources = psauxmod psobjs t1decode t1cmap ;
   }
   else
   {
--- a/src/psaux/psaux.c
+++ b/src/psaux/psaux.c
@@ -22,6 +22,7 @@
 #include "psobjs.c"
 #include "psauxmod.c"
 #include "t1decode.c"
+#include "t1cmap.c"
 
 
 /* END */
--- a/src/psaux/psauxmod.c
+++ b/src/psaux/psauxmod.c
@@ -20,6 +20,7 @@
 #include "psauxmod.h"
 #include "psobjs.h"
 #include "t1decode.h"
+#include "t1cmap.h"
 
 
   FT_CALLBACK_TABLE_DEF
@@ -73,6 +74,16 @@
   };
 
 
+  FT_CALLBACK_TABLE_DEF
+  const T1_CMap_ClassesRec  t1_cmap_classes =
+  {
+    &t1_cmap_standard_class_rec,
+    &t1_cmap_expert_class_rec,
+    &t1_cmap_custom_class_rec,
+    &t1_cmap_unicode_class_rec
+  };
+
+
   static
   const PSAux_Interface  psaux_interface =
   {
@@ -81,7 +92,9 @@
     &t1_builder_funcs,
     &t1_decoder_funcs,
 
-    T1_Decrypt
+    T1_Decrypt,
+    
+    (const T1_CMap_ClassesRec*) &t1_cmap_classes,
   };
 
 
--- a/src/psaux/rules.mk
+++ b/src/psaux/rules.mk
@@ -28,6 +28,7 @@
 #
 PSAUX_DRV_SRC := $(PSAUX_DIR_)psobjs.c   \
                  $(PSAUX_DIR_)t1decode.c \
+                 $(PSAUX_DIR_)t1cmap.c   \
                  $(PSAUX_DIR_)psauxmod.c
 
 # PSAUX driver headers
--- a/src/psaux/t1cmap.c
+++ b/src/psaux/t1cmap.c
@@ -1,5 +1,8 @@
 #include "t1cmap.h"
+#include <stdlib.h>
 
+#include FT_INTERNAL_DEBUG_H
+
  /***************************************************************************/
  /***************************************************************************/
  /*****                                                                 *****/
@@ -8,7 +11,7 @@
  /***************************************************************************/
  /***************************************************************************/
 
-  static( void )
+  static void
   t1_cmap_std_init( T1_CMapStd   cmap,
                     FT_Int       is_expert )
   {
@@ -15,11 +18,11 @@
     T1_Face          face    = (T1_Face) FT_CMAP_FACE(cmap);
     PSNames_Service  psnames = face->psnames;
 
-    cmap->num_glyphs  = face->type1.num_glyphs;
-    cmap->glyph_names = face->type1.glyph_names;
-    cmap->sid_strings = sid_strings;
-    cmap->code_to_sid = is_expert ? psnames->adobe_expert_encoding
-                                  : psnames->adobe_std_encoding;
+    cmap->num_glyphs    = face->type1.num_glyphs;
+    cmap->glyph_names   = face->type1.glyph_names;
+    cmap->sid_to_string = psnames->adobe_std_strings;
+    cmap->code_to_sid   = is_expert ? psnames->adobe_expert_encoding
+                                    : psnames->adobe_std_encoding;
 
     FT_ASSERT( cmap->code_to_sid != NULL );
   }
@@ -28,10 +31,10 @@
   FT_CALLBACK_DEF( void )
   t1_cmap_std_done( T1_CMapStd  cmap )
   {
-    cmap->num_glyphs  = 0;
-    cmap->glyph_names = NULL;
-    cmap->sid_strings = NULL;
-    cmap->code_to_sid = NULL;
+    cmap->num_glyphs    = 0;
+    cmap->glyph_names   = NULL;
+    cmap->sid_to_string = NULL;
+    cmap->code_to_sid   = NULL;
   }
 
 
@@ -43,13 +46,12 @@
 
     if ( char_code < 256 )
     {
-      FT_UInt      code;
+      FT_UInt      code, n;
       const char*  glyph_name;
-      FT_Int       n;
 
       /* conver character code to Adobe SID string */
       code       = cmap->code_to_sid[ char_code ];
-      glyph_name = cmap->adobe_sid_strings[ code ];
+      glyph_name = cmap->sid_to_string( code );
 
       /* look for the corresponding glyph name */
       for ( n = 0; n < cmap->num_glyphs; n++ )
@@ -77,7 +79,7 @@
 
     while ( char_code < 256 )
     {
-      result = t1_cmap_standard_char_index( cmap, char_code );
+      result = t1_cmap_std_char_index( cmap, char_code );
       if ( result != 0 )
         goto Exit;
 
@@ -99,26 +101,21 @@
   }
 
 
-  FT_CALLBACK_TABLE const T1_CMap_ClassRec
+  FT_LOCAL_DEF( const FT_CMap_ClassRec )
   t1_cmap_standard_class_rec =
   {
     sizeof( T1_CMapStdRec ),
 
-    t1_cmap_standard_init,
-    t1_cmap_std_done,
-    t1_cmap_std_char_index,
-    t1_cmap_std_char_next
+    (FT_CMap_InitFunc)      t1_cmap_standard_init,
+    (FT_CMap_DoneFunc)      t1_cmap_std_done,
+    (FT_CMap_CharIndexFunc) t1_cmap_std_char_index,
+    (FT_CMap_CharNextFunc)  t1_cmap_std_char_next
   };
 
 
-  FT_LOCAL_DEF( T1_CMap_Class )
-  t1_cmap_standard_class = &t1_cmap_standard_class_rec;
 
 
-
-
-
-  FT_CALLBACK_DEF( void )
+  FT_CALLBACK_DEF( FT_Error )
   t1_cmap_expert_init( T1_CMapStd  cmap )
   {
     t1_cmap_std_init( cmap, 1 );
@@ -125,20 +122,18 @@
     return 0;
   }
 
-  FT_CALLBACK_TABLE const FT_CMap_ClassRec
+  FT_LOCAL_DEF( const FT_CMap_ClassRec )
   t1_cmap_expert_class_rec =
   {
     sizeof( T1_CMapStdRec ),
 
-    t1_cmap_expert_init,
-    t1_cmap_std_done,
-    t1_cmap_std_char_index,
-    t1_cmap_std_char_next
+    (FT_CMap_InitFunc)      t1_cmap_expert_init,
+    (FT_CMap_DoneFunc)      t1_cmap_std_done,
+    (FT_CMap_CharIndexFunc) t1_cmap_std_char_index,
+    (FT_CMap_CharNextFunc)  t1_cmap_std_char_next
   };
 
 
-  FT_LOCAL_DEF( FT_CMap_Class )
-  t1_cmap_expert_class = &t1_cmap_expert_class_rec;
 
 
  /***************************************************************************/
@@ -153,8 +148,8 @@
   FT_CALLBACK_DEF( FT_Error )
   t1_cmap_custom_init( T1_CMapCustom  cmap )
   {
-    T1_Face       face     = (T1_Face) FT_CMAP_FACE(cmap);
-    T1_Encoding  encoding = face->type1.encoding;
+    T1_Face      face     = (T1_Face) FT_CMAP_FACE(cmap);
+    T1_Encoding  encoding = &face->type1.encoding;
 
     cmap->first   = encoding->code_first;
     cmap->count   = (FT_UInt)(encoding->code_last - cmap->first + 1);
@@ -192,8 +187,8 @@
 
 
   FT_CALLBACK_DEF( FT_UInt )
-  t1_cmap_custom_char_next( T1_CMapCustion  cmap,
-                            FT_UInt32      *pchar_code )
+  t1_cmap_custom_char_next( T1_CMapCustom  cmap,
+                            FT_UInt32     *pchar_code )
   {
     FT_UInt   result = 0;
     FT_UInt32 char_code = *pchar_code;
@@ -205,7 +200,7 @@
       char_code = cmap->first;
 
     index = (FT_UInt32)( char_code - cmap->first );
-    while ( index < cmap->count; index++, char_code++ )
+    for ( ; index < cmap->count; index++, char_code++ )
     {
       result = cmap->indices[index];
       if ( result != 0 )
@@ -220,19 +215,17 @@
   }
 
 
-  FT_CALLBACK_TABLE const FT_CMap_ClassRec
+  FT_LOCAL_DEF( const FT_CMap_ClassRec )
   t1_cmap_custom_class_rec =
   {
     sizeof( T1_CMapCustomRec ),
-    t1_cmap_custom_init,
-    t1_cmap_custom_done,
-    t1_cmap_custom_char_index,
-    t1_cmap_custom_char_next
+    (FT_CMap_InitFunc)      t1_cmap_custom_init,
+    (FT_CMap_DoneFunc)      t1_cmap_custom_done,
+    (FT_CMap_CharIndexFunc) t1_cmap_custom_char_index,
+    (FT_CMap_CharNextFunc)  t1_cmap_custom_char_next
   };
 
 
-  FT_LOCAL_DEF( FT_CMap_Class )
-  t1_cmap_custom_class = &t1_cmap_custom_class_rec;
 
 
  /***************************************************************************/
@@ -243,14 +236,32 @@
  /***************************************************************************/
  /***************************************************************************/
 
+  FT_CALLBACK_DEF( FT_Int )
+  t1_cmap_uni_pair_compare( const void*  pair1,
+                            const void*  pair2 )
+  {
+    FT_UInt32  u1 = ((T1_CMapUniPair)pair1)->unicode;
+    FT_UInt32  u2 = ((T1_CMapUniPair)pair2)->unicode;
+    
+    if ( u1 < u2 )
+      return -1;
+      
+    if ( u1 > u2 )
+      return +1;
+      
+    return 0;
+  }                            
 
+
+
   FT_CALLBACK_DEF( FT_Error )
   t1_cmap_unicode_init( T1_CMapUnicode  cmap )
   {
-    FT_Error    error;
-    FT_UInt     count;
-    T1_Face     face   = (T1_Face) FT_CMAP_FACE(cmap);
-    FT_Memory   memory = FT_FACE_MEMORY(face);
+    FT_Error         error;
+    FT_UInt          count;
+    T1_Face          face    = (T1_Face) FT_CMAP_FACE(cmap);
+    FT_Memory        memory  = FT_FACE_MEMORY(face);
+    PSNames_Service  psnames = face->psnames;
 
     cmap->num_pairs = 0;
     cmap->pairs     = NULL;
@@ -272,7 +283,7 @@
         /* build unsorted pair table by matching glyph names */
         if ( gname )
         {
-          uni_code = PS_Unicode_Value( gname );
+          uni_code = psnames->unicode_value( gname );
 
           if ( uni_code != 0 )
           {
@@ -281,28 +292,32 @@
             pair++;
           }
         }
-
-        if ( new_count == 0 )
+      }
+      
+      new_count = (FT_UInt)( pair - cmap->pairs );
+      if ( new_count == 0 )
+      {
+        /* there are no unicode characters in here !! */
+        FREE( cmap->pairs );
+        error = FT_Err_Invalid_Argument;
+      }
+      else
+      {
+        /* re-allocate if the new array is much smaller than the original */
+        /* one..                                                          */
+        if ( new_count != count && new_count < count/2 )
         {
-          /* there are no unicode characters in here !! */
-          FREE( cmap->pairs );
-          error = FT_Err_Invalid_Argument;
+          (void)REALLOC_ARRAY( cmap->pairs, count, new_count, T1_CMapUniPairRec );
+          error = 0;
         }
-        else
-        {
-          /* re-allocate if the new array is much smaller than the original */
-          /* one..                                                          */
-          if ( new_count != count && new_count < count/2 )
-            REALLOC_ARRAY( cmap->pairs, count, new_count, T1_CMapUniPairRec )
 
-          /* sort the pairs table to allow efficient binary searches */
-          qsort( cmap->pairs,
-                 new_count,
-                 sizeof(T1_CMapUniPairRec),
-                 t1_cmap_uni_pair_compare );
+        /* sort the pairs table to allow efficient binary searches */
+        qsort( cmap->pairs,
+               new_count,
+               sizeof(T1_CMapUniPairRec),
+               t1_cmap_uni_pair_compare );
 
-          cmap->num_pairs = new_count;
-        }
+        cmap->num_pairs = new_count;
       }
     }
 
@@ -313,7 +328,7 @@
   FT_CALLBACK_DEF( void )
   t1_cmap_unicode_done( T1_CMapUnicode  cmap )
   {
-    FT_Face    face = FT_CMAP_FACE(cmap);
+    FT_Face    face   = FT_CMAP_FACE(cmap);
     FT_Memory  memory = FT_FACE_MEMORY(face);
 
     FREE( cmap->pairs );
@@ -321,6 +336,7 @@
   }
 
 
+
   FT_CALLBACK_DEF( FT_UInt )
   t1_cmap_unicode_char_index( T1_CMapUnicode  cmap,
                               FT_UInt32       char_code )
@@ -351,7 +367,8 @@
   t1_cmap_unicode_char_next( T1_CMapUnicode  cmap,
                              FT_UInt32      *pchar_code )
   {
-    FT_UInt32       char_code = *pchar_code + 1;
+    FT_UInt      result    = 0;
+    FT_UInt32    char_code = *pchar_code + 1;
 
   Restart:
     {
@@ -362,7 +379,7 @@
 
       while ( min < max )
       {
-        mid  = min + (max - min)/2;
+        mid  = min + ((max - min) >> 1);
         pair = cmap->pairs + mid;
 
         if ( pair->unicode == char_code )
@@ -386,7 +403,7 @@
 
       if ( min < cmap->num_pairs )
       {
-        pair   = cmap->num_pairs + min;
+        pair   = cmap->pairs + min;
         result = pair->gindex;
         if ( result != 0 )
           char_code = pair->unicode;
@@ -403,8 +420,14 @@
   t1_cmap_unicode_class_rec =
   {
     sizeof( T1_CMapUnicodeRec ),
-    t1_cmap_unicode_init,
-    t1_cmap_unicode_done,
-    t1_cmap_unicode_char_index,
-    t1_cmap_unicode_char_next
+    (FT_CMap_InitFunc)      t1_cmap_unicode_init,
+    (FT_CMap_DoneFunc)      t1_cmap_unicode_done,
+    (FT_CMap_CharIndexFunc) t1_cmap_unicode_char_index,
+    (FT_CMap_CharNextFunc)  t1_cmap_unicode_char_next
   };
+
+
+
+  FT_LOCAL_DEF( const FT_CMap_Class )
+  t1_cmap_unicode_class = &t1_cmap_unicode_class_rec;
+
--- a/src/psaux/t1cmap.h
+++ b/src/psaux/t1cmap.h
@@ -1,6 +1,11 @@
 #ifndef __FT_TYPE1_CMAP_H__
 #define __FT_TYPE1_CMAP_H__
 
+#include <ft2build.h>
+#include FT_INTERNAL_OBJECTS_H
+#include FT_INTERNAL_TYPE1_TYPES_H
+#include FT_INTERNAL_POSTSCRIPT_NAMES_H
+
 FT_BEGIN_HEADER
 
  /***************************************************************************/
@@ -16,22 +21,21 @@
 
   typedef struct T1_CMapStdRec_
   {
-    FT_CMapRec          cmap;
+    FT_CMapRec                 cmap;
 
-    const FT_UShort*    charcode_to_sid;
-    const char* const*  adobe_sid_strings;
+    const FT_UShort*           code_to_sid;
+    PS_Adobe_Std_Strings_Func  sid_to_string;
 
-    FT_UInt             num_glyphs;
-    const char**        glyph_names;
+    FT_UInt                    num_glyphs;
+    const char* const*         glyph_names;
     
-    
   } T1_CMapStdRec;
 
 
-  FT_LOCAL( FT_CMap_Class )   t1_cmap_standard_class;
-
-  FT_LOCAL( FT_CMap_Class )   t1_cmap_expert_class;
-
+  FT_LOCAL( const FT_CMap_ClassRec )   t1_cmap_standard_class_rec;
+  
+  FT_LOCAL( const FT_CMap_ClassRec )   t1_cmap_expert_class_rec;
+  
  /***************************************************************************/
  /***************************************************************************/
  /*****                                                                 *****/
@@ -47,13 +51,12 @@
     FT_CMapRec    cmap;
     FT_UInt       first;
     FT_UInt       count;
-    FT_UInt*      indices;
+    FT_UShort*    indices;
   
   } T1_CMapCustomRec;
 
-
-  FT_LOCAL( FT_CMap_Class )   t1_cmap_custom_class;
-
+  FT_LOCAL( const FT_CMap_ClassRec )   t1_cmap_custom_class_rec;
+  
  /***************************************************************************/
  /***************************************************************************/
  /*****                                                                 *****/
@@ -82,7 +85,7 @@
   } T1_CMapUnicodeRec;
 
 
-  FT_LOCAL( FT_CMap_Class )   t1_cmap_unicode_class;
+  FT_LOCAL( const FT_CMap_ClassRec )   t1_cmap_unicode_class_rec;
 
  /* */