]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/pango-font.cc
Fix some bugs in the dynamic engraver and PostScript backend
[lilypond.git] / lily / pango-font.cc
index 6419187dbf018b47d809603b3de61313488280e2..73ea7426a65ea4a6bf498d1c9881a4bd138ae7ec 100644 (file)
@@ -92,9 +92,9 @@ void
 get_unicode_name (char*s, FT_ULong code)
 {
   if (code > 0xFFFF)
-    sprintf (s,  "u%06lX", char_code);
+    sprintf (s,  "u%lX", code);
   else
-    sprintf (s,  "uni%04lX", char_code);
+    sprintf (s,  "uni%04lX", code);
 }
 
 
@@ -140,7 +140,8 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str) const
   SCM *tail = &glyph_exprs;
       
   Index_to_charcode_map const *cmap = 0;
-  if  (! (ftface->face_flags & FT_FACE_FLAG_GLYPH_NAMES))
+  bool has_glyph_names = ftface->face_flags & FT_FACE_FLAG_GLYPH_NAMES;
+  if  (! has_glyph_names)
     cmap = ((Pango_font*)this)->get_index_to_charcode_map (file_name, ftface);
   
   bool cid_keyed = false;
@@ -151,23 +152,39 @@ Pango_font::pango_item_string_stencil (PangoItem const *item, string str) const
       PangoGlyph pg = pgi->glyph;
       PangoGlyphGeometry ggeo = pgi->geometry;
 
-      FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN);
+      glyph_name[0] = '\0';
+      if (has_glyph_names)
+       {
+         int errorcode = FT_Get_Glyph_Name (ftface, pg, glyph_name, GLYPH_NAME_LEN);
+         if (errorcode)
+           programming_error ("FT_Get_Glyph_Name returns error");
+       }
+      
+      SCM char_id = SCM_EOL;
+      if (glyph_name[0] == '\0'
+         && cmap
 
-      SCM char_id;
-      if (glyph_name[0] == '\0' && cmap)
+         /* Ugh should ask FreeType about font type. */
+         && (file_name.find (".ttf") != NPOS
+             || file_name.find (".TTF") != NPOS))
        {
          FT_ULong char_code = cmap->find (pg)->second;
          get_unicode_name (glyph_name, char_code);
        }
-      
-  
+
+      if (glyph_name[0] ==  '\0' && has_glyph_names)
+       {
+         programming_error ("Glyph has no name, but font supports glyph naming. Skipping glyph.");
+         continue;
+       }
+         
       if (glyph_name[0] == '\0')
        {
          /*
            CID entry
          */
          cid_keyed = true;
-         char_id = scm_from_int (pg);
+         char_id = scm_from_uint32 (pg);
        }
       else
        char_id = scm_makfrom0str (glyph_name);