--- /dev/null
+\version "2.13.4"
+
+#(ly:set-option 'warning-as-error #f)
+
+\header {
+ texidoc = "Margin values must fit the line-width, that means: paper-width =
+ line-width + left-margin + right-margin. In case they do not, default margins
+ are set and a warning is printed."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ left-margin = 20 \mm
+ right-margin = 40 \mm
+ line-width = 100 \mm
+}
+
+\score { \someNotes }
--- /dev/null
+\version "2.13.4"
+
+\header {
+ texidoc = "Here only left-margin is given, right-margin will remain default."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ left-margin = 40 \mm
+}
+
+\score { \someNotes }
--- /dev/null
+\version "2.13.4"
+
+\header {
+ texidoc = "If only line-width is given, systems are vertically centered."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ line-width = 100 \mm
+}
+
+\score { \someNotes }
--- /dev/null
+\version "2.13.4"
+
+\header {
+ texidoc = "All checks can be avoided by setting check-consistency to ##f in \paper."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ left-margin = 20 \mm
+ right-margin = 40 \mm
+ line-width = 200 \mm
+ check-consistency = ##f
+}
+
+\score { \someNotes }
+
+
--- /dev/null
+\version "2.13.4"
+
+#(ly:set-option 'warning-as-error #f)
+
+\header {
+ texidoc = "Normally, margin settings must not cause systems to run off the page."
+}
+
+#(set-default-paper-size "a4")
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ left-margin = 20 \mm
+ line-width = 200 \mm
+}
+
+\score { \someNotes }
--- /dev/null
+\version "2.13.4"
+
+\header {
+ texidoc = "Here only right-margin is given, left-margin will remain default."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper {
+ right-margin = 40 \mm
+}
+
+\score { \someNotes }
--- /dev/null
+\version "2.13.4"
+
+\header {
+ texidoc = "Paper margin settings do not have to be complete. Missing values are
+ added automatically. If no paper settings are specified, default values are
+ used."
+}
+
+someNotes = \relative c' { \repeat unfold 40 { c4 d e f }}
+
+\paper { }
+
+\score { \someNotes }
+
}
else
{
+ paper_book->paper_->normalize ();
/* Process scores */
/* Render in order of parsing. */
for (SCM s = scm_reverse (scores_); scm_is_pair (s); s = scm_cdr (s))
SCM c_variable (string id) const;
SCM lookup_variable (SCM sym) const;
void set_variable (SCM sym, SCM val);
+ void normalize ();
Real get_dimension (SCM symbol) const;
};
SCM get_font_table (Output_def *def);
void assign_context_def (Output_def *m, SCM transdef);
SCM find_context_def (Output_def const *m, SCM name);
-Interval line_dimensions_int (Output_def*def, int);
+Interval line_dimensions_int (Output_def *def, int);
Font_metric *select_encoded_font (Output_def *layout, SCM chain);
#include "context-def.hh"
#include "file-path.hh"
#include "global-context.hh"
+#include "international.hh"
#include "interval.hh"
#include "main.hh"
#include "output-def.hh"
parent_ = 0;
smobify_self ();
-
+
scope_ = ly_make_anonymous_module (false);
}
{
SCM sym = tp->get_context_name ();
m->set_variable (sym, transdef);
- }
+ }
}
/* find the translator for NAME. NAME must be a symbol. */
SCM var = ly_module_lookup (scope_, sym);
if (SCM_VARIABLEP (var) && SCM_VARIABLE_REF (var) != SCM_UNDEFINED)
return SCM_VARIABLE_REF (var);
-
+
if (parent_)
return parent_->lookup_variable (sym);
-
+
return SCM_UNDEFINED;
}
scm_module_define (scope_, sym, val);
}
-
+void
+Output_def::normalize ()
+{
+ Real paper_width;
+ SCM scm_paper_width = c_variable ("paper-width");
+
+ Real left_margin, left_margin_default;
+ SCM scm_left_margin_default = c_variable ("left-margin-default");
+ SCM scm_left_margin = c_variable ("left-margin");
+
+ Real right_margin, right_margin_default;
+ SCM scm_right_margin_default = c_variable ("right-margin-default");
+ SCM scm_right_margin = c_variable ("right-margin");
+
+ if (scm_paper_width == SCM_UNDEFINED
+ || scm_left_margin_default == SCM_UNDEFINED
+ || scm_right_margin_default == SCM_UNDEFINED)
+ {
+ programming_error ("called normalize() on paper with missing settings");
+ return;
+ }
+ else
+ {
+ paper_width = scm_to_double (scm_paper_width);
+ left_margin_default = scm_to_double (scm_left_margin_default);
+ right_margin_default = scm_to_double (scm_right_margin_default);
+ }
+
+ Real line_width;
+ Real line_width_default = paper_width - left_margin_default - right_margin_default;
+ SCM scm_line_width = c_variable ("line-width");
+
+ if (scm_line_width == SCM_UNDEFINED)
+ {
+ left_margin = ((scm_left_margin == SCM_UNDEFINED) ? left_margin_default : scm_to_double(scm_left_margin));
+ right_margin = ((scm_right_margin == SCM_UNDEFINED) ? right_margin_default : scm_to_double(scm_right_margin));
+ line_width = paper_width - left_margin - right_margin;
+ }
+ else
+ {
+ line_width = scm_to_double (scm_line_width);
+ if (scm_left_margin == SCM_UNDEFINED)
+ {
+ if (scm_right_margin == SCM_UNDEFINED) // Vertically center systems if only line-width is given
+ {
+ left_margin = (paper_width - line_width) / 2;
+ right_margin = left_margin;
+ }
+ else
+ {
+ right_margin = scm_to_double (scm_right_margin);
+ left_margin = paper_width - line_width - right_margin;
+ }
+ }
+ else
+ {
+ left_margin = scm_to_double (scm_left_margin);
+ right_margin = ((scm_right_margin == SCM_UNDEFINED)
+ ? (paper_width - line_width - left_margin)
+ : scm_to_double (scm_right_margin));
+ }
+ }
+
+ if (to_boolean (c_variable ("check-consistency")))
+ {
+ // Consistency checks. If values don't match, set defaults.
+ if (abs(paper_width - line_width - left_margin - right_margin) > 1e-6)
+ {
+ line_width = line_width_default;
+ left_margin = left_margin_default;
+ right_margin = right_margin_default;
+ warning (_ ("margins do not fit with line-width, setting default values"));
+ }
+ else if ((left_margin < 0) || (right_margin < 0))
+ {
+ line_width = line_width_default;
+ left_margin = left_margin_default;
+ right_margin = right_margin_default;
+ warning (_ ("systems run off the page due to improper paper settings, setting default values"));
+ }
+ }
+
+ set_variable (ly_symbol2scm ("left-margin"), scm_from_double (left_margin));
+ set_variable (ly_symbol2scm ("right-margin"), scm_from_double (right_margin));
+ set_variable (ly_symbol2scm ("line-width"), scm_from_double (line_width));
+}
+
/* FIXME. This is broken until we have a generic way of
putting lists inside the \layout block. */
Interval
{
int first_page_number = robust_scm2int (paper_->c_variable ("first-page-number"), 1);
int first_performance_number = 0;
+
+ /* FIXME: We need a line-width for ps output (framework-ps.scm:92). If we don't have any, we take the paper-width
+ unless we know better which line-width to choose (e.g. if there are \bookparts with different line-widths)
+ and why we need it at all. */
+
+ if (paper_->c_variable ("line-width") == SCM_UNDEFINED)
+ paper_->set_variable (ly_symbol2scm ("line-width"), paper_->c_variable ("paper-width"));
+
if (!output_aux (output_channel,
true,
&first_page_number,
&first_performance_number))
return;
-
+
+
SCM scopes = SCM_EOL;
if (ly_is_module (header_))
scopes = scm_cons (header_, scopes);
\include "titling-init.ly"
+ check-consistency = ##t
+
top-margin = 5 \mm
bottom-margin = 6 \mm
+
+ left-margin-default = 10 \mm
+ right-margin-default = 10 \mm
+
head-separation = 4 \mm
foot-separation = 4 \mm
first-page-number = #1
- print-first-page-number =##f
+ print-first-page-number = ##f
}
(let*
((paper-height (ly:output-def-lookup layout 'paper-height))
(paper-width (ly:output-def-lookup layout 'paper-width))
- (lmargin (ly:output-def-lookup layout 'left-margin #f))
- (left-margin (if lmargin
- lmargin
- (/ (- paper-width
- (ly:output-def-lookup layout 'line-width)) 2)))
+ (left-margin (ly:output-def-lookup layout 'left-margin))
(bottom-edge (- paper-height
(ly:output-def-lookup layout 'bottom-margin)) )
(top-margin (ly:output-def-lookup layout 'top-margin))
indent
ledger-line-thickness
left-margin
+ left-margin-default
line-thickness
line-width
mm
paper-width
pt
right-margin
+ right-margin-default
short-indent
staff-height
staff-space
("f4" . (cons (* 210 mm) (* 330 mm)))
))
-;; todo: take dimension arguments.
+; todo: take dimension arguments.
(define (set-paper-dimensions m w h)
"M is a module (i.e. layout->scope_ )"
- (let* ((mm (eval 'mm m)))
+ (begin
+ ;; page layout - what to do with (printer specific!) margin settings?
(module-define! m 'paper-width w)
(module-define! m 'paper-height h)
- (module-define! m 'line-width (- w
- (ly:modules-lookup (list m) 'left-margin (* 10 mm))
- (ly:modules-lookup (list m) 'right-margin (* 10 mm))))
-
(module-define! m 'indent (/ w 14))
- (module-define! m 'short-indent 0)
-
- ;; page layout - what to do with (printer specific!) margin settings?
-
- ))
+ (module-define! m 'short-indent 0))
+ (module-remove! m 'line-width))
(define (internal-set-paper-size module name landscape?)
(define (swap x)
if not INDENT in self.option_dict:
self.option_dict[INDENT] = '0\\mm'
+ # Set a default line-width if there is none. We need this, because
+ # lilypond-book has set left-padding by default and therefore does
+ # #(define line-width (- line-width (* 3 mm)))
+ # TODO: Junk this ugly hack if the code gets rewritten to concatenate
+ # all settings before writing them in the \paper block.
+ if not LINE_WIDTH in self.option_dict:
+ if not QUOTE in self.option_dict:
+ if not LILYQUOTE in self.option_dict:
+ self.option_dict[LINE_WIDTH] = "#(- paper-width \
+left-margin-default right-margin-default)"
+
def compose_ly (self, code):
if FRAGMENT in self.option_dict:
body = FRAGMENT_LY