* src/cff/cfftypes.h (CFF_FontRecDictRec): Change type of
`cid_count' to `FT_ULong'.

* src/cff/cffgload.c (cff_slot_load): Take care of empty `cids'
array.

* src/cff/cffload.c (cff_charset_done): Free `cids' array.
(cff_font_load): Create cids array only for CID-keyed fonts which
are subsetted.

* src/cff/cffobjs.c (cff_face_init): Check the availability of
the PSNames modules for non-pure CFFs also.
Set FT_FACE_FLAG_GLYPH_NAMES for a non-pure CFF also if it isn't
CID-keyed.

* src/cff/rules.mk (CFF_DRV_H): Add cfftypes.h.
diff --git a/ChangeLog b/ChangeLog
index 854823f..cc0a0c6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2003-12-18  Werner Lemberg  <wl@gnu.org>
+
+	* src/cff/cfftypes.h (CFF_FontRecDictRec): Change type of
+	`cid_count' to `FT_ULong'.
+
+	* src/cff/cffgload.c (cff_slot_load): Take care of empty `cids'
+	array.
+
+	* src/cff/cffload.c (cff_charset_done): Free `cids' array.
+	(cff_font_load): Create cids array only for CID-keyed fonts which
+	are subsetted.
+
+	* src/cff/cffobjs.c (cff_face_init): Check the availability of
+	the PSNames modules for non-pure CFFs also.
+	Set FT_FACE_FLAG_GLYPH_NAMES for a non-pure CFF also if it isn't
+	CID-keyed.
+
+	* src/cff/rules.mk (CFF_DRV_H): Add cfftypes.h.
+
 2003-12-17  Werner Lemberg  <wl@gnu.org>
 
 	* src/sfnt/sfobjs.c (sfnt_init_face): Don't set
diff --git a/docs/CHANGES b/docs/CHANGES
index ab9d913..09026b9 100644
--- a/docs/CHANGES
+++ b/docs/CHANGES
@@ -14,8 +14,8 @@
       correctly  treated as a CID,  similar to  FreeType's CID  driver
       module.  Note that CID CMaps support is still missing.
 
-    - SFNT  based fonts  no longer  set  the FT_FACE_FLAGS_GLYPH_NAMES
-      flag if a version 3.0 `post' table is present.
+    - The FT_FACE_FLAGS_GLYPH_NAMES is now  set correctly for all font
+      formats.
 
 
   II. IMPORTANT CHANGES
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 0388b75..a905b84 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -2316,8 +2316,10 @@
 
 
       /* in a CID-keyed font, consider `glyph_index' as a CID and map */
-      /* it immediately to the real glyph_index                       */
-      if ( cff->top_font.font_dict.cid_registry != 0xFFFFU )
+      /* it immediately to the real glyph_index -- if it isn't a      */
+      /* subsetted font, glyph_indices and CIDs are identical, though */
+      if ( cff->top_font.font_dict.cid_registry != 0xFFFFU &&
+           cff->charset.cids )
         glyph_index = cff->charset.cids[glyph_index];
 
       cff_decoder_init( &decoder, face, size, glyph, hinting,
diff --git a/src/cff/cffload.c b/src/cff/cffload.c
index 68bac3e..f63d7fd 100644
--- a/src/cff/cffload.c
+++ b/src/cff/cffload.c
@@ -1501,6 +1501,7 @@
 
 
     FT_FREE( charset->sids );
+    FT_FREE( charset->cids );
     charset->format = 0;
     charset->offset = 0;
   }
@@ -1672,7 +1673,7 @@
       }
     }
 
