]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/lookup.cc
release: 1.3.0
[lilypond.git] / lily / lookup.cc
index cc9466bc12dae5be0c80b1ad31c24f9003a16aa7..1181e03925052b1f0f3b374dac7c2f358cb150ef 100644 (file)
   TODO
       Glissando
 */
-
+#include <math.h>
 #include <ctype.h>
 #include "lookup.hh"
 #include "debug.hh"
 #include "dimensions.hh"
-#include "scalar.hh"
+
 #include "paper-def.hh"
 #include "string-convert.hh"
 #include "file-path.hh"
@@ -96,13 +96,13 @@ Lookup::afm_find (String s, bool warn) const
 {
   if (!afm_l_)      
     {
-      Lookup * me =     (Lookup*)(this);
+      Lookup * me = (Lookup*)(this);
       me->afm_l_ = all_fonts_global_p->find_afm (font_name_);
       if (!me->afm_l_)
        {
-         warning (_f("Can't open `%s'\n", font_name_));
-         warning (_f("Search path %s\n", global_path.str ().ch_C()));
-         error (_f("Aborting"));
+         warning (_f ("Can't find font: `%s'", font_name_));
+         warning (_f ("(search path: `%s')", global_path.str ().ch_C()));
+         error (_ ("Aborting"));
        }
     }
   Adobe_font_char_metric cm = afm_l_->find_char (s, warn);
@@ -132,6 +132,8 @@ Lookup::notehead (int j, String type) const
 {
   if (j > 2)
     j = 2;
+  if (type == "harmonic" || type == "cross")
+    j = 2;
 
   return afm_find (String ("noteheads-") + to_str (j) + type);
 }
@@ -361,7 +363,7 @@ Lookup::filledbox (Box b ) const
 /**
    Magnification steps.  These are powers of 1.2. The numbers are
  taken from Knuth's plain.tex: */
-static Real mag_steps[] = {1, 1, 1.200, 1.440, 1.7280,  2.074, 2.488};
+
 
 /**
    TODO: THIS IS UGLY.  Since the user has direct access to TeX
@@ -381,16 +383,19 @@ Lookup::text (String style, String text, Paper_def *paper_l) const
     {
       font_h = paper_l->get_var ("font_" + style);
     }
-   
+
+
+  Real realmag = 1.0;
   if (paper_l->scope_p_->elem_b ("magnification_" + style))
     {
       font_mag = (int)paper_l->get_var ("magnification_" + style);
+      realmag = pow (1.2, font_mag);
     }
 
   /*
     UGH.
   */
-  SCM l = gh_eval_str (("(style-to-cmr \"" + style + "\")").ch_C());
+  SCM l = ly_ch_C_eval_scm (("(style-to-cmr \"" + style + "\")").ch_C());
   if (l != SCM_BOOL_F)
     {
       style = ly_scm2string (SCM_CDR(l)) +to_str  ((int)font_h);
@@ -400,7 +405,7 @@ Lookup::text (String style, String text, Paper_def *paper_l) const
   Interval ydims (0,0);
 
   Font_metric* afm_l = all_fonts_global_p->find_font (style);
-  DOUT << "\nChars: ";
+  DEBUG_OUT << "\nChars: ";
 
 
   int brace_count =0;
@@ -419,23 +424,20 @@ Lookup::text (String style, String text, Paper_def *paper_l) const
            brace_count ++;
          else if (text[i] == '}')
            brace_count --;
-          Character_metric *c = afm_l->get_char ((unsigned char)text[i],false);
+          Character_metric *c = (Character_metric*)afm_l->
+           get_char ((unsigned char)text[i],false);
 
+         // Ugh, use the width of 'x' for unknown characters
+         if (c->dimensions()[X_AXIS].length () == 0) 
+           c = (Character_metric*)afm_l->get_char ((unsigned char)'x',false);
          w += c->dimensions()[X_AXIS].length ();
          ydims.unite (c->dimensions()[Y_AXIS]);
        }
     }
 
-  if (font_mag > 1 && font_mag < 7 )
-    {
-      /* UGH  */ 
-      w *= mag_steps[font_mag];
-      ydims *= mag_steps[font_mag];
-    }
-
   if(brace_count)
     {
-      warning (_f ("Non-matching braces in text `%s', adding braces.", text.ch_C()));
+      warning (_f ("Non-matching braces in text `%s', adding braces", text.ch_C()));
 
       if (brace_count < 0)
        {
@@ -447,14 +449,13 @@ Lookup::text (String style, String text, Paper_def *paper_l) const
        }
     }
 
-  
-  DOUT << "\n" << to_str (w) << "\n";
-  m.dim_.x () = Interval (0, w);
+  ydims *= realmag;
+  m.dim_.x () = Interval (0, w*realmag);
   m.dim_.y () = ydims;
 
   
   Atom at  (gh_list (text_scm_sym,
-                    gh_str02scm (text.ch_C()),
+                    ly_ch_C_to_scm (text.ch_C()),
                     SCM_UNDEFINED));
   at.font_ = ly_symbol (style);
   at.magn_ = gh_int2scm (font_mag);