]> git.donarmstrong.com Git - lilypond.git/commitdiff
(ly_bookpaper_fonts): move from Paperdef
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 16 May 2004 22:46:36 +0000 (22:46 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sun, 16 May 2004 22:46:36 +0000 (22:46 +0000)
(find_scaled_font): move from Paper_def

25 files changed:
ChangeLog
lily/book-paper-def.cc [new file with mode: 0644]
lily/book.cc
lily/font-select.cc
lily/include/book.hh
lily/include/dimensions.hh
lily/include/lily-proto.hh
lily/include/paper-def.hh
lily/include/paper-outputter.hh
lily/include/score.hh
lily/modified-font-metric.cc [new file with mode: 0644]
lily/my-lily-parser.cc
lily/paper-book.cc
lily/paper-def.cc
lily/paper-outputter.cc
lily/parser.yy
lily/scaled-font-metric.cc [deleted file]
lily/score.cc
ly/declarations-init.ly
po/fr.po
ps/music-drawing-routines.ps
scm/lily.scm
scm/output-ps.scm
scm/output-tex.scm
scm/paper.scm

index ca8d5171b32c9cb0e8db87b3faa564f964b8ddf2..b19dacdc71c43991ab12078484195efb88d9edf4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2004-05-17  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+
+       * lily/book-paper-def.cc (ly_bookpaper_fonts): move from Paperdef
+       (find_scaled_font): move from Paper_def
+
+2004-05-16  Han-Wen Nienhuys   <hanwen@xs4all.nl>
+
+       * lily/my-lily-parser.cc (LY_DEFINE): new function ly_parser_lookup
+       (LY_DEFINE): add SCM_ASSERT_TYPE everywhere.
+
+       * po/fr.po: update po.
+
+       * lily/include/book-paper-def.hh (class Book_paper_def): new file.
+
+       * lily/book-paper-def.cc (print_smob): new file.
+
 2004-05-16  Heikki Junes <hjunes@cc.hut.fi>
 
        * buildscripts/lilypond-words.py: search words also from
diff --git a/lily/book-paper-def.cc b/lily/book-paper-def.cc
new file mode 100644 (file)
index 0000000..e79b158
--- /dev/null
@@ -0,0 +1,196 @@
+/* 
+  book-paper-def.cc --  implement Book_paper_def
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
+  
+*/
+
+#include "paper-def.hh"
+#include "dimensions.hh"
+#include "book-paper-def.hh"
+#include "ly-smobs.icc"
+#include "font-metric.hh"
+#include "virtual-font-metric.hh"
+#include "scaled-font-metric.hh"
+
+IMPLEMENT_SMOBS (Book_paper_def);
+IMPLEMENT_DEFAULT_EQUAL_P (Book_paper_def);
+
+
+SCM
+Book_paper_def::mark_smob (SCM m)
+{
+  Book_paper_def * mo = (Book_paper_def*) SCM_CELL_WORD_1 (m);
+
+  return mo->scaled_fonts_;
+}
+
+Font_metric*
+Book_paper_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name)
+{
+  Real lookup_mag = m;
+  if (!dynamic_cast<Virtual_font_metric*> (f))
+    {
+      lookup_mag /= output_scale_;
+    }
+  
+  SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F);
+  if (sizes != SCM_BOOL_F)
+    {
+      SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
+      if (ly_c_pair_p (met))
+       return unsmob_metrics (ly_cdr (met));
+    }
+  else
+    sizes = SCM_EOL;
+  
+  /* Hmm. We're chaining font - metrics.  Should consider whether to
+     merge virtual-font and scaled_font.  */
+  SCM val = SCM_EOL;
+  if (Virtual_font_metric * vf = dynamic_cast<Virtual_font_metric*> (f))
+    {
+      /*
+       For fontify_atom (), the magnification and name must be known
+       at the same time. That's impossible for
+
+         Scaled (Virtual_font (Font1,Font2))
+
+       so we replace by
+
+         Virtual_font (Scaled (Font1), Scaled (Font2))
+
+      */
+      
+      SCM lst = SCM_EOL;
+      SCM *t = &lst;
+      for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s))
+       {
+         Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)),
+                                                 m, input_enc_name);
+         *t = scm_cons (scaled->self_scm (), SCM_EOL);
+         t = SCM_CDRLOC(*t);
+       }
+
+      vf = new Virtual_font_metric (lst);
+      val = vf->self_scm ();
+    }
+  else
+    {
+      if (!ly_c_symbol_p (input_enc_name))
+       {
+#if 0
+         /* FIXME.*/
+         SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding"));
+         input_enc_name = scm_variable_ref (var);
+      
+#endif
+         input_enc_name = ly_symbol2scm ("latin1"); 
+       }
+
+      val = Modified_font_metric::make_scaled_font_metric (input_enc_name,
+                                                          f, lookup_mag);
+    }
+
+  sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
+  scm_gc_unprotect_object (val);
+  scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes);
+  return unsmob_metrics (val);
+}
+
+
+
+Book_paper_def::Book_paper_def ()
+{
+  output_scale_ = 1.0;
+  scaled_fonts_ = SCM_EOL;
+  smobify_self ();
+  scaled_fonts_ = scm_c_make_hash_table (11);
+}
+
+Book_paper_def::~Book_paper_def ()
+{
+}
+
+
+
+
+LY_DEFINE(ly_make_bookpaper, "ly:make-bookpaper",
+         1,0,0,
+         (SCM size),
+         "Make a paperbook, for staff space SIZE, which is in INTERNAL_UNIT.") 
+{
+  Book_paper_def * bp = new Book_paper_def ;
+
+  SCM_ASSERT_TYPE(ly_c_number_p (size), size,
+                 SCM_ARG1, __FUNCTION__, "number");
+
+  
+  bp->output_scale_ = (ly_scm2double (size)) MM;
+  
+  return scm_gc_unprotect_object (bp->self_scm ());
+}
+
+
+LY_DEFINE(ly_bookpaper_fonts, "ly:bookpaper-fonts",
+         1,0,0,
+         (SCM bp),
+         "Return fonts scaled up BP")
+{
+  Book_paper_def * b = unsmob_bookpaper (bp);
+
+  SCM_ASSERT_TYPE(b, bp,
+                 SCM_ARG1, __FUNCTION__, "bookpaper");
+
+  SCM func = ly_scheme_function ("hash-table->alist");
+
+  SCM l = SCM_EOL;
+  for (SCM s = scm_call_1 (func, b->scaled_fonts_); ly_c_pair_p (s); s = ly_cdr (s))
+    {
+      SCM entry = ly_car (s);
+      for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t  = ly_cdr (t))
+       {
+         Font_metric *fm= unsmob_metrics (ly_cdar (t));
+
+         if (dynamic_cast<Modified_font_metric*> (fm))
+           l = scm_cons (fm->self_scm (), l);
+       }
+    }
+  return l;
+}
+
+
+LY_DEFINE(ly_bookpaper_outputscale, "ly:bookpaper-outputscale",
+         1,0,0,
+         (SCM bp),
+         "Get outputscale for BP.")
+{
+  Book_paper_def * b = unsmob_bookpaper (bp);
+
+  SCM_ASSERT_TYPE(b, bp,
+                 SCM_ARG1, __FUNCTION__, "bookpaper");
+  return scm_make_real (b->output_scale_);
+}
+
+int
+Book_paper_def::print_smob (SCM s, SCM p, scm_print_state*)
+{
+  scm_puts ("#<Book_paper>", p);
+  return 1;
+}
+
+
+Paper_def * 
+Book_paper_def::scale_paper (Paper_def* pd) const
+{
+  SCM proc = ly_scheme_function ("scale-paper");
+  SCM new_pap = scm_call_2 (proc, pd->self_scm (), self_scm ());
+
+  scm_gc_protect_object (new_pap);
+
+  Paper_def* p = unsmob_paper (new_pap);
+  
+  p->bookpaper_ = (Book_paper_def*) this;
+  return p;
+}
index cf64b174555b0f0387267e45918a5e0a30650efb..4e804b7d52ee90e381df8336fb9de8ec0d655bcb 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 
+#include "book-paper-def.hh"
 #include "ly-smobs.icc"
 #include "stencil.hh"
 #include "book.hh"
