]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/afm.cc
* make/lilypond.fedora.spec.in (Group): add lilypond-internals to
[lilypond.git] / lily / afm.cc
index e0961d7f456e5b74ab55b94995fe3c1ef9d4ec0d..95f138090abc29bace0eda1fa066ff1ab8f0ae75 100644 (file)
@@ -1,15 +1,15 @@
-/*   
-  afm.cc --  implement Adobe_font_metric
-  
+/*
+  afm.cc -- implement Adobe_font_metric
+
   source file of the GNU LilyPond music typesetter
-  
-  (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
+
+  (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
 
 #include "afm.hh"
 
 #include <cstring>
+using namespace std;
 
 #include "warn.hh"
 #include "libc-extension.hh"
@@ -20,16 +20,16 @@ Adobe_font_metric::Adobe_font_metric (AFM_Font_info *fi)
   checksum_ = 0;
   font_info_ = fi;
   design_size_ = 1.0;
-  
-  for (int i = 256 >? fi->numOfChars; i--;)
+
+  for (int i = max (256, fi->numOfChars); i--;)
     ascii_to_metric_idx_.push (-1);
-  
-  for (int i=0; i < fi->numOfChars; i++)
+
+  for (int i = 0; i < fi->numOfChars; i++)
     {
-      AFM_CharMetricInfo * c = fi->cmi + i;
+      AFM_CharMetricInfo *c = fi->cmi + i;
 
       /* Some TeX afm files contain code = -1.  We don't know why,
-       let's ignore it.  */
+        let's ignore it.  */
       if (c->code >= 0)
        ascii_to_metric_idx_[c->code] = i;
       name_to_metric_dict_[c->name] = i;
@@ -49,13 +49,13 @@ Adobe_font_metric::make_afm (AFM_Font_info *fi,
   Adobe_font_metric *fm = new Adobe_font_metric (fi);
   fm->checksum_ = checksum;
   fm->design_size_ = design_size;
-  return fm->self_scm ();    
+  return fm->self_scm ();
 }
 
-AFM_CharMetricInfo const*
+AFM_CharMetricInfo const *
 Adobe_font_metric::find_ascii_metric (int a) const
 {
-  if (ascii_to_metric_idx_[a] >=0)
+  if (ascii_to_metric_idx_[a] >= 0)
     {
       int code = ascii_to_metric_idx_[a];
       if (code >= 0)
@@ -64,7 +64,7 @@ Adobe_font_metric::find_ascii_metric (int a) const
   return 0;
 }
 
-AFM_CharMetricInfo const*
+AFM_CharMetricInfo const *
 Adobe_font_metric::find_char_metric (String nm) const
 {
   int idx = name_to_index (nm);
@@ -76,10 +76,10 @@ Adobe_font_metric::find_char_metric (String nm) const
 int
 Adobe_font_metric::name_to_index (String name) const
 {
-  std::map<String,int>::const_iterator ai = name_to_metric_dict_.find (name);
+  map<String, int>::const_iterator ai = name_to_metric_dict_.find (name);
   if (ai == name_to_metric_dict_.end ())
     return -1;
-  return (*ai).second; 
+  return (*ai).second;
 }
 
 int
@@ -94,7 +94,7 @@ Adobe_font_metric::get_ascii_char (int code) const
   AFM_CharMetricInfo const *c = find_ascii_metric (code);
   Box b (Interval (0, 0), Interval (0, 0));
   if (c)
-    b = afm_bbox_to_box (c->charBBox);         
+    b = afm_bbox_to_box (c->charBBox);
   return b;
 }
 
@@ -116,14 +116,14 @@ Adobe_font_metric::get_indexed_char (int code) const
 SCM
 read_afm_file (String nm)
 {
-  FILE *f = fopen (nm.to_str0 () , "r");
+  FILE *f = fopen (nm.to_str0 (), "r");
   char s[2048] = "";
   char *check_key = "Comment TfmCheckSum";
   char *size_key = "Comment DesignSize";
 
   unsigned int cs = 0;
   Real ds = 1.0;
-  
+
   /* Assume check_key in first 10 lines */
   for (int i = 0; i < 10; i++)
     {
@@ -133,17 +133,14 @@ read_afm_file (String nm)
       else if (strncmp (s, size_key, strlen (size_key)) == 0)
        sscanf (s + strlen (size_key), "%lf", &ds);
     }
-  
+
   rewind (f);
-    
+
   AFM_Font_info *fi;
-  int ok = AFM_parseFile (f, &fi, ~0);
+  int e = AFM_parseFile (f, &fi, ~0);
 
-  if (ok)
-    {
-      error (_f ("Error parsing AFM file: `%s'", nm.to_str0 ()));
-      exit (2);
-    }
+  if (e)
+    error (_f ("parsing AFM file: `%s'", nm.to_str0 ()));
   fclose (f);
 
   return Adobe_font_metric::make_afm (fi, cs, ds);
@@ -152,7 +149,7 @@ read_afm_file (String nm)
 Box
 afm_bbox_to_box (AFM_BBox bb)
 {
-#if 1 /* Fine for feta; ec-fonts-mftraced do not have AFM :-(  */
+#if 1 /* Fine for feta; ec-fonts-mftraced do not have AFM.  */
   return Box (Interval (bb.llx, bb.urx) * 0.001 PT,
              Interval (bb.lly, bb.ury) * 0.001 PT);
 #else /* FIXME: about right for lmodern.  */
@@ -165,7 +162,7 @@ Offset
 Adobe_font_metric::get_indexed_wxwy (int k) const
 {
   AFM_CharMetricInfo const *mi = font_info_->cmi + k;
-#if 1 /* Fine for feta; ec-fonts-mftraced do not have AFM :-( */
+#if 1 /* Fine for feta; ec-fonts-mftraced do not have AFM */
   return Offset (mi->wx, mi->wy) * 0.001 PT;
 #else /* FIXME: about right for lmodern.  */
   return Offset (mi->wx, mi->wy) * 1.14 * 0.001 PT;
@@ -175,11 +172,11 @@ Adobe_font_metric::get_indexed_wxwy (int k) const
 Real
 Adobe_font_metric::design_size () const
 {
-  return design_size_;    
+  return design_size_;
 }
 
 String
-Adobe_font_metric::coding_scheme () const
+Adobe_font_metric::font_name () const
 {
-  return font_info_->gfi->encodingScheme;
+  return font_info_->gfi->fontName;
 }