]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-def.cc
* scm/chord-name.scm: remove new-chord-name-brew-molecule ; use
[lilypond.git] / lily / paper-def.cc
index 03a4b322f88aacd4edb36b9ad6705913289b70ee..4d59d1f763b464eafebef2dd5640672f36409d3c 100644 (file)
@@ -3,11 +3,13 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c)  1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+
 #include <math.h>
 
+#include "virtual-font-metric.hh"
 #include "all-font-metrics.hh"
 #include "string.hh"
 #include "misc.hh"
@@ -16,8 +18,9 @@
 #include "scaled-font-metric.hh"
 #include "main.hh"
 #include "scm-hash.hh"
-#include "file-results.hh" // urg? header_global
+#include "input-file-results.hh" // urg? header_global
 #include "paper-outputter.hh"
+#include "ly-modules.hh"
 
 /*
   This is an almost empty thing. The only substantial thing this class
@@ -39,50 +42,15 @@ Paper_def::Paper_def (Paper_def const&src)
 }
 
 
-Real
-Paper_def::get_var (String s) const
-{
-  return get_realvar (ly_symbol2scm (s.to_str0 ()));
-}
-
-SCM
-Paper_def::get_scmvar (String s) const
-{
-  return variable_tab_->get (ly_symbol2scm (s.to_str0 ()));
-}
-
-
-SCM
-Paper_def::get_scmvar_scm (SCM sym) const
-{
-  return  gh_double2scm (get_realvar (sym));
-}
 
 Real
 Paper_def::get_realvar (SCM s) const
 {
-  SCM val ;
-  if (!variable_tab_->try_retrieve (s, &val))
-    {
-      programming_error ("unknown paper variable: " +  ly_symbol2string (s));
-      return 0.0;
-    }
-
-  Real sc = 1.0;
-  SCM ssc;
-  if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
-    {
-      sc = gh_scm2double (ssc);
-    }
-  if (gh_number_p (val))
-    {
-      return gh_scm2double (val) / sc;
-    }
-  else
-    {
-      programming_error ("not a real variable");
-      return 0.0;
-    }
+  SCM val = lookup_variable (s);
+  SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
+  
+  Real sc = gh_scm2double (scale);
+  return gh_scm2double (val) / sc;
 }
 
 /*
@@ -92,14 +60,13 @@ Paper_def::get_realvar (SCM s) const
 Interval
 Paper_def::line_dimensions_int (int n) const
 {
-  Real lw =  get_var ("linewidth");
-  Real ind = n? 0.0:get_var ("indent");
+  Real lw =  get_realvar (ly_symbol2scm ("linewidth"));
+  Real ind = n? 0.0:get_realvar (ly_symbol2scm ("indent"));
 
   return Interval (ind, lw);
 }
 
 
-
 int Paper_def::score_count_ = 0;
 
 int
@@ -126,7 +93,7 @@ Paper_def::get_paper_outputter ()
   Paper_outputter * po = new Paper_outputter (outname);
   Path p = split_path (outname);
   p.ext = "";
-  po->basename_ = p.string ();
+  po->basename_ = p.to_string ();
   return po;
 }
 
@@ -143,19 +110,29 @@ Paper_def::find_font (SCM fn, Real m)
   if (gh_pair_p (met))
     return unsmob_metrics (ly_cdr (met));
 
-  SCM ssc;
-  if (variable_tab_->try_retrieve (ly_symbol2scm ("outputscale"), &ssc))
+  /*
+    Hmm. We're chaining font - metrics. Should consider wether to merge
+    virtual-font and scaled_font.
+   */
+  Font_metric*  f=0;
+  if (gh_list_p (fn))
     {
-      m /= gh_scm2double (ssc);
+      f = new Virtual_font_metric (fn, m, this);
     }
-  
-  Font_metric*  f = all_fonts_global->find_font (ly_scm2string (fn));
-  SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
-  scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
+  else
+    {
+      SCM scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
+
+      m /= gh_scm2double (scm_variable_ref (scale_var));
 
-  scm_gc_unprotect_object (val);
+      f = all_fonts_global->find_font (ly_scm2string (fn));
+      SCM val = Scaled_font_metric::make_scaled_font_metric (f, m);
+      scaled_fonts_ = scm_acons (key, val, scaled_fonts_);
+      f = unsmob_metrics (val);
+      scm_gc_unprotect_object (val);
+    }
 
-  return dynamic_cast<Scaled_font_metric*> (unsmob_metrics (val));
+  return f;
 }
 
 
@@ -175,3 +152,11 @@ Paper_def::font_descriptions ()const
     }
   return l;
 }
+
+Paper_def* 
+unsmob_paper (SCM x)
+{
+  return dynamic_cast<Paper_def*> (unsmob_music_output_def (x));
+}
+
+