]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/afm.cc
($(outdir)/%.pdf): add DVIPS_FLAGS. This will
[lilypond.git] / lily / afm.cc
index b20336967a0e75cdd069ab975d36333e9ecc0986..db6ff873172b5f1f7767ed92bb3207d76178c215 100644 (file)
@@ -3,18 +3,16 @@
   
   source file of the GNU LilyPond music typesetter
   
-  (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
   
  */
 
-#ifndef _GNU_SOURCE // we want memmem
-#define _GNU_SOURCE
-#endif
 #include <string.h>
+
+#include "warn.hh"             // error()
 #include "libc-extension.hh"
 #include "afm.hh"
-#include "warn.hh"
-#include "molecule.hh"
+#include "stencil.hh"
 #include "dimensions.hh"
 
 Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
@@ -51,7 +49,7 @@ Adobe_font_metric::make_afm (AFM_Font_info *fi, unsigned int checksum)
 
 
 AFM_CharMetricInfo const *
-Adobe_font_metric::find_ascii_metric (int a , bool warn) const
+Adobe_font_metric::find_ascii_metric (int a) const
 {
   if (ascii_to_metric_idx_[a] >=0)
     {
@@ -61,29 +59,31 @@ Adobe_font_metric::find_ascii_metric (int a , bool warn) const
          return font_inf_->cmi + code;
        }
     }
-  else if (warn)
-    {
-      warning (_f ("can't find character number: %d", a));
-    }
 
   return 0;
 }
 
+
+
 AFM_CharMetricInfo const *
-Adobe_font_metric::find_char_metric (String nm, bool warn) const
+Adobe_font_metric::find_char_metric (String nm) const
+{
+  int idx = name_to_index (nm);
+  if (idx >= 0)
+    return font_inf_->cmi+ idx;
+  else
+    return 0;
+}
+
+int
+Adobe_font_metric::name_to_index (String nm)const 
 {
   std::map<String,int>::const_iterator ai = name_to_metric_dict_.find (nm);
   
   if (ai == name_to_metric_dict_.end ())
-    {
-      if (warn)
-       {
-         warning (_f ("can't find character called: `%s'", nm.to_str0 ()));
-       }
-      return 0;
-    }
+    return -1;
   else
-    return font_inf_->cmi + (*ai).second;
+    return (*ai).second; 
 }
 
 int
@@ -93,10 +93,10 @@ Adobe_font_metric::count () const
 }
 
 Box
-Adobe_font_metric::get_char (int code) const
+Adobe_font_metric::get_ascii_char (int code) const
 {
   AFM_CharMetricInfo const
-    * c =  find_ascii_metric (code,false);
+    * c =  find_ascii_metric (code);
   Box b (Interval (0,0),Interval (0,0));
   if (c)
     b = afm_bbox_to_box (c->charBBox);                 
@@ -104,6 +104,16 @@ Adobe_font_metric::get_char (int code) const
   return b;
 }
 
+
+Box
+Adobe_font_metric::get_indexed_char (int code) const
+{
+  if (code>= 0)
+    return afm_bbox_to_box (font_inf_->cmi[code].charBBox);
+  else
+    return   Box (Interval (0,0),Interval (0,0));
+}
+
 SCM
 read_afm_file (String nm)
 {
@@ -113,12 +123,6 @@ read_afm_file (String nm)
 
   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++)
@@ -130,7 +134,6 @@ read_afm_file (String nm)
          break;
        }
     }
-#endif
   
   rewind (f);
     
@@ -159,7 +162,15 @@ afm_bbox_to_box (AFM_BBox bb)
              Interval (bb.lly, bb.ury)* (1/1000.0) PT);
 
 }
-  
+
+Offset
+Adobe_font_metric::get_indexed_wxwy (int k)const
+{
+  AFM_CharMetricInfo const *mi = font_inf_->cmi+ k;
+  return 1/1000.0 PT * Offset (mi->wx, mi->wy); 
+}
+
+
 
 Adobe_font_metric::~Adobe_font_metric ()
 {
@@ -167,12 +178,12 @@ Adobe_font_metric::~Adobe_font_metric ()
 }
 
 /*
-  return a molecule, without fontification 
+  return a stencil, without fontification 
  */
-Molecule
+Stencil
 Adobe_font_metric::find_by_name (String s) const
 {
-  AFM_CharMetricInfo const *cm = find_char_metric (s, false);
+  AFM_CharMetricInfo const *cm = find_char_metric (s);
 
   if (!cm)
     {
@@ -180,7 +191,7 @@ Adobe_font_metric::find_by_name (String s) const
        Why don't we return empty?
        */
       
-      Molecule m;
+      Stencil m;
       m.set_empty (false);
       return m;
     }
@@ -192,5 +203,5 @@ Adobe_font_metric::find_by_name (String s) const
   //  at= fontify_atom ((Font_metric*)this, at);
   Box b = afm_bbox_to_box (cm->charBBox);
 
-  return Molecule (b, at);
+  return Stencil (b, at);
 }