@@ -27,6 +28,7 @@
 Book::Book ()
   : Input ()
 {
+  bookpaper_ = 0;
   header_ = SCM_EOL;
   assert (!scores_.size ());
   smobify_self ();
@@ -46,6 +48,9 @@ Book::mark_smob (SCM s)
   int score_count = book->scores_.size ();
   for (int i = 0; i < score_count; i++)
     scm_gc_mark (book->scores_[i]->self_scm ());
+
+  if (book->bookpaper_)
+    scm_gc_mark (book->bookpaper_->self_scm ());
   return book->header_;
 }
 
@@ -64,13 +69,15 @@ Book::process (String outname, Music_output_def *default_def, SCM header)
   for (int i = 0; i < score_count; i++)
     {
       Paper_def *paper = 0;
-      SCM systems = scores_[i]->book_rendering (outname, default_def, &paper);
+      SCM systems = scores_[i]->book_rendering (outname,
+                                               bookpaper_,
+                                               default_def, &paper);
       if (systems != SCM_UNDEFINED)
        {
          Score_lines sc;
          sc.paper_ = paper;
          sc.lines_ = systems;
-         sc.header_ =header;
+         sc.header_ = header;
 
          paper_book->score_lines_.push (sc);
        }
@@ -88,7 +95,9 @@ Book::to_stencil (Music_output_def *default_def, SCM header)
   for (int i = 0; i < score_count; i++)
     {
       Paper_def *paper = 0;
-      SCM systems = scores_[i]->book_rendering ("<markup>", default_def,
+      SCM systems = scores_[i]->book_rendering ("<markup>",
+                                               bookpaper_,
+                                               default_def,
                                                &paper);
       if (systems != SCM_UNDEFINED)
        {
index 3fa108f06442bca5f109aca6200d6f3c3b3b9705..df98d77ceeb2de419e98debbb58c58a17caa5069 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <math.h>
 
+#include "book-paper-def.hh"
 #include "all-font-metrics.hh"
 #include "paper-def.hh"
 #include "font-interface.hh"
@@ -83,7 +84,8 @@ get_font_by_design_size (Paper_def* paper, Real requested,
     }
 
   Font_metric *fm = unsmob_metrics (scm_force (SCM_VECTOR_REF (font_vector, i)));
-  return paper->find_scaled_font (fm, requested / size, input_encoding_name);
+  return paper->bookpaper_->find_scaled_font (fm, requested / size, input_encoding_name);
+
 }
 
 
@@ -127,7 +129,7 @@ select_encoded_font (Paper_def *paper, SCM chain, SCM encoding_name)
       Font_metric * fm = all_fonts_global->find_font (ly_scm2string (name));
       
       
-      return paper->find_scaled_font (fm, rmag, encoding_name);
+      return paper->bookpaper_->find_scaled_font (fm, rmag, encoding_name);
     }
   else if (scm_instance_p (name))
     {
@@ -148,8 +150,6 @@ select_encoded_font (Paper_def *paper, SCM chain, SCM encoding_name)
   return 0;
 }
 
-
-
 Font_metric *
 select_font (Paper_def *paper, SCM chain)
 {
index 7e65d51b217a78ea9105c2a0732e03810c867c6e..67ff4dfa5449c15455a43983887e152601a765cc 100644 (file)
@@ -20,8 +20,9 @@ class Book : public Input
 
 public:
   SCM header_;
+  Book_paper_def *bookpaper_;
+  
   Link_array<Score> scores_;
-    
   Book ();
 
   void process (String outname, Music_output_def*, SCM header);
index c5f54a17e7afcec833352a1125463cf9290917e2..a72361a6f4ea7c90799f320a8c7a5ab918625687 100644 (file)
@@ -36,6 +36,7 @@ const Real PT_TO_MM = (1.0/MM_TO_PT);
 #define CHAR *CHAR_TO_PT *PT_TO_MM
 #define INTERNAL_UNIT "mm"
 
+
 #endif
 
 String print_dimen (Real);
index 0e1dc356c147e1a9652919f0521a695b54028e90..f74f32d9786748664a64af38ae2ea0ff81c6ca39 100644 (file)
@@ -37,6 +37,7 @@ class Beaming_info_list;
 class Bezier;
 class Bezier_bow;
 class Book;
+class Book_paper_def;
 class Break_algorithm;
 class Change_iterator;
 class Change_translator;
index 466fa59b3a46704a886ec6ba62bd40354c308447..f5ea1cacb41c467557ec73da83d8bdb1e9230822 100644 (file)
@@ -47,9 +47,9 @@ class Paper_def : public Music_output_def
 {
 protected:
   VIRTUAL_COPY_CONSTRUCTOR (Music_output_def, Paper_def);
-  SCM scaled_fonts_;
   
-public:    
+public:
+  Book_paper_def * bookpaper_;
   static int score_count_;
   
   Paper_def ();
index 7cf2a75e5ddbb8e7f8842556a4234ffd0cf76718..bbd67d495b43e827b9649c03b30643cfde5d668e 100644 (file)
@@ -30,10 +30,9 @@ class Paper_outputter
   SCM output_module_;
   Protected_scm file_;
   String filename_;
-  Paper_def * paper_ ;         // THIS IS BROKEN.
   
   void output_expr (SCM expr, Offset o);
-  void output_metadata (Paper_def*, SCM);
+  void output_metadata (Book_paper_def*, SCM);
   void output_music_output_def (Music_output_def* odef);
 
 public:
@@ -43,7 +42,7 @@ public:
   void dump_scheme (SCM);
   void output_scheme (SCM scm);
   void output_stencil (Stencil);
-  void output_header (Paper_def*, SCM, int, bool);
+  void output_header (Book_paper_def*, SCM, int, bool);
   void output_line (SCM, Offset*, bool);
   void output_page (Page*, bool);
 };
index 2c9858948ece57d82bbe644476d8a93b9d6f74a9..ca25c3d0f980fbf5dd1f472a4b048cd178a829db 100644 (file)
@@ -27,12 +27,13 @@ public:
     
   Score ();
   Score (Score const&);
-  SCM book_rendering (String, Music_output_def*, Paper_def**);
+  SCM book_rendering (String, Book_paper_def*, Music_output_def*, Paper_def**);
 };
+
 DECLARE_UNSMOB (Score, score);
 
 SCM ly_run_translator (SCM, SCM);
 SCM ly_render_output (SCM, SCM);
-void default_rendering (SCM, SCM, SCM, SCM);
+void default_rendering (SCM, SCM, SCM, SCM, SCM);
 
 #endif /* SCORE_HH */
diff --git a/lily/modified-font-metric.cc b/lily/modified-font-metric.cc
new file mode 100644 (file)
index 0000000..0210c86
--- /dev/null
@@ -0,0 +1,303 @@
+/*
+  scaled-font-metric.cc -- declare Modified_font_metric
+  
+  source file of the GNU LilyPond music typesetter
+  
+  (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  
+ */
+
+#include <ctype.h>
+
+#include "warn.hh"
+#include "scaled-font-metric.hh"
+#include "string.hh"
+#include "stencil.hh"
+
+Modified_font_metric::Modified_font_metric (String coding, Font_metric* m, Real magn)
+{
+  coding_vector_ = SCM_EOL;
+  coding_mapping_ = SCM_EOL;
+  coding_table_ = SCM_EOL;
+  coding_description_ = SCM_EOL;
+  
+  coding_scheme_ = coding;
+  magnification_ = magn;
+  
+  SCM desc = m->description_;
+
+  Real total_mag = magn * ly_scm2double (ly_cdr (desc));
+  assert (total_mag);
+  
+  description_ = scm_cons (ly_car (desc), scm_make_real (total_mag));
+  orig_ = m;
+
+  if (coding_scheme_ != "TeX"
+      && coding_scheme_ != "ASCII"
+      && coding_scheme_ !=  orig_->coding_scheme ())
+    {
+      coding_vector_ = scm_call_1 (ly_scheme_function ("get-coding-vector"),
+                                  scm_makfrom0str (coding_scheme_.to_str0 ()));
+
+      if (!ly_c_vector_p (coding_vector_))
+       {
+         programming_error ("get-coding-vector  should return vector");
+         coding_vector_ = scm_c_make_vector (256, ly_symbol2scm (".notdef"));
+       }
+
+      
+      coding_table_ = scm_call_1 (ly_scheme_function ("get-coding-table"),
+                                 scm_makfrom0str (orig_->coding_scheme ().to_str0 ()));
+         
+      coding_mapping_  = scm_call_2 (ly_scheme_function ("make-encoding-mapping"),
+                                        coding_vector_,
+                                        coding_table_);
+
+      coding_description_= SCM_EOL;
+
+      coding_description_ = scm_acons (ly_symbol2scm ("input-name"),
+                                      scm_makfrom0str (coding_scheme_.to_str0 ()),
+                                      coding_description_);
+
+      coding_description_ = scm_acons (ly_symbol2scm ("input-vector"),
+                                      coding_vector_, coding_description_);
+      coding_description_ = scm_acons (ly_symbol2scm ("output-name"),
+                                      scm_makfrom0str (orig_->coding_scheme ().to_str0 ()),
+                                      coding_description_);
+      coding_description_ = scm_acons (ly_symbol2scm ("output-table"),
+                                      coding_table_,
+                                      coding_description_);
+      
+      coding_description_ = scm_acons (ly_symbol2scm ("char-mapping"),
+                                      coding_mapping_,
+                                      coding_description_);
+    } 
+}
+
+
+
+LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist",
+          1, 0, 0,
+          (SCM font),
+          "Given the Modified_font_metric @var{font}, return an "
+          "alist. Keys are input-name, input-vector, "
+          "output-name, output-table, mapping.")
+{
+  Modified_font_metric *fm
+    = dynamic_cast<Modified_font_metric*> (unsmob_metrics (font));
+  
+  SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric");
+  return fm->coding_description_;
+}
+
+SCM
+Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s)
+{
+  /*
+    UGOHR.
+   */
+  if (ly_c_symbol_p (coding))
+    coding = scm_symbol_to_string (coding);
+  
+  String scheme = ly_scm2string (coding);
+  
+  Modified_font_metric *sfm = new Modified_font_metric (scheme, m, s);
+  
+  return sfm->self_scm ();
+}
+
+Real
+Modified_font_metric::design_size () const
+{
+  return orig_->design_size ();
+}
+
+
+Box 
+Modified_font_metric::get_indexed_char (int i) const
+{
+  Box b = orig_->get_indexed_char (i);
+  b.scale (magnification_);
+  return b;  
+}
+
+Box 
+Modified_font_metric::get_ascii_char (int i) const
+{
+  Box b = orig_->get_ascii_char (i);
+  b.scale (magnification_);
+  return b;  
+}
+
+int
+Modified_font_metric::count () const
+{
+  return orig_->count ();
+}
+
+Offset
+Modified_font_metric::get_indexed_wxwy (int k) const
+{
+  Offset o = orig_->get_indexed_wxwy (k);
+  return o * magnification_;
+}
+
+int
+Modified_font_metric::name_to_index (String s) const
+{
+  return orig_->name_to_index (s);
+}
+
+int
+Modified_font_metric::index_to_ascii (int k) const
+{
+  return orig_->index_to_ascii (k);
+}
+
+String
+Modified_font_metric::coding_scheme () const
+{
+  return coding_scheme_;
+}
+
+void
+Modified_font_metric::derived_mark () const
+{
+  scm_gc_mark (coding_vector_);
+  scm_gc_mark (coding_description_);
+  scm_gc_mark (coding_table_);
+  scm_gc_mark (coding_mapping_);
+}
+
+Box
+Modified_font_metric::tex_kludge (String text) const
+{
+  Interval ydims;
+  Real w=0.0;
+
+  /*
+    TODO: put this klutchness behind ly:option switch.
+  */  
+  for (int i = 0; i < text.length (); i++) 
+    {
+      switch (text[i]) 
+       {
+       case '\\':
+         // accent marks use width of base letter
+         if (i +1 < text.length ())
+          {
+            if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' ||
+                text[i+1]=='^')
+              {
+                i++;
+                break;
+              }
+            // for string width \\ is a \ and \_ is a _.
+            if (text[i+1]=='\\' || text[i+1]=='_')        
+              {
+                break;
+              }
+          }
+         
+         for (i++; (i < text.length ()) && !isspace (text[i]) 
+                && text[i]!='{' && text[i]!='}'; i++)
+           ;
+         
+         // ugh.
+         i--; // Compensate for the increment in the outer loop!
+         break;
+       case '{':  // Skip '{' and '}'
+       case '}':
+         break;
+       
+       default: 
+         Box b = get_ascii_char ((unsigned char)text[i]);
+         
+         // Ugh, use the width of 'x' for unknown characters
+         if (b[X_AXIS].length () == 0) 
+           b = get_ascii_char ((unsigned char)'x');
+         
+         w += b[X_AXIS].length ();
+         ydims.unite (b[Y_AXIS]);
+         break;
+       }
+    }
+  
+  if (ydims.is_empty ())
+    ydims = Interval (0, 0);
+  
+  return Box (Interval (0, w), ydims);
+}
+
+Box
+Modified_font_metric::text_dimension (String text) 
+{
+  Box b; 
+  if (coding_scheme_ == "TeX")
+    {
+      b = tex_kludge (text);
+    }
+  else if (coding_scheme_ == "ASCII"
+          || coding_scheme_ ==  orig_->coding_scheme ())
+    {
+      Interval ydims;
+
+      Real w=0.0;
+
+      for (int i = 0; i < text.length (); i++) 
+       {
+         Box b = get_ascii_char ((unsigned char)text[i]);
+    
+         w += b[X_AXIS].length ();
+         ydims.unite (b[Y_AXIS]); 
+       }
+      if (ydims.is_empty ())
+       ydims = Interval (0, 0);
+
+      b = Box(Interval(0,w), ydims);
+    }
+  else
+    {
+      Interval ydims;
+      Real w = 0.0;
+
+      for (int i = 0; i < text.length (); i++) 
+       {
+         SCM sym = scm_vector_ref (coding_vector_,
+                                   SCM_MAKINUM((unsigned char) text[i]));
+
+         Box char_box;
+
+         if (!ly_c_symbol_p (sym))
+           continue;
+
+         char const * chars =  SCM_SYMBOL_CHARS(sym);
+         
+         int idx = orig_->name_to_index (chars);
+         if (idx >= 0)
+           {
+             char_box = orig_->get_indexed_char (idx);
+           }
+         
+         char_box.scale (magnification_);
+         if (!char_box[X_AXIS].is_empty ())
+           w += char_box[X_AXIS][RIGHT]; // length ?
+
+         ydims.unite (char_box[Y_AXIS]);
+       }
+
+      if (ydims.is_empty ())
+       ydims = Interval (0, 0);
+
+         
+      b = Box (Interval (0, w), ydims);
+    }
+  
+  return b;
+}
+
+Font_metric*
+Modified_font_metric::original_font () const
+{
+  return orig_;
+}
index 0d6aeb34bca4331887d369cf675059932c200eed..1680f3de4c9cf697958b347d6dc823fb3d545201 100644 (file)
@@ -8,6 +8,7 @@
 */
 
 #include "book.hh"
