]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/afm.cc
* scm/output-gnome.scm (FIXME-glyph-string): New function. Cannot
[lilypond.git] / lily / afm.cc
index b0787ac362374440f98887a517a87c5327a69482..3c2d84f10537171bfe3b648b9ac4278f59fbff80 100644 (file)
   
  */
 
-#include <string.h>
+#include "afm.hh"
+
+#include <cstring>
 
-#include "warn.hh"             // error ()
+#include "warn.hh"
 #include "libc-extension.hh"
-#include "afm.hh"
-#include "stencil.hh"
 #include "dimensions.hh"
 
-Adobe_font_metric::Adobe_font_metric (AFM_Font_info * fi)
+Adobe_font_metric::Adobe_font_metric (AFM_Font_info *fi)
 {
   checksum_ = 0;
-  font_inf_ = fi;
-
+  font_info_ = fi;
   design_size_ = 1.0;
   
-  for (int i= 256  >? fi->numOfChars; i--;)
+  for (int i = 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;
 
-      /*
-       Some TeX afm files contain code = -1. We don't know why, let's
-       ignore it.
-       
-       */
+      /* Some TeX afm files contain code = -1.  We don't know why,
+       let's ignore it.  */
       if (c->code >= 0)
        ascii_to_metric_idx_[c->code] = i;
       name_to_metric_dict_[c->name] = i;
     }
 }
 
+Adobe_font_metric::~Adobe_font_metric ()
+{
+  AFM_free (font_info_);
+}
 
 SCM
 Adobe_font_metric::make_afm (AFM_Font_info *fi,
                             unsigned int checksum,
                             Real design_size)
 {
-  Adobe_font_metric * fm = new Adobe_font_metric (fi);
+  Adobe_font_metric *fm = new Adobe_font_metric (fi);
   fm->checksum_ = checksum;
-  fm->design_size_ = design_size;
+  fm->design_size_ = design_size; 
   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)
-       {
-         return font_inf_->cmi + code;
-       }
+      if (code >= 0)
+       return font_info_->cmi + code;
     }
-
   return 0;
 }
 
-
-
-AFM_CharMetricInfo const *
+AFM_CharMetricInfo 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;
+    return font_info_->cmi + idx;
+  return 0;
 }
 
 int
-Adobe_font_metric::name_to_index (String nm)const 
+Adobe_font_metric::name_to_index (String name) const
 {
-  std::map<String,int>::const_iterator ai = name_to_metric_dict_.find (nm);
-  
+  std::map<String,int>::const_iterator ai = name_to_metric_dict_.find (name);
   if (ai == name_to_metric_dict_.end ())
     return -1;
-  else
-    return (*ai).second; 
+  return (*ai).second; 
 }
 
 int
 Adobe_font_metric::count () const
 {
-  return font_inf_->numOfChars ;
+  return font_info_->numOfChars;
 }
 
 Box
 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));
+  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;
 }
 
+int
+Adobe_font_metric::index_to_ascii (int code) const
+{
+  return font_info_->cmi[code].code;
+}
 
 Box
 Adobe_font_metric::get_indexed_char (int code) const
 {
-  if (code>= 0)
-    return afm_bbox_to_box (font_inf_->cmi[code].charBBox);
+  if (code >= 0)
+    return afm_bbox_to_box (font_info_->cmi[code].charBBox);
   else
-    return   Box (Interval (0,0),Interval (0,0));
+    return Box (Interval (0, 0), Interval (0, 0));
 }
 
 SCM
@@ -135,19 +129,15 @@ read_afm_file (String nm)
     {
       fgets (s, sizeof (s), f);
       if (strncmp (s, check_key, strlen (check_key)) == 0)
-       {
-         sscanf (s + strlen (check_key), "%ud", &cs);
-       }
+       sscanf (s + strlen (check_key), "%ud", &cs);
       else if (strncmp (s, size_key, strlen (size_key)) == 0)
-       {
-         sscanf (s + strlen (size_key), "%lf", &ds);
-       }
+       sscanf (s + strlen (size_key), "%lf", &ds);
     }
   
   rewind (f);
     
-  AFM_Font_info * fi;
-  int ok = AFM_parseFile (f, &fi, ~1);
+  AFM_Font_info *fi;
+  int ok = AFM_parseFile (f, &fi, ~0);
 
   if (ok)
     {
@@ -159,58 +149,43 @@ read_afm_file (String nm)
   return Adobe_font_metric::make_afm (fi, cs, ds);
 }
 
-
-/*
-  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) PT,
-             Interval (bb.lly, bb.ury)* (1/1000.0) PT);
-
+#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.  */
+  return Box (Interval (bb.llx, bb.urx) * 1.14 * 0.001 PT,
+             Interval (bb.lly, bb.ury) * 1.14 * 0.001 PT);
+#endif
 }
 
 Offset
-Adobe_font_metric::get_indexed_wxwy (int k)const
+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); 
+  AFM_CharMetricInfo const *mi = font_info_->cmi + k;
+#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;
+#endif
 }
 
-
-
-Adobe_font_metric::~Adobe_font_metric ()
+Real
+Adobe_font_metric::design_size () const
 {
-  AFM_free (font_inf_);
+  return design_size_;    
 }
 
-/*
-  return a stencil, without fontification 
- */
-Stencil
-Adobe_font_metric::find_by_name (String s) const
+String
+Adobe_font_metric::coding_scheme () const
 {
-  AFM_CharMetricInfo const *cm = find_char_metric (s);
-
-  if (!cm)
-    {
-      /*
-       Why don't we return empty?
-       */
-      
-      Stencil m;
-      m.set_empty (false);
-      return m;
-    }
-  
-  SCM at = (scm_list_n (ly_symbol2scm ("char"),
-                     scm_int2num (cm->code),
-                     SCM_UNDEFINED));
-  
-  //  at= fontify_atom ((Font_metric*)this, at);
-  Box b = afm_bbox_to_box (cm->charBBox);
+  return font_info_->gfi->encodingScheme;
+}
 
-  return Stencil (b, at);
+String
+Adobe_font_metric::font_name () const
+{
+  return font_info_->gfi->fontName;
 }