]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/afm.cc
*** empty log message ***
[lilypond.git] / lily / afm.cc
index f09d63bad58ce915cad52de595cfcbc345318fdd..5510c8fe75e0956af51decd139f554a9f91937ee 100644 (file)
@@ -1,21 +1,28 @@
 /*   
   afm.cc --  implement Adobe_font_metric
   
-  source file of the Flower Library
+  source file of the GNU LilyPond music typesetter
   
-  (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
+
+#ifndef _GNU_SOURCE // we want memmem
+#define _GNU_SOURCE
+#endif
+#include <string.h>
+#include "libc-extension.hh"
 #include "afm.hh"
 #include "warn.hh"
 #include "molecule.hh"
+#include "dimensions.hh"
 
 Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
 {
   checksum_ = 0;
   font_inf_ = fi;
 
-  for (int i= 256; i--;)
+  for (int i= 256  >? fi->numOfChars; i--;)
     ascii_to_metric_idx_.push (-1);
   
   for (int i=0; i < fi->numOfChars; i++)
@@ -71,7 +78,7 @@ Adobe_font_metric::find_char_metric (String nm, bool warn) const
     {
       if (warn)
        {
-         warning (_f ("can't find character called: `%s'", nm.ch_C ()));
+         warning (_f ("can't find character called: `%s'", nm.to_str0 ()));
        }
       return 0;
     }
@@ -82,7 +89,7 @@ Adobe_font_metric::find_char_metric (String nm, bool warn) const
 int
 Adobe_font_metric::count () const
 {
-  return ascii_to_metric_idx_.size ();
+  return font_inf_->numOfChars ;
 }
 
 Box
@@ -100,28 +107,39 @@ Adobe_font_metric::get_char (int code) const
 SCM
 read_afm_file (String nm)
 {
-  FILE *f = fopen (nm.ch_C () , "r");
+  FILE *f = fopen (nm.to_str0 () , "r");
   char s[2048];
-  char *check_key = "TfmCheckSum"; 
-  fgets (s, sizeof (s), f);
-
-  unsigned int cs = 0;  
-  if (strncmp (s, check_key, strlen (check_key)) == 0)
-    {
-      sscanf (s + strlen (check_key), "%ud", &cs);
-    }
-  else
+  char *check_key = "Comment TfmCheckSum";
+
+  unsigned int cs = 0;
+
+#if 0
+  fread (s, sizeof (s), sizeof (*s), f);
+  if (char const* p = (char const *)
+      memmem (s, sizeof (s), check_key, strlen (check_key)))
+    sscanf (p + strlen (check_key), "%ud", &cs);
+#else
+  s[0] = 0;
+  /* Assume check_key in first 10 lines */
+  for (int i = 0; i < 10; i++)
     {
-      rewind (f);
+      fgets (s, sizeof (s), f);
+      if (strncmp (s, check_key, strlen (check_key)) == 0)
+       {
+         sscanf (s + strlen (check_key), "%ud", &cs);
+         break;
+       }
     }
-
+#endif
+  
+  rewind (f);
     
   AFM_Font_info * fi;
   int ok = AFM_parseFile (f, &fi, ~1);
 
   if (ok)
     {
-      error (_f ("Error parsing AFM file: `%s'", nm.ch_C ()));
+      error (_f ("Error parsing AFM file: `%s'", nm.to_str0 ()));
       exit (2);
     }
   fclose (f);
@@ -129,12 +147,16 @@ read_afm_file (String nm)
   return Adobe_font_metric::make_afm (fi, cs);
 }
 
-  
+
+/*
+  actually, AFMs will be printers point, usually, but our .py script dumps
+  real points.
+ */
 Box
 afm_bbox_to_box (AFM_BBox bb)
 {
-  return Box (Interval (bb.llx, bb.urx)* (1/1000.0),
-             Interval (bb.lly, bb.ury)* (1/1000.0));
+  return Box (Interval (bb.llx, bb.urx)* (1/1000.0) PT,
+             Interval (bb.lly, bb.ury)* (1/1000.0) PT);
 
 }
   
@@ -154,13 +176,17 @@ Adobe_font_metric::find_by_name (String s) const
 
   if (!cm)
     {
+      /*
+       Why don't we return empty?
+       */
+      
       Molecule m;
       m.set_empty (false);
       return m;
     }
   
-  SCM at = (scm_listify (ly_symbol2scm ("char"),
-                     gh_int2scm (cm->code),
+  SCM at = (scm_list_n (ly_symbol2scm ("char"),
+                     scm_int2num (cm->code),
                      SCM_UNDEFINED));
   
   //  at= fontify_atom ((Font_metric*)this, at);