]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-book.cc
Add '-dcrop' option to ps and svg backends
[lilypond.git] / lily / paper-book.cc
index 9cf318416c83218ff0f230a9736af84d4123b1cb..f1787e99550f2bb09eb001188b69384c69e5f004 100644 (file)
@@ -1,7 +1,7 @@
 /*
   This file is part of LilyPond, the GNU music typesetter.
 
-  Copyright (C) 2004--2014 Jan Nieuwenhuizen <janneke@gnu.org>
+  Copyright (C) 2004--2015 Jan Nieuwenhuizen <janneke@gnu.org>
 
   LilyPond is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -30,6 +30,8 @@
 #include "warn.hh"
 #include "program-option.hh"
 #include "page-marker.hh"
+#include "ly-module.hh"
+#include "lily-imports.hh"
 
 
 Paper_book::Paper_book ()
@@ -51,10 +53,10 @@ Paper_book::~Paper_book ()
 {
 }
 
-const char Paper_book::type_p_name_[] = "ly:paper-book?";
+const char * const Paper_book::type_p_name_ = "ly:paper-book?";
 
 SCM
-Paper_book::mark_smob ()
+Paper_book::mark_smob () const
 {
   if (paper_)
     scm_gc_mark (paper_->self_scm ());
@@ -116,19 +118,16 @@ Paper_book::output_aux (SCM output_channel,
   long page_nb = 0;
   if (scm_is_pair (performances_))
     {
-      SCM proc = ly_lily_module_constant ("write-performances-midis");
-
-      scm_call_3 (proc,
-                  performances (),
-                  output_channel,
-                  scm_from_long (*first_performance_number));
+      Lily::write_performances_midis (performances (),
+                                      output_channel,
+                                      scm_from_long (*first_performance_number));
       *first_performance_number += scm_ilength (performances_);
     }
 
   if (scm_is_pair (bookparts_))
     {
       for (SCM p = bookparts_; scm_is_pair (p); p = scm_cdr (p))
-        if (Paper_book *pbookpart = Paper_book::unsmob (scm_car (p)))
+        if (Paper_book *pbookpart = unsmob<Paper_book> (scm_car (p)))
           {
             bool is_last_part = (is_last && !scm_is_pair (scm_cdr (p)));
             page_nb += pbookpart->output_aux (output_channel,
@@ -139,7 +138,7 @@ Paper_book::output_aux (SCM output_channel,
     }
   else
     {
-      if (scores_ == SCM_EOL)
+      if (scm_is_null (scores_))
         return 0;
       paper_->set_variable (ly_symbol2scm ("first-page-number"),
                             scm_from_long (*first_page_number));
@@ -165,7 +164,7 @@ Paper_book::output (SCM output_channel)
      with different line-widths) and why we need it at all.
   */
 
-  if (paper_->c_variable ("line-width") == SCM_UNDEFINED)
+  if (SCM_UNBNDP (paper_->c_variable ("line-width")))
     paper_->set_variable (ly_symbol2scm ("line-width"),
                           paper_->c_variable ("paper-width"));
 
@@ -188,7 +187,7 @@ Paper_book::output (SCM output_channel)
       SCM framework = ly_module_lookup (mod,
                                         ly_symbol2scm ("output-framework"));
 
