]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/afm.cc
patch::: 1.3.136.jcn2
[lilypond.git] / lily / afm.cc
index 1f1d22f1dbfde2f059603aeaffbc7c3e463f36f5..746c6eb123b5f4da5e857230bb3efa61af168d64 100644 (file)
@@ -1,16 +1,18 @@
 /*   
-  afm2.cc --  implement Adobe_font_metric
+  afm.cc --  implement Adobe_font_metric
   
   source file of the Flower Library
   
-  (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 #include "afm.hh"
 #include "warn.hh"
+#include "molecule.hh"
 
 Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
 {
+  checksum_ = 0;
   font_inf_ = fi;
 
   for (int i= 256; i--;)
@@ -24,7 +26,16 @@ Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
       name_to_metric_dict_[c->name] = i;
     }
 }
-  
+
+
+SCM
+Adobe_font_metric::make_afm (AFM_Font_info *fi, unsigned int checksum)
+{
+  Adobe_font_metric * fm = new Adobe_font_metric (fi);
+  fm->checksum_ = checksum;
+  return fm->self_scm();    
+}
+
 
 AFM_CharMetricInfo const *
 Adobe_font_metric::find_ascii_metric (int a , bool warn) const
@@ -64,32 +75,47 @@ Adobe_font_metric::find_char_metric (String nm, bool warn) const
 
 
 Box
-Adobe_font_metric::get_char (int code, bool warn) const
+Adobe_font_metric::get_char (int code) const
 {
   AFM_CharMetricInfo const
-    * c =  find_ascii_metric (code,warn);
+    * c =  find_ascii_metric (code,false);
+  Box b (Interval (0,0),Interval(0,0));
   if (c)
-    return afm_bbox_to_box (c->charBBox);                      
-  else
-    return Box (Interval (0,0),Interval(0,0));
+    b = afm_bbox_to_box (c->charBBox);                 
+
+  return b;
 }
 
-Adobe_font_metric*
+SCM
 read_afm_file (String nm)
 {
   FILE *f = fopen (nm.ch_C() , "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
+    {
+      rewind (f);
+    }
 
+    
   AFM_Font_info * fi;
   int ok = AFM_parseFile (f, &fi, ~1);
 
   if (ok)
     {
-      error (_("Error parsing AFM file"));
+      error (_f ("Error parsing AFM file: %s", nm.ch_C ()));
       exit (2);
     }
   fclose (f);
 
-  return new Adobe_font_metric (fi);
+  return Adobe_font_metric::make_afm (fi, cs);
 }
 
   
@@ -106,3 +132,28 @@ Adobe_font_metric::~Adobe_font_metric ()
 {
   AFM_free (font_inf_);
 }
+
+/*
+  return a molecule, without fontification 
+ */
+Molecule
+Adobe_font_metric::find_by_name (String s) const
+{
+  AFM_CharMetricInfo const *cm = find_char_metric (s, false);
+
+  if (!cm)
+    {
+      Molecule m;
+      m.set_empty (false);
+      return m;
+    }
+  
+  SCM at =  (gh_list (ly_symbol2scm ("char"),
+                     gh_int2scm (cm->code),
+                     SCM_UNDEFINED));
+  
+  //  at= fontify_atom ((Font_metric*)this, at);
+  Box b = afm_bbox_to_box (cm->charBBox);
+
+  return Molecule (b, at);
+}