+#include "book-paper-def.hh"
 #include "file-name.hh"
 #include "file-path.hh"
 #include "lily-version.hh"
@@ -325,11 +326,30 @@ LY_DEFINE(ly_parser_define, "ly:parser-define",
           (SCM parser_smob, SCM symbol, SCM val),
           "Bind SYMBOL to VAL in PARSER_SMOB's module.")
 {
-  SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG1, __FUNCTION__, "symbol");
   My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+  SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG2, __FUNCTION__, "symbol");
+  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser");  
+
+
   parser->lexer_->set_identifier (scm_symbol_to_string (symbol), val);
   return SCM_UNSPECIFIED;
 }
+LY_DEFINE(ly_parser_lookup, "ly:parser-lookup",
+          2, 0, 0, 
+          (SCM parser_smob, SCM symbol),
+          "Lookup @var{symbol} in @var{parser_smob}'s module. Undefined is '().")
+{
+  My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+
+  SCM_ASSERT_TYPE (ly_c_symbol_p (symbol), symbol, SCM_ARG2, __FUNCTION__, "symbol");
+  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG2, __FUNCTION__, "parser");  
+
+  SCM val= parser->lexer_->lookup_identifier (ly_scm2string (scm_symbol_to_string (symbol)));
+  if (val != SCM_UNDEFINED)
+    return val;
+  else
+    return SCM_EOL;
+}
 
 LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string",
           2, 0, 0,