-      if (framework != SCM_BOOL_F)
+      if (scm_is_true (framework))
         {
           SCM func = scm_variable_ref (framework);
           scm_call_4 (func,
@@ -207,7 +206,7 @@ Paper_book::output (SCM output_channel)
       SCM framework
         = ly_module_lookup (mod, ly_symbol2scm ("output-preview-framework"));
 
-      if (framework != SCM_BOOL_F)
+      if (scm_is_true (framework))
         {
           SCM func = scm_variable_ref (framework);
           scm_call_4 (func,
@@ -220,6 +219,25 @@ Paper_book::output (SCM output_channel)
         warning (_f ("program option -dpreview not supported by backend `%s'",
                      get_output_backend_name ()));
     }
+
+  if (get_program_option ("crop"))
+    {
+      SCM framework
+        = ly_module_lookup (mod, ly_symbol2scm ("output-crop-framework"));
+
+      if (scm_is_true (framework))
+        {
+          SCM func = scm_variable_ref (framework);
+          scm_call_4 (func,
+                      output_channel,
+                      self_scm (),
+                      scopes,
+                      dump_fields ());
+        }
+      else
+        warning (_f ("program option -dcrop not supported by backend `%s'",
+                     get_output_backend_name ()));
+    }
 }
 
 void
@@ -228,11 +246,9 @@ Paper_book::classic_output_aux (SCM output,
 {
   if (scm_is_pair (performances_))
     {
-      SCM proc = ly_lily_module_constant ("write-performances-midis");
-      scm_call_3 (proc,
-                  performances (),
-                  output,
-                  scm_from_long (*first_performance_number));
+      Lily::write_performances_midis (performances (),
+                                      output,
+                                      scm_from_long (*first_performance_number));
       *first_performance_number += scm_ilength (performances_);
     }
 
@@ -285,8 +301,8 @@ Paper_book::book_title ()
                       paper_->self_scm (),
                       scopes);
 
-  if (Stencil::is_smob (tit))
-    title = *Stencil::unsmob (tit);
+  if (unsmob<Stencil> (tit))
+    title = *unsmob<Stencil> (tit);
 
   if (!title.is_empty ())
     title.align_to (Y_AXIS, UP);
@@ -314,8 +330,8 @@ Paper_book::score_title (SCM header)
                       paper_->self_scm (),
                       scopes);
 
-  if (Stencil::is_smob (tit))
-    title = *Stencil::unsmob (tit);
+  if (unsmob<Stencil> (tit))
+    title = *unsmob<Stencil> (tit);
 
   if (!title.is_empty ())
     title.align_to (Y_AXIS, UP);
@@ -326,7 +342,7 @@ Paper_book::score_title (SCM header)
 void
 set_page_permission (SCM sys, SCM symbol, SCM permission)
 {
-  if (Paper_score *ps = dynamic_cast<Paper_score *> (Music_output::unsmob (sys)))
+  if (Paper_score *ps = unsmob<Paper_score> (sys))
     {
       vector<Grob *> cols = ps->get_columns ();
       if (cols.size ())
@@ -336,7 +352,7 @@ set_page_permission (SCM sys, SCM symbol, SCM permission)
           col->find_prebroken_piece (LEFT)->set_property (symbol, permission);
         }
     }
-  else if (Prob *pb = Prob::unsmob (sys))
+  else if (Prob *pb = unsmob<Prob> (sys))
     pb->set_property (symbol, permission);
 }
 
@@ -370,7 +386,7 @@ set_system_penalty (SCM sys, SCM header)
 void
 set_labels (SCM sys, SCM labels)
 {
-  if (Paper_score *ps = dynamic_cast<Paper_score *> (Music_output::unsmob (sys)))
+  if (Paper_score *ps = unsmob<Paper_score> (sys))
     {
       vector<Grob *> cols = ps->get_columns ();
       if (cols.size ())
@@ -386,7 +402,7 @@ set_labels (SCM sys, SCM labels)
                                                              labels)));
         }
     }
-  else if (Prob *pb = Prob::unsmob (sys))
+  else if (Prob *pb = unsmob<Prob> (sys))
     pb->set_property ("labels",
                       scm_append_x (scm_list_2 (pb->get_property ("labels"),
                                                 labels)));
@@ -433,10 +449,8 @@ Paper_book::get_system_specs ()
     }
 
   SCM page_properties
-    = scm_call_1 (ly_lily_module_constant ("layout-extract-page-properties"),
-                  paper_->self_scm ());
+    = Lily::layout_extract_page_properties (paper_->self_scm ());
 
-  SCM interpret_markup_list = ly_lily_module_constant ("interpret-markup-list");
   SCM header = SCM_EOL;
   SCM labels = SCM_EOL;
   for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
@@ -444,10 +458,10 @@ Paper_book::get_system_specs ()
       if (ly_is_module (scm_car (s)))
         {
           header = scm_car (s);
-          if (header_0_ == SCM_EOL)
+          if (scm_is_null (header_0_))
             header_0_ = header;
         }
-      else if (Page_marker *page_marker = Page_marker::unsmob (scm_car (s)))
+      else if (Page_marker *page_marker = unsmob<Page_marker> (scm_car (s)))
         {
           /* page markers are used to set page breaking/turning permission,
              or to place bookmarking labels */
@@ -465,7 +479,7 @@ Paper_book::get_system_specs ()
               labels = scm_cons (page_marker->label (), labels);
             }
         }