-    /* we have to invert the `sids' array for CID-keyed fonts */
+    /* we have to invert the `sids' array for subsetted CID-keyed fonts */
     if ( invert )
     {
       FT_UInt    i;
@@ -2244,9 +2245,13 @@
     /* read the Charset and Encoding tables if available */
     if ( font->num_glyphs > 0 )
     {
+      FT_Bool  invert;
+
+
+      invert = dict->cid_registry != 0xFFFFU &&
+               font->charstrings_index.count != dict->cid_count;
       error = cff_charset_load( &font->charset, font->num_glyphs, stream,
-                                base_offset, dict->charset_offset,
-                                dict->cid_registry != 0xFFFFU );
+                                base_offset, dict->charset_offset, invert );
       if ( error )
         goto Exit;
 
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index 15540b7..8d45165 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -337,10 +337,11 @@
 
     /* now load and parse the CFF table in the file */
     {
-      CFF_Font   cff;
-      FT_Memory  memory = face->root.memory;
-      FT_Face    root;
-      FT_Int32   flags;
+      CFF_Font         cff;
+      CFF_FontRecDict  dict;
+      FT_Memory        memory = face->root.memory;
+      FT_Face          root;
+      FT_Int32         flags;
 
 
       if ( FT_NEW( cff ) )
@@ -360,23 +361,24 @@
       root             = &face->root;
       root->num_glyphs = cff->num_glyphs;
 
+      dict = &cff->top_font.font_dict;
+
+      /* we need the `PSNames' module for CFF and CEF formats */
+      /* which aren't CID-keyed                               */
+      if ( dict->cid_registry == 0xFFFFU && !psnames )
+      {
+        FT_ERROR(( "cff_face_init:" ));
+        FT_ERROR(( " cannot open CFF & CEF fonts\n" ));
+        FT_ERROR(( "              " ));
+        FT_ERROR(( " without the `PSNames' module\n" ));
+        goto Bad_Format;
+      }
+
       if ( pure_cff )
       {
-        CFF_FontRecDict  dict = &cff->top_font.font_dict;
-        char*            style_name;
+        char*  style_name;
 
 
-        /* we need the `PSNames' module for pure-CFF and CEF formats */
-        /* which aren't CID-keyed                                    */
-        if ( dict->cid_registry == 0xFFFFU && !psnames )
-        {
-          FT_ERROR(( "cff_face_init:" ));
-          FT_ERROR(( " cannot open CFF & CEF fonts\n" ));
-          FT_ERROR(( "              " ));
-          FT_ERROR(( " without the `PSNames' module\n" ));
-          goto Bad_Format;
-        }
-
         /* Set up num_faces. */
         root->num_faces = cff->num_faces;
 
@@ -483,12 +485,6 @@
           flags |= FT_FACE_FLAG_KERNING;
 #endif
 
-#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
-        /* CID-keyed CFF fonts don't have glyph names */
-        if ( dict->cid_registry == 0xFFFFU )
-          flags |= FT_FACE_FLAG_GLYPH_NAMES;
-#endif
-
         root->face_flags = flags;
 
         /*******************************************************************/
@@ -515,6 +511,13 @@
         root->style_flags = flags;
       }
 
+#ifndef FT_CONFIG_OPTION_NO_GLYPH_NAMES
+      /* CID-keyed CFF fonts don't have glyph names -- the SFNT loader */
+      /* has unset this flag because of the 3.0 `post' table           */
+      if ( dict->cid_registry == 0xFFFFU )
+        root->face_flags |= FT_FACE_FLAG_GLYPH_NAMES;
+#endif
+
       /*******************************************************************/
       /*                                                                 */
       /* Compute char maps.                                              */
diff --git a/src/cff/cfftypes.h b/src/cff/cfftypes.h
index 83b7d19..4508d98 100644
--- a/src/cff/cfftypes.h
+++ b/src/cff/cfftypes.h
@@ -123,7 +123,7 @@
     FT_Long    cid_font_version;
     FT_Long    cid_font_revision;
     FT_Long    cid_font_type;
-    FT_Long    cid_count;
+    FT_ULong   cid_count;
     FT_ULong   cid_uid_base;
     FT_ULong   cid_fd_array_offset;
     FT_ULong   cid_fd_select_offset;
diff --git a/src/cff/rules.mk b/src/cff/rules.mk
index 579f144..4100c80 100644
--- a/src/cff/rules.mk
+++ b/src/cff/rules.mk
@@ -34,6 +34,7 @@
 #
 CFF_DRV_H := $(CFF_DRV_SRC:%.c=%.h) \
              $(CFF_DIR)/cfftoken.h  \
+             $(CFF_DIR)/cfftypes.h  \
              $(CFF_DIR)/cfferrs.h