]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/ttf.cc
thinko
[lilypond.git] / lily / ttf.cc
index 0e5526f8e1727a7b5d3bbc79f2f562652fe2fe86..095de80ab1ff0710db1147ae08345902e0ab75b5 100644 (file)
@@ -3,14 +3,13 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 2005--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
 */
 
 #include "freetype.hh"
 
 #include <freetype/tttables.h>
 
-#include "lily-proto.hh"
 #include "memory-stream.hh"
 #include "warn.hh"
 #include "lily-guile.hh"
@@ -26,7 +25,7 @@ make_index_to_charcode_map (FT_Face face)
   FT_UInt gindex;
 
   FT_CharMap current_cmap = face->charmap;
-  FT_Select_Charmap(face, FT_ENCODING_UNICODE);
+  FT_Select_Charmap (face, FT_ENCODING_UNICODE);
 
   int j = 0;
   for (charcode = FT_Get_First_Char (face, &gindex); gindex != 0;
@@ -53,7 +52,7 @@ print_header (void *out, FT_Face face)
     = (TT_Postscript *) FT_Get_Sfnt_Table (face, ft_sfnt_post);
 
   if (pt->maxMemType42)
-    lily_cookie_fprintf (out, "%%%%VMUsage: %ld %ld\n", 0, 0);
+    lily_cookie_fprintf (out, "%%%%VMUsage: %d %d\n", 0, 0);
 
   lily_cookie_fprintf (out, "%d dict begin\n", 11);
   lily_cookie_fprintf (out, "/FontName /%s def\n",
@@ -75,8 +74,8 @@ print_header (void *out, FT_Face face)
   lily_cookie_fprintf (out, "/FontType 42 def\n");
   lily_cookie_fprintf (out, "/FontInfo 8 dict dup begin\n");
   lily_cookie_fprintf (out, "/version (%d.%d) def\n",
-                      (ht->Font_Revision >> 16),
-                      (ht->Font_Revision &((1 << 16) -1)));
+                      int (ht->Font_Revision >> 16),
+                      int (ht->Font_Revision &((1 << 16) -1)));
 
 #if 0
   if (strings[0])
@@ -145,6 +144,52 @@ print_body (void *out, string name)
   fclose (fd);
 }
 
+#if 0
+static
+void t42_write_sting (void *out, unsigned char const * buffer, size_t s)
+{
+  lily_cookie_fprintf (out, "\n<");
+  int l = 0;
+  static char xdigits[] = "0123456789ABCDEF";
+  for (size_t j = 0; j < s; j++)
+    {
+      if (j != 0 && j % 36 == 0)
+       lily_cookie_putc ('\n', out);
+
+      if (l ++ >= CHUNKSIZE)
+       lily_cookie_fprintf (out, "00>\n<");
+
+      /* lily_cookie_fprintf (out,"%02X",(int)buffer[j]) is too slow */
+      lily_cookie_putc (xdigits[ (buffer[j] & 0xF0) >> 4], out);
+      lily_cookie_putc (xdigits[buffer[j] & 0x0F], out);
+    }
+  lily_cookie_fprintf (out, "00>");    /* Adobe bug? */
+}
+
+
+static void
+new_print_body (void *out,  FT_Face face)
+{
+  FT_UInt idx = 0;
+
+  FT_ULong tag, length;
+  
+  lily_cookie_fprintf (out, "/sfnts [");
+  while (FT_Sfnt_Table_Info(face, idx, &tag, &length)!=
+        FT_Err_Table_Missing)
+    {
+      unsigned char *buf = new unsigned char[length];
+      FT_Error error = FT_Load_Sfnt_Table(face, tag, 0, buf, NULL); 
+
+      t42_write_sting (out, buf, length);
+
+      delete[] buf;
+      idx ++;
+    }
+  lily_cookie_fprintf (out, "\n] def\n");
+}
+#endif
+
 static void
 print_trailer (void *out,
               FT_Face face)
@@ -169,7 +214,7 @@ print_trailer (void *out,
                                              GLYPH_NAME_LEN);
          if (error)
            {
-             programming_error ("print_trailer(): FT_Get_Glyph_Name() returned error");
+             programming_error ("FT_Get_Glyph_Name (): error.");
              glyph_name[0] = 0;
            }
        }
@@ -213,6 +258,7 @@ create_type42_font (void *out, string name)
   FT_Face face = open_ft_face (name);
 
   print_header (out, face);
+  // new_print_body (out, face);
   print_body (out, name);
   print_trailer (out, face);
 
@@ -224,15 +270,14 @@ 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");
+  LY_ASSERT_TYPE (scm_is_string, ttf_file_name, 1);
   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 : "");
+  SCM ps_name = scm_from_locale_string (ps_name_str0 ? ps_name_str0 : "");
   
   FT_Done_Face (face);
   
@@ -244,13 +289,12 @@ LY_DEFINE (ly_ttf_ps_name, "ly:ttf-ps-name",
 
 
 
-LY_DEFINE (ly_ttf_to_pfa, "ly:ttf->pfa",
+LY_DEFINE (ly_ttf_2_pfa, "ly:ttf->pfa",
           1, 0, 0, (SCM ttf_file_name),
           "Convert the contents of a TTF file to Type42 PFA, returning it as "
           " a string.")
 {
-  SCM_ASSERT_TYPE (scm_is_string (ttf_file_name), ttf_file_name,
-                  SCM_ARG1, __FUNCTION__, "string");
+  LY_ASSERT_TYPE (scm_is_string, ttf_file_name, 1);
 
   string file_name = ly_scm2string (ttf_file_name);
   if (be_verbose_global)