@@ -337,20 +357,13 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string",
           "Parse the string LY_CODE with PARSER_SMOB."
           "Upon failure, throw @code{ly-file-failed} key.")
 {
-#if 0
-  SCM_ASSERT_TYPE (ly_c_parser_p (parser), music, SCM_ARG1, __FUNCTION__, "parser");
-#endif
-  SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG1, __FUNCTION__, "string");
 
-#if 1
   My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
+
+  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
+  SCM_ASSERT_TYPE (ly_c_string_p (ly_code), ly_code, SCM_ARG2, __FUNCTION__, "string");
+  
   parser->parse_string (ly_scm2string (ly_code));
-#else
-  My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
-  My_lily_parser *clone = new My_lily_parser (*parser);
-  clone->parse_string (ly_scm2string (ly_code));
-  clone = 0;
-#endif
   
   return SCM_UNSPECIFIED;
 }
@@ -363,18 +376,31 @@ get_paper (My_lily_parser *parser)
   return paper ? paper->clone () : new Paper_def;
 }
 
+
+Book_paper_def*
+get_bookpaper (My_lily_parser *parser)
+{
+  SCM id = parser->lexer_->lookup_identifier ("$defaultbookpaper");
+  Book_paper_def *paper = unsmob_bookpaper (id);
+  return  paper->clone ();
+}
+
+
+/*
+  TODO: move this to Scheme? Why take the parser arg, and all the back
+  & forth between scm and c++?
+ */
 LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
           2, 0, 0,
           (SCM parser_smob, SCM score_smob),
           "Print score, i.e., the classic way.")
 {
-#if 0
-  SCM_ASSERT_TYPE (ly_c_parser_p (parser), music, SCM_ARG1, __FUNCTION__, "parser");
-  SCM_ASSERT_TYPE (ly_c_music_p (music), music, SCM_ARG1, __FUNCTION__, "music");
-#endif
   My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
   Score *score = unsmob_score (score_smob);
 
+  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "parser");
+  SCM_ASSERT_TYPE (score, score_smob, SCM_ARG2, __FUNCTION__, "score");
+
   SCM header = is_module (score->header_) ? score->header_
     : parser->header_.to_SCM ();
   