-      else if (Music_output *mop = Music_output::unsmob (scm_car (s)))
+      else if (Music_output *mop = unsmob<Music_output> (scm_car (s)))
         {
           if (Paper_score *pscore = dynamic_cast<Paper_score *> (mop))
             {
@@ -474,10 +488,10 @@ Paper_book::get_system_specs ()
               if (scm_is_pair (system_specs))
                 set_system_penalty (scm_car (system_specs), header);
 
-              if (Prob::is_smob (title))
+              if (unsmob<Prob> (title))
                 {
                   system_specs = scm_cons (title, system_specs);
-                  Prob::unsmob (title)->unprotect ();
+                  unsmob<Prob> (title)->unprotect ();
                 }
 
               header = SCM_EOL;
@@ -497,10 +511,9 @@ Paper_book::get_system_specs ()
         }
       else if (Text_interface::is_markup_list (scm_car (s)))
         {
-          SCM texts = scm_call_3 (interpret_markup_list,
-                                  paper_->self_scm (),
-                                  page_properties,
-                                  scm_car (s));
+          SCM texts = Lily::interpret_markup_list (paper_->self_scm (),
+                                                   page_properties,
+                                                   scm_car (s));
           Prob *first = 0;
           Prob *last = 0;
           for (SCM list = texts; scm_is_pair (list); list = scm_cdr (list))
@@ -515,12 +528,12 @@ Paper_book::get_system_specs ()
               ps->set_property ("last-markup-line", SCM_BOOL_F);
               ps->set_property ("first-markup-line", SCM_BOOL_F);
 
-              paper_system_set_stencil (ps, *Stencil::unsmob (t));
+              paper_system_set_stencil (ps, *unsmob<Stencil> (t));
 
-              SCM footnotes = get_footnotes (Stencil::unsmob (t)->expr ());
+              SCM footnotes = get_footnotes (unsmob<Stencil> (t)->expr ());
               ps->set_property ("footnotes", footnotes);
               ps->set_property ("is-title", SCM_BOOL_T);
-              if (list == texts)
+              if (scm_is_eq (list, texts))
                 first = ps;
               else
                 {
@@ -560,7 +573,7 @@ Paper_book::get_system_specs ()
 SCM
 Paper_book::systems ()
 {
-  if (systems_ != SCM_BOOL_F)
+  if (scm_is_true (systems_))
     return systems_;
 
   systems_ = SCM_EOL;
@@ -568,7 +581,7 @@ Paper_book::systems ()
     {
       SCM system_list = SCM_EOL;
       for (SCM p = bookparts_; scm_is_pair (p); p = scm_cdr (p))
-        if (Paper_book *pbookpart = Paper_book::unsmob (scm_car (p)))
+        if (Paper_book *pbookpart = unsmob<Paper_book> (scm_car (p)))
           system_list = scm_cons (pbookpart->systems (), system_list);
       systems_ = scm_append (scm_reverse_x (system_list, SCM_EOL));
     }
@@ -578,7 +591,7 @@ Paper_book::systems ()
       for (SCM s = specs; scm_is_pair (s); s = scm_cdr (s))
         {
           if (Paper_score * pscore
-              = dynamic_cast<Paper_score *> (Music_output::unsmob (scm_car (s))))
+              = unsmob<Paper_score> (scm_car (s)))
             {
               SCM system_list
                 = scm_vector_to_list (pscore->get_paper_systems ());
@@ -597,7 +610,7 @@ Paper_book::systems ()
       Prob *last = 0;
       for (SCM s = systems_; scm_is_pair (s); s = scm_cdr (s))
         {
-          Prob *ps = Prob::unsmob (scm_car (s));
+          Prob *ps = unsmob<Prob> (scm_car (s));
           ps->set_property ("number", scm_from_int (++i));
 
           if (last
@@ -609,10 +622,10 @@ Paper_book::systems ()
           if (scm_is_pair (scm_cdr (s)))
             {
               SCM perm = ps->get_property ("page-break-permission");
-              Prob *next = Prob::unsmob (scm_cadr (s));
-              if (perm == SCM_EOL)
+              Prob *next = unsmob<Prob> (scm_cadr (s));
+              if (scm_is_null (perm))
                 next->set_property ("penalty", scm_from_int (10001));
-              else if (perm == ly_symbol2scm ("force"))
+              else if (scm_is_eq (perm, ly_symbol2scm ("force")))
                 next->set_property ("penalty", scm_from_int (-10001));
             }
         }
@@ -624,14 +637,14 @@ Paper_book::systems ()
 SCM
 Paper_book::pages ()
 {
-  if (SCM_BOOL_F != pages_)
+  if (scm_is_true (pages_))
     return pages_;
 
   pages_ = SCM_EOL;
   if (scm_is_pair (bookparts_))
     {
       for (SCM p = bookparts_; scm_is_pair (p); p = scm_cdr (p))
-        if (Paper_book *pbookpart = Paper_book::unsmob (scm_car (p)))
+        if (Paper_book *pbookpart = unsmob<Paper_book> (scm_car (p)))
           pages_ = scm_cons (pbookpart->pages (), pages_);
       pages_ = scm_append (scm_reverse_x (pages_, SCM_EOL));
     }
@@ -653,12 +666,12 @@ Paper_book::pages ()
         scm_call_2 (post_process, paper_->self_scm (), pages_);
 
       /* set systems_ from the pages */
-      if (systems_ == SCM_BOOL_F)
+      if (scm_is_false (systems_))
         {
           systems_ = SCM_EOL;
           for (SCM p = pages_; scm_is_pair (p); p = scm_cdr (p))
             {
-              Prob *page = Prob::unsmob (scm_car (p));
+              Prob *page = unsmob<Prob> (scm_car (p));
               SCM systems = page->get_property ("lines");
               systems_ = scm_cons (systems, systems_);
             }