]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/ttf.cc
tie-details.hh
[lilypond.git] / lily / ttf.cc
index 170fbfb71967e3deb9cfaeeaec41a19a6c2a1027..82bc78dce28f2614fa85ab8b41b9c2e849915cfe 100644 (file)
@@ -3,7 +3,7 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "freetype.hh"
@@ -86,9 +86,9 @@ print_header (void *out, FT_Face face)
 #define CHUNKSIZE 65534
 
 static void
-print_body (void *out, String name)
+print_body (void *out, string name)
 {
-  FILE *fd = fopen (name.to_str0 (), "rb");
+  FILE *fd = fopen (name.c_str (), "rb");
 
   static char xdigits[] = "0123456789ABCDEF";
 
@@ -131,32 +131,63 @@ print_trailer (void *out,
     = (TT_MaxProfile *)FT_Get_Sfnt_Table (face, ft_sfnt_maxp);
 
   lily_cookie_fprintf (out, "/CharStrings %d dict dup begin\n", mp->numGlyphs);
-  for (int i = 0; i < mp->numGlyphs; i++)
-    {
-      FT_Error error = FT_Get_Glyph_Name (face, i, glyph_name, GLYPH_NAME_LEN);
 
-      if (error)
-       programming_error ("FT_Get_Glyph_Name() returned error");
-      else
-       lily_cookie_fprintf (out, "/%s %d def ", glyph_name, i);
 
-      if (! (i % 5))
-       lily_cookie_fprintf (out, "\n");
-    }
+  if (face->face_flags & FT_FACE_FLAG_GLYPH_NAMES)
+    for (int i = 0; i < mp->numGlyphs; i++)
+      {
+       FT_Error error = FT_Get_Glyph_Name (face, i, glyph_name,
+                                           GLYPH_NAME_LEN);
+       if (error)
+         programming_error ("print_trailer(): FT_Get_Glyph_Name() returned error");
+       else
+         lily_cookie_fprintf (out, "/%s %d def ", glyph_name, i);
+
+       if (! (i % 5))
+         lily_cookie_fprintf (out, "\n");
+      }
+
   lily_cookie_fprintf (out, "end readonly def\n");
   lily_cookie_fprintf (out, "FontName currentdict end definefont pop\n");
 }
 
 static void
-create_type42_font (void *out, String name)
+create_type42_font (void *out, string name)
 {
   FT_Face face = open_ft_face (name);
 
   print_header (out, face);
   print_body (out, name);
   print_trailer (out, face);
+
+  FT_Done_Face (face);
 }
 
+
+LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name",
+          1, 0, 0, (SCM ttf_file_name),
+          "Extract the PostScript name from a TrueType font.")
+{
+  SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name,
+                  SCM_ARG1, __FUNCTION__, "string");
+  string file_name = ly_scm2string (ttf_file_name);
+  if (be_verbose_global)
+    progress_indication ("[" + file_name);
+
+  FT_Face face = open_ft_face (file_name);
+  char const *ps_name_str0 = FT_Get_Postscript_Name (face);
+  SCM ps_name = scm_makfrom0str (ps_name_str0 ? ps_name_str0 : "");
+  
+  FT_Done_Face (face);
+  
+  if (be_verbose_global)
+    progress_indication ("]");
+  
+  return ps_name;
+}
+
+
+
 LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa",
           1, 0, 0, (SCM ttf_file_name),
           "Convert the contents of a TTF file to Type42 PFA, returning it as "
@@ -165,7 +196,7 @@ LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa",
   SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name,
                   SCM_ARG1, __FUNCTION__, "string");
 
-  String file_name = ly_scm2string (ttf_file_name);
+  string file_name = ly_scm2string (ttf_file_name);
   if (be_verbose_global)
     progress_indication ("[" + file_name);