@@ -386,13 +412,16 @@ LY_DEFINE (ly_parser_print_score, "ly:parser-print-score",
 
   SCM os = scm_makfrom0str (outname.to_string ().to_str0 ());
   for (int i = 0; i < score->defs_.size (); i++)
-    default_rendering (score->music_, score->defs_[i]->self_scm (), header,
-                      os);
+    default_rendering (score->music_, score->defs_[i]->self_scm (),
+                      get_bookpaper (parser)->self_scm (),
+                      header, os);
 
   if (score->defs_.is_empty ())
     {
       Music_output_def *paper = get_paper (parser);
-      default_rendering (score->music_, paper->self_scm (), header, os);
+      default_rendering (score->music_, paper->self_scm (),
+                        get_bookpaper (parser)->self_scm (),
+                        header, os);
       scm_gc_unprotect_object (paper->self_scm ());
     }
   return SCM_UNDEFINED;
@@ -403,12 +432,14 @@ LY_DEFINE (ly_parser_print_book, "ly:parser-print-book",
           (SCM parser_smob, SCM book_smob),
           "Print book.")
 {
-#if 0
-  SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smob, SCM_ARG1, __FUNCTION__, "parser_smob");
-  SCM_ASSERT_TYPE (ly_c_music_p (book_smob), book_smob, SCM_ARG1, __FUNCTION__, "book_smob");
-#endif
   My_lily_parser *parser = unsmob_my_lily_parser (parser_smob);
   Book *book = unsmob_book (book_smob);
+  Book_paper_def *bp = unsmob_bookpaper (parser->lexer_->lookup_identifier ("$defaultbookpaper"));
+  
+  SCM_ASSERT_TYPE (parser, parser_smob, SCM_ARG1, __FUNCTION__, "Lilypond parser");
+  SCM_ASSERT_TYPE (book, book_smob, SCM_ARG2, __FUNCTION__, "Book");
+  
+  book->bookpaper_ = bp;       // ugh. changing argument. 
   
   SCM header = parser->header_;
   File_name outname (parser->output_basename_);
index 048295b0a4c3689ef2c7ff3b684dc77b641e166e..8fbc9fbd2ddd6d1fe69c7c1a455ea73db988f3b8 100644 (file)
@@ -89,7 +89,7 @@ Paper_book::output (String outname)
   Paper_def *paper = score_lines_[0].paper_;
   Paper_outputter *out = paper->get_paper_outputter (outname);
   int page_count = scm_ilength (pages);
-  out->output_header (paper, scopes (0), page_count, false);
+  out->output_header (paper->bookpaper_, scopes (0), page_count, false);
 
   for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s))
     {
@@ -145,7 +145,7 @@ Paper_book::classic_output (String outname)
   int count = score_lines_.size ();
   Paper_def * p = score_lines_.top ().paper_;
   Paper_outputter *out = p->get_paper_outputter (outname);
-  out->output_header (p, scopes (count - 1), 0, true);
+  out->output_header (p->bookpaper_, scopes (count - 1), 0, true);
 
   SCM top_lines = score_lines_.top ().lines_;
   Paper_line *first = unsmob_paper_line (scm_vector_ref (top_lines,
index b1b3a6d6e599106c843f0498a406fb5186fdcc91..85cb00b73e2724c61e45e027d094006a9613a30e 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <math.h>
 
+#include "book-paper-def.hh"
 #include "virtual-font-metric.hh"
 #include "all-font-metrics.hh"
 #include "string.hh"
 
 Paper_def::Paper_def ()
 {
-  /* Do not remove this statement, scm_make_hash_table may trigger GC.  */
-  scaled_fonts_ = SCM_EOL;
-  scaled_fonts_ = scm_c_make_hash_table (11);
+  bookpaper_ = 0;
 }
 
 Paper_def::Paper_def (Paper_def const&src)
   : Music_output_def (src)
 {
   /* Do not remove this statement, scm_make_hash_table may trigger GC.  */
-  scaled_fonts_ = SCM_EOL;
-  scaled_fonts_ = scm_c_make_hash_table (11);
+  bookpaper_ = 0;
 }
 
 Paper_def::~Paper_def ()
@@ -49,17 +47,15 @@ Paper_def::~Paper_def ()
 void
 Paper_def::derived_mark ()
 {
-  scm_gc_mark (scaled_fonts_);
+  if (bookpaper_)
+    scm_gc_mark (bookpaper_->self_scm ());
 }
 
 Real
 Paper_def::get_dimension (SCM s) const
 {
   SCM val = lookup_variable (s);
-  SCM scale = lookup_variable (ly_symbol2scm ("outputscale"));
-  
-  Real sc = ly_scm2double (scale);
-  return ly_scm2double (val) / sc;
+  return ly_scm2double (val);
 }
 
 /* FIXME.  This is broken until we have a generic way of
@@ -79,98 +75,7 @@ Paper_def::get_paper_outputter (String outname) const
   progress_indication (_f ("paper output to `%s'...",
                           outname == "-" ? String ("<stdout>") : outname));
   return new Paper_outputter (outname);
-}
-
-Font_metric*
-Paper_def::find_scaled_font (Font_metric *f, Real m, SCM input_enc_name)
-{
-  SCM scale_var = SCM_EOL;
-  Real lookup_mag = m;
-  if (!dynamic_cast<Virtual_font_metric*> (f))
-    {
-      scale_var = ly_module_lookup (scope_, ly_symbol2scm ("outputscale"));
-      lookup_mag /= ly_scm2double (scm_variable_ref (scale_var));
-    }
-  
-  SCM sizes = scm_hashq_ref (scaled_fonts_, f->self_scm (), SCM_BOOL_F);
-  if (sizes != SCM_BOOL_F)
-    {
-      SCM met = scm_assoc (scm_make_real (lookup_mag), sizes);
-      if (ly_c_pair_p (met))
-       return unsmob_metrics (ly_cdr (met));
-    }
-  else
-    sizes = SCM_EOL;
-  
-  /* Hmm. We're chaining font - metrics.  Should consider whether to
-     merge virtual-font and scaled_font.  */
-  SCM val = SCM_EOL;
-  if (Virtual_font_metric * vf = dynamic_cast<Virtual_font_metric*> (f))
-    {
-      /*
-       For fontify_atom (), the magnification and name must be known
-       at the same time. That's impossible for
-
-         Scaled (Virtual_font (Font1,Font2))
-
-       so we replace by
-
-         Virtual_font (Scaled (Font1), Scaled (Font2))
-
-      */
-      
-      SCM lst = SCM_EOL;
-      SCM *t = &lst;
-      for (SCM s = vf->get_font_list (); ly_c_pair_p (s); s = ly_cdr (s))
-       {
-         Font_metric *scaled = find_scaled_font (unsmob_metrics (ly_car (s)),
-                                                 m, input_enc_name);
-         *t = scm_cons (scaled->self_scm (), SCM_EOL);
-         t = SCM_CDRLOC(*t);
-       }
-
-      vf = new Virtual_font_metric (lst);
-      val = vf->self_scm ();
-    }
-  else
-    {
-
-      if (!ly_c_symbol_p (input_enc_name))
-       {
-         SCM var = ly_module_lookup (scope_, ly_symbol2scm ("inputencoding"));
-         input_enc_name = scm_variable_ref (var);
-       }
-      val = Modified_font_metric::make_scaled_font_metric (input_enc_name,
-                                                          f, lookup_mag);
-    }
-
-  sizes = scm_acons (scm_make_real (lookup_mag), val, sizes);
-  scm_gc_unprotect_object (val);
-  scm_hashq_set_x (scaled_fonts_, f->self_scm (), sizes);
-  return unsmob_metrics (val);
-}
 
-
-/* Return alist to translate internally used fonts back to real-world
-   coordinates.  */
-SCM
-Paper_def::font_descriptions () const
-{
-  SCM func = ly_scheme_function ("hash-table->alist");
-
-  SCM l = SCM_EOL;
-  for (SCM s = scm_call_1 (func, scaled_fonts_); ly_c_pair_p (s); s = ly_cdr (s))
-    {
-      SCM entry = ly_car (s);
-      for (SCM t = ly_cdr (entry); ly_c_pair_p (t); t  = ly_cdr (t))
-       {
-         Font_metric *fm= unsmob_metrics (ly_cdar (t));
-
-         if (dynamic_cast<Modified_font_metric*> (fm))
-           l = scm_cons (fm->self_scm (), l);
-       }
-    }
-  return l;
 }
 
 Paper_def* 
index 49351e11d3e7de677383eeeebcf321013dbc2f44..318784259e4e49695e0bdf63acf6bec74e749ae9 100644 (file)
@@ -10,6 +10,7 @@
 #include <math.h>
 #include <time.h>
 
+#include "book-paper-def.hh"
 #include "array.hh"
 #include "dimensions.hh"
 #include "font-metric.hh"
@@ -35,7 +36,6 @@ extern SCM stencil2line (Stencil* stil, bool is_title = false);
 Paper_outputter::Paper_outputter (String filename)
 {
   filename_ = filename;
-  paper_ = 0;
   file_ = scm_open_file (scm_makfrom0str (filename.to_str0 ()),
                         scm_makfrom0str ("w"));
 
@@ -56,7 +56,7 @@ Paper_outputter::output_scheme (SCM scm)
 }
 
 void
-Paper_outputter::output_metadata (Paper_def *paper, SCM scopes)
+Paper_outputter::output_metadata (Book_paper_def *paper, SCM scopes)
 {
   SCM fields = SCM_EOL;
   for (int i = dump_header_fieldnames_global.size (); i--; )
@@ -76,10 +76,12 @@ Paper_outputter::output_metadata (Paper_def *paper, SCM scopes)
 }
 
 void
-Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count,
+Paper_outputter::output_header (Book_paper_def * bookpaper,
+                               
+                               SCM scopes,
+                               int page_count,
                                bool is_classic)
 {
-  paper_ = paper;              //  BROKEN BROKEN BROKEN.
   String creator = gnu_lilypond_version_string ();
   creator += " (http://lilypond.org)";
   time_t t (time (0));
@@ -89,14 +91,14 @@ Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count,
   output_scheme (scm_list_n (ly_symbol2scm ("header"),
                             scm_makfrom0str (creator.to_str0 ()),
                             scm_makfrom0str (time_stamp.to_str0 ()),
-                            paper->self_scm (),
+                            bookpaper->self_scm (), // FIXME.
                             scm_int2num (page_count),
                             ly_bool2scm (is_classic),
                             SCM_UNDEFINED));
 
-  output_metadata (paper, scopes);
-  output_music_output_def (paper);
-
+  output_metadata (bookpaper, scopes);
+  output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"),
+                            bookpaper->self_scm ()));
   output_scheme (scm_list_1 (ly_symbol2scm ("header-end")));
 }
 
@@ -162,13 +164,7 @@ paper_outputter_dump (void * po, SCM x)
 void
 Paper_outputter::output_stencil (Stencil stil)
 {
-  SCM fonts = find_expression_fonts (stil.expr ());
-
-  output_scheme (scm_list_3 (ly_symbol2scm ("define-fonts"),
-                            paper_->self_scm (),
-                            ly_quote_scm (ly_list_qsort_uniq_x (fonts))));
-  
-  interpret_stencil_expression (stil.expr (), paper_outputter_dump,
+   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
                          (void*) this, Offset (0,0));
 }
 
index 89a1a02973ec43b444a0c0c50c49f9d2a14352f7..f31f99023e05b62773461ea6777475e98b704e53 100644 (file)
@@ -26,6 +26,7 @@ TODO:
 
 
 #include "book.hh"
+#include "book-paper-def.hh"
 #include "context-def.hh"
 #include "dimensions.hh"
 #include "event.hh"
@@ -622,6 +623,7 @@ book_body:
        {
                $$ = new Book;
                $$->set_spot (THIS->here_input ());
+               $$->bookpaper_ = unsmob_bookpaper (THIS->lexer_->lookup_identifier ("$defaultbookpaper"));
        }
        | book_body score_block {
                Score *score = $2;
diff --git a/lily/scaled-font-metric.cc b/lily/scaled-font-metric.cc
deleted file mode 100644 (file)
index 0210c86..0000000
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
-  scaled-font-metric.cc -- declare Modified_font_metric
-  
-  source file of the GNU LilyPond music typesetter
-  
-  (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-  
- */
-
-#include <ctype.h>
-
-#include "warn.hh"
-#include "scaled-font-metric.hh"
-#include "string.hh"
-#include "stencil.hh"
-
-Modified_font_metric::Modified_font_metric (String coding, Font_metric* m, Real magn)
-{
-  coding_vector_ = SCM_EOL;
-  coding_mapping_ = SCM_EOL;
-  coding_table_ = SCM_EOL;
-  coding_description_ = SCM_EOL;
-  
-  coding_scheme_ = coding;
-  magnification_ = magn;
-  
-  SCM desc = m->description_;
-
-  Real total_mag = magn * ly_scm2double (ly_cdr (desc));
-  assert (total_mag);
-  
-  description_ = scm_cons (ly_car (desc), scm_make_real (total_mag));
-  orig_ = m;
-
-  if (coding_scheme_ != "TeX"
-      && coding_scheme_ != "ASCII"
-      && coding_scheme_ !=  orig_->coding_scheme ())
-    {
-      coding_vector_ = scm_call_1 (ly_scheme_function ("get-coding-vector"),
-                                  scm_makfrom0str (coding_scheme_.to_str0 ()));
-
-      if (!ly_c_vector_p (coding_vector_))
-       {
-         programming_error ("get-coding-vector  should return vector");
-         coding_vector_ = scm_c_make_vector (256, ly_symbol2scm (".notdef"));
-       }
-
-      
-      coding_table_ = scm_call_1 (ly_scheme_function ("get-coding-table"),
-                                 scm_makfrom0str (orig_->coding_scheme ().to_str0 ()));
-         
-      coding_mapping_  = scm_call_2 (ly_scheme_function ("make-encoding-mapping"),
-                                        coding_vector_,
-                                        coding_table_);
-
-      coding_description_= SCM_EOL;
-
-      coding_description_ = scm_acons (ly_symbol2scm ("input-name"),
-                                      scm_makfrom0str (coding_scheme_.to_str0 ()),
-                                      coding_description_);
-
-      coding_description_ = scm_acons (ly_symbol2scm ("input-vector"),
-                                      coding_vector_, coding_description_);
-      coding_description_ = scm_acons (ly_symbol2scm ("output-name"),
-                                      scm_makfrom0str (orig_->coding_scheme ().to_str0 ()),
-                                      coding_description_);
-      coding_description_ = scm_acons (ly_symbol2scm ("output-table"),
-                                      coding_table_,
-                                      coding_description_);
-      
-      coding_description_ = scm_acons (ly_symbol2scm ("char-mapping"),
-                                      coding_mapping_,
-                                      coding_description_);
-    } 
-}
-
-
-
-LY_DEFINE (ly_font_encoding_alist, "ly:font-encoding-alist",
-          1, 0, 0,
-          (SCM font),
-          "Given the Modified_font_metric @var{font}, return an "
-          "alist. Keys are input-name, input-vector, "
-          "output-name, output-table, mapping.")
-{
-  Modified_font_metric *fm
-    = dynamic_cast<Modified_font_metric*> (unsmob_metrics (font));
-  
-  SCM_ASSERT_TYPE (fm, font, SCM_ARG1, __FUNCTION__, "Modified_font_metric");
-  return fm->coding_description_;
-}
-
-SCM
-Modified_font_metric::make_scaled_font_metric (SCM coding, Font_metric *m, Real s)
-{
-  /*
-    UGOHR.
-   */
-  if (ly_c_symbol_p (coding))
-    coding = scm_symbol_to_string (coding);
-  
-  String scheme = ly_scm2string (coding);
-  
-  Modified_font_metric *sfm = new Modified_font_metric (scheme, m, s);
-  
-  return sfm->self_scm ();
-}
-
-Real
-Modified_font_metric::design_size () const
-{
-  return orig_->design_size ();
-}
-
-
-Box 
-Modified_font_metric::get_indexed_char (int i) const
-{
-  Box b = orig_->get_indexed_char (i);
-  b.scale (magnification_);
-  return b;  
-}
-
-Box 
-Modified_font_metric::get_ascii_char (int i) const
-{
-  Box b = orig_->get_ascii_char (i);
-  b.scale (magnification_);
-  return b;  
-}
-
-int
-Modified_font_metric::count () const
-{
-  return orig_->count ();
-}
-
-Offset
-Modified_font_metric::get_indexed_wxwy (int k) const
-{
-  Offset o = orig_->get_indexed_wxwy (k);
-  return o * magnification_;
-}
-
-int
-Modified_font_metric::name_to_index (String s) const
-{
-  return orig_->name_to_index (s);
-}
-
-int
-Modified_font_metric::index_to_ascii (int k) const
-{
-  return orig_->index_to_ascii (k);
-}
-
-String
-Modified_font_metric::coding_scheme () const
-{
-  return coding_scheme_;
-}
-
-void
-Modified_font_metric::derived_mark () const
-{
-  scm_gc_mark (coding_vector_);
-  scm_gc_mark (coding_description_);
-  scm_gc_mark (coding_table_);
-  scm_gc_mark (coding_mapping_);
-}
-
-Box
-Modified_font_metric::tex_kludge (String text) const
-{
-  Interval ydims;
-  Real w=0.0;
-
-  /*
-    TODO: put this klutchness behind ly:option switch.
-  */  
-  for (int i = 0; i < text.length (); i++) 
-    {
-      switch (text[i]) 
-       {
-       case '\\':
-         // accent marks use width of base letter
-         if (i +1 < text.length ())
-          {
-            if (text[i+1]=='\'' || text[i+1]=='`' || text[i+1]=='"' ||
-                text[i+1]=='^')
-              {
-                i++;
-                break;
-              }
-            // for string width \\ is a \ and \_ is a _.
-            if (text[i+1]=='\\' || text[i+1]=='_')        
-              {
-                break;
-              }
-          }
-         
-         for (i++; (i < text.length ()) && !isspace (text[i]) 
-                && text[i]!='{' && text[i]!='}'; i++)
-           ;
-         
-         // ugh.
-         i--; // Compensate for the increment in the outer loop!
-         break;
-       case '{':  // Skip '{' and '}'
-       case '}':
-         break;
-       
-       default: 
-         Box b = get_ascii_char ((unsigned char)text[i]);
-         
-         // Ugh, use the width of 'x' for unknown characters
-         if (b[X_AXIS].length () == 0) 
-           b = get_ascii_char ((unsigned char)'x');
-         
-         w += b[X_AXIS].length ();
-         ydims.unite (b[Y_AXIS]);
-         break;
-       }
-    }
-  
-  if (ydims.is_empty ())
-    ydims = Interval (0, 0);
-  
-  return Box (Interval (0, w), ydims);
-}
-
-Box
-Modified_font_metric::text_dimension (String text) 
-{
-  Box b; 
-  if (coding_scheme_ == "TeX")
-    {
-      b = tex_kludge (text);
-    }
-  else if (coding_scheme_ == "ASCII"
-          || coding_scheme_ ==  orig_->coding_scheme ())
-    {
-      Interval ydims;
-
-      Real w=0.0;
-
-      for (int i = 0; i < text.length (); i++) 
-       {
-         Box b = get_ascii_char ((unsigned char)text[i]);
-    
-         w += b[X_AXIS].length ();
-         ydims.unite (b[Y_AXIS]); 
-       }
-      if (ydims.is_empty ())
-       ydims = Interval (0, 0);
-
-      b = Box(Interval(0,w), ydims);
-    }
-  else
-    {
-      Interval ydims;
-      Real w = 0.0;
-
-      for (int i = 0; i < text.length (); i++) 
-       {
-         SCM sym = scm_vector_ref (coding_vector_,
-                                   SCM_MAKINUM((unsigned char) text[i]));
-
-         Box char_box;
-
-         if (!ly_c_symbol_p (sym))
-           continue;
-
-         char const * chars =  SCM_SYMBOL_CHARS(sym);
-         
-         int idx = orig_->name_to_index (chars);
-         if (idx >= 0)
-           {
-             char_box = orig_->get_indexed_char (idx);
-           }
-         
-         char_box.scale (magnification_);
-         if (!char_box[X_AXIS].is_empty ())
-           w += char_box[X_AXIS][RIGHT]; // length ?
-
-         ydims.unite (char_box[Y_AXIS]);
-       }
-
-      if (ydims.is_empty ())
-       ydims = Interval (0, 0);
-
-         
-      b = Box (Interval (0, w), ydims);
-    }
-  
-  return b;
-}
-
-Font_metric*
-Modified_font_metric::original_font () const
-{
-  return orig_;
-}
index b287028e24f04e02962c6f494c28dbc45f2f8bc4..18a43641d002dd6d598e96ac17bdba07b62e3aa0 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdio.h>
 
 #include "book.hh"
+#include "book-paper-def.hh"
 #include "cpu-timer.hh"
 #include "global-context.hh"
 #include "ly-module.hh"
@@ -155,10 +156,20 @@ LY_DEFINE (ly_format_output, "ly:format-output",
 }
 
 void
-default_rendering (SCM music, SCM outdef, SCM header, SCM outname)
+default_rendering (SCM music, SCM outdef,
+                  SCM book_outputdef,
+                  SCM header, SCM outname)
 {
   SCM context = ly_run_translator (music, outdef);
 
+  Book_paper_def * bpd = unsmob_bookpaper (book_outputdef);
+  if (bpd &&
+      unsmob_paper (outdef))
+    {
+      outdef = bpd->scale_paper (unsmob_paper (outdef))->self_scm (); // mem
+                                                                     // leak.
+    }
+  
   if (Global_context *g = dynamic_cast<Global_context*>
       (unsmob_context (context)))
     {
@@ -182,9 +193,11 @@ default_rendering (SCM music, SCM outdef, SCM header, SCM outname)
       delete output;
     }
 }
-
 SCM
-Score::book_rendering (String outname, Music_output_def *default_def,
+Score::book_rendering (String outname,
+                      Book_paper_def* paperbook,
+                      Music_output_def *default_def,
                       Paper_def **paper)
 {
   SCM out = scm_makfrom0str (outname.to_str0 ());
@@ -193,6 +206,11 @@ Score::book_rendering (String outname, Music_output_def *default_def,
   for (int i = 0; !i || i < outdef_count; i++)
     {
       Music_output_def *def = outdef_count ? defs_[i] : default_def;
+      if (Paper_def * pd = dynamic_cast<Paper_def*> (def))
+       {
+         def = paperbook->scale_paper (pd);
+       }
+      
       if (!(no_paper_global_b && dynamic_cast<Paper_def*> (def)))
        {
          SCM context = ly_run_translator (music_, def->self_scm ());
index b7a4829df00b9ad3030149eb3bf59723a873d1e7..f0fc60ee7bfe31284767e96bbd89e022847aa08b 100644 (file)
@@ -86,6 +86,14 @@ melismaEnd = #(make-span-event 'ManualMelismaEvent STOP)
     \include "engraver-init.ly"
 }
 
+%
+% 20pt staff, 5 pt = 1.75 mm
+%
+
+#(define-public $defaultbookpaper (ly:make-bookpaper 1.7573))
+  
+
+
 #(set-default-paper-size "a4")
 
 
index 6424c799eec4efde85f91a634605b4aeb7775fca..96d4929c1b37890fbde9d1acf4f7cb9d3dbc4ca1 100644 (file)
--- a/po/fr.po
+++ b/po/fr.po
@@ -1,5 +1,5 @@
 # Messages français pour lilypond.
-# Copyright © 2001 Free Software Foundation, Inc.
+# Copyright © 2004 Free Software Foundation, Inc.
 # Michel Robitaille <robitail@IRO.UMontreal.CA>, traducteur depuis/since 1996.
 #
 msgid ""
@@ -7,12 +7,13 @@ msgstr ""
 "Project-Id-Version: lilypond 2.2.0\n"
 "Report-Msgid-Bugs-To: \n"
 "POT-Creation-Date: 2004-03-31 16:22+0200\n"
-"PO-Revision-Date: 2004-04-04 08:00-0500\n"
+"PO-Revision-Date: 2004-05-10 08:00-0500\n"
 "Last-Translator: Michel Robitaille <robitail@IRO.UMontreal.CA>\n"
 "Language-Team: French <traduc@traduc.org>\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=ISO-8859-1\n"
 "Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
 
 #: lilylib.py:60
 msgid "lilylib module"
index 39374dae2176cb367932fd987dbaa60ef9256aee..5d39f3305d3c0ff56dc3214c8910045094a0c96d 100644 (file)
@@ -3,8 +3,6 @@
 % Functions for direct and embedded PostScript
 
 
-/blot-diameter { lilypondpaperblotdiameter } bind def
-
 /set_tex_dimen {
        cvr def     
 } bind def
 % Nice rectangle with rounded corners
 /draw_box % breapth width depth height
 {
-       currentdict /testing known {
+%      currentdict /testing known {
                %% real thin lines for testing
                /blot 0.005 def
-       }{
-               /blot blot-diameter def
-       } ifelse
+%      }{
+%              /blot blot-diameter def
+%      } ifelse
 
        0 setlinecap
        blot setlinewidth
index 58c3a603e0248bdf5e9e476bac47de9ee43e8e57..a1c81d4775466e8d577693e9c1cd8ea41eae1f46 100644 (file)
     (ly:parser-print-book parser book)))
 
 (define-public (print-score-as-book parser score)
-  (let ((book (ly:score-bookify score)))
+  (let
+      ((book (ly:score-bookify score))
+       )
+    
     (ly:parser-print-book parser book)))
 
 (define-public (print-score parser score)
index 22cce8d52ba4a67144e23234d304aa79900a4fd1..4cc714fdecf34ac05ae58d18c255ebed76b10f1b 100644 (file)
    " /Helvetica-Bold " ;; ugh
    " draw_ez_ball"))
 
-(define (filledbox breapth width depth height) 
+(define (filledbox breapth width depth height) ; FIXME : use draw_round_box
   (string-append (ly:numbers->string (list breapth width depth height))
                 " draw_box"))
 
    "{\n"
    "set-ps-scale-to-lily-scale\n"))
 
-(define (stem breapth width depth height) 
+(define (stem breapth width depth height) ; FIXME: use draw_round_box.
   (string-append
    (ly:numbers->string (list breapth width depth height))
    " draw_box" ))
index 4c0800a25b4bc1f65bf3a069fbba8577501790f2..77dd2053b43f457aa10e6c2e57c8383516121771 100644 (file)
    (string-encode-integer
     (inexact->exact (round (* 1000 (ly:font-magnification font)))))))
 
-(define (define-fonts paper font-list)
+(define (define-fonts bookpaper)
+  (string-append
+   "\\def\\lilypondpaperunit{mm}" ;; UGH. FIXME. 
+   (tex-number-def "lilypondpaper" 'outputscale
+                  (number->string (exact->inexact
+                                   (ly:bookpaper-outputscale bookpaper))))
   (apply string-append
-        (map (lambda (x) (font-load-command paper x)) font-list)))
-
+        (map (lambda (x) (font-load-command bookpaper x))
+             (ly:bookpaper-fonts bookpaper)
+             )))
+)
 (define (unknown) 
   "%\n\\unknown\n")
 
   (string-append
    "\\def\\" prefix (symbol->tex-key key) (string->param number) "%\n"))
 
-(define (output-paper-def pd)
-  (apply
-   string-append
-   (module-map
-    (lambda (sym var)
-      (let ((val (variable-ref var))
-           (key (symbol->tex-key sym)))
-
-       (cond
-        ((string? val)
-         (tex-string-def "lilypondpaper" sym val))
-        ((number? val)
-         (tex-number-def "lilypondpaper" sym
-                         (if (integer? val)
-                             (number->string val)
-                             (number->string (exact->inexact val)))))
-        (else ""))))
-      
-    (ly:output-def-scope pd))))
+(define (output-paper-def paper)
+      (apply
+       string-append
+       (module-map
+       (lambda (sym var)
+         (let ((val (variable-ref var))
+               (key (symbol->tex-key sym)))
+
+           (cond
+            ((string? val)
+             (tex-string-def "lilypondpaper" sym val))
+            ((number? val)
+             (tex-number-def "lilypondpaper" sym
+                             (if (integer? val)
+                                 (number->string val)
+                                 (number->string (exact->inexact val)))))
+            (else ""))))
+       
+       (ly:output-def-scope pd))))
 
 (define (output-scopes paper scopes fields basename)
   (define (output-scope scope)
 (define (symmetric-x-triangle t w h)
   (embedded-ps (list 'symmetric-x-triangle t w h)))
 
-(define (font-load-command paper font)
+(define (font-load-command bookpaper font)
   (string-append
    "\\font\\" (font-command font) "="
    (ly:font-filename font)
    (ly:number->string (inexact->exact
                       (round (* 1000
                          (ly:font-magnification font)
-                         (ly:paper-lookup paper 'outputscale)))))
+                         (ly:bookpaper-outputscale bookpaper)))))
    "\n"))
 
 (define (ez-ball c l b)
    "\\lilypondspecial\n"
    "\\lilypondpostscript\n"))
 
+; why paper? 
 (define (header creator time-stamp paper page-count classic?)
   (string-append
    "% Generated by " creator "\n"
index beb11e087eaf0ae447df28091433939342f17bae..15acb3ea767f0858d475e41b37966dde28919041 100644 (file)
@@ -13,7 +13,6 @@
         (mm (eval 'mm m)))
    
     (module-define! m 'fonts (make-cmr-tree (/  sz (* 20 pt))))
-    
     (module-define! m 'staffheight sz)
     (module-define! m 'staff-space ss)
     (module-define! m 'staffspace ss)
 
     ;; !! synchronize with feta-params.mf
     (module-define! m 'linethickness (+ (* 0.3 pt) (* 0.04 ss)))
-    (module-define! m 'outputscale ss)
     (module-define! m 'ledgerlinethickness (+ (* 0.5 pt) (/ ss 10)))
     (module-define! m 'blotdiameter (* 0.35 pt))
-    (module-define! m 'interscoreline (* 4 mm))))
+    (module-define! m 'interscoreline (* 4 mm))
+
+    (module-define! m 'dimension-variables
+                   '(pt mm cm in staffheight staff-space
+                        staffspace linethickness ledgerlinethickness
+                        blotdiameter interscoreline))
+    ))
 
 (define-public (set-global-staff-size sz)
   "Set the default staff size, where SZ is thought to be in PT."
       ;;; TODO: should raise (generic) exception with throw, and catch
       ;;; that in parse-scm.cc
       (ly:warn "Must use #(set-paper-size .. ) within \\paper { ... }")))
+
+(define-public (scale-paper pap bookpap)
+  (let*
+      ((scale (ly:bookpaper-outputscale bookpap))
+       (new-pap (ly:output-def-clone pap))
+       (dim-vars (ly:paper-lookup pap 'dimension-variables))
+       (scope (ly:output-def-scope new-pap))
+       )
+
+    (for-each
+     (lambda (v)
+       (module-define! scope v
+                      (* (ly:paper-lookup pap v) scale)))
+
+     
+     dim-vars)
+
+    new-pap
+  ))