]> git.donarmstrong.com Git - lilypond.git/commitdiff
Let default margins depend on paper size.
authorMichael Käppler <xmichael-k@web.de>
Sat, 12 Sep 2009 19:55:17 +0000 (21:55 +0200)
committerNeil Puttock <n.puttock@gmail.com>
Thu, 29 Oct 2009 00:18:15 +0000 (00:18 +0000)
* Make indent and short-indent defaults accessible in paper-defaults-init.ly

* Default margins apply to the paper size set by (ly:set-option 'paper-size)
  and are linearly scaled for other paper sizes

* Modify input/regression/page-turn-page-breaking-auto-first-page.ly to work
  with the new margin sizes

14 files changed:
input/regression/page-turn-page-breaking-auto-first-page.ly
input/regression/paper-default-margins-a6.ly [new file with mode: 0644]
input/regression/paper-default-margins-def.ly [new file with mode: 0644]
input/regression/paper-margins-consistency.ly
input/regression/paper-margins-left-margin.ly
input/regression/paper-margins-line-width.ly
input/regression/paper-margins-no-checks.ly
input/regression/paper-margins-overrun.ly
input/regression/paper-margins-right-margin.ly
input/regression/paper-margins.ly
lily/output-def.cc
ly/paper-defaults-init.ly
scm/lily-library.scm
scm/paper.scm

index a9c3f31bf93db71e7a21d1d94c53f418b8337620..0aa55705c1c103646854f11a212a9d11b4057c3c 100644 (file)
@@ -17,6 +17,6 @@ number to 2 in order to avoid a bad page turn."
 
 \book {
   \score {
-    {\repeat unfold 40 {a b c d}}
+    \relative c' {\repeat unfold 60 {a b c d}}
   }
-}
\ No newline at end of file
+}
diff --git a/input/regression/paper-default-margins-a6.ly b/input/regression/paper-default-margins-a6.ly
new file mode 100644 (file)
index 0000000..163a9bf
--- /dev/null
@@ -0,0 +1,24 @@
+\version "2.13.7"
+
+\header {
+  texidoc = "Default margin values are accessible in paper-defaults-init.ly
+and apply to the default paper size returned by (ly:get-option
+'paper-size). For other paper sizes, they are scaled linearly.
+This also affects head- and foot-separation as well as indents."
+}
+
+someNotes = \repeat unfold 30 { c4 d e f }
+
+\paper {
+  #(set-paper-size "a6")
+}
+
+\book {
+  \markup { For other paper sizes, margins are scaled accordingly. }
+  \score {
+    \relative c' {
+      \someNotes
+    }
+  }
+}
+
diff --git a/input/regression/paper-default-margins-def.ly b/input/regression/paper-default-margins-def.ly
new file mode 100644 (file)
index 0000000..8e22229
--- /dev/null
@@ -0,0 +1,25 @@
+\version "2.13.7"
+
+\header {
+  texidoc = "Default margin values are accessible in paper-defaults-init.ly
+and apply to the default paper size returned by (ly:get-option
+'paper-size). For other paper sizes, they are scaled linearly.
+This also affects head- and foot-separation as well as indents."
+}
+
+someNotes = \repeat unfold 30 { c4 d e f }
+
+\paper {
+  #(set-paper-size (ly:get-option 'paper-size))
+}
+
+\book {
+  \markup { If the paper size remains default, the margin values from
+            paper-defaults-init.ly remain unchanged. }
+  \score {
+    \relative c' {
+      \someNotes
+      \someNotes
+    }
+  }
+}
index 1b58b15d95f9fad1754e60e01390b654d5a508d7..a3a7a409c7525b1b8c654938787d57275b4742ca 100644 (file)
@@ -16,4 +16,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
index 58761964578ab2e51a28ba6fc344b96ce6070438..23268e2d0b280c7f37dde45faf0856a61495e906 100644 (file)
@@ -7,7 +7,10 @@
 someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
 
 \paper {
+  #(set-paper-size (ly:get-option 'paper-size))
   left-margin = 40 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
index bf6e14d7c8cbc51199519a00e069fd44c71d78b2..e38f57f48d120ecf41e791c6a813abecd41db719 100644 (file)
@@ -10,4 +10,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
index 119235edeac69ad0e91f5e29ad427b0b604ba8ba..5f3e7833eb1e3f00662bfd388cc19b3a133c4a39 100644 (file)
@@ -13,6 +13,8 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   check-consistency = ##f
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
 
 
index ebe42690f6f82410f52927709c1a62aa4d104d69..1492de93c61cddc6a07538a1e18e247a4d445f28 100644 (file)
@@ -15,4 +15,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 200 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
index 40091b43dce02ed124de0dc163b8cbd6832c55f4..eaa4b1a254dadf6d23a0e8f4fcaa9cc8abdd429d 100644 (file)
@@ -7,7 +7,10 @@
 someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
 
 \paper {
+  #(set-paper-size (ly:get-option 'paper-size))
   right-margin = 40 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
index 99d584133f78c86bd64169b1572ea05be8b8b239..29538914c51c7b459e1f317bed05de7a08e04fe4 100644 (file)
@@ -8,7 +8,11 @@ are specified, default values are used."
 
 someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
 
-\paper { }
+\paper {
+  #(set-paper-size (ly:get-option 'paper-size))
+}
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
 
index 4a1ce211ba741336a20d11d77a01c66e5a7ff62a..3461e3c920cd727d121f6c4f7f0214dc96f442e6 100644 (file)
@@ -136,11 +136,11 @@ Output_def::normalize ()
   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_default = c_variable ("left-margin-default-scaled");
   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_default = c_variable ("right-margin-default-scaled");
   SCM scm_right_margin = c_variable ("right-margin");
 
   if (scm_paper_width == SCM_UNDEFINED
index df7a63b768a1cad7834f15f4dbf1a85ae418178f..8be089f618fb70ae3fd5321f6f7dd4ba0a365204 100644 (file)
 
   check-consistency = ##t
 
-  top-margin = 5 \mm
-  bottom-margin = 6 \mm
+  % These margins apply to the default paper format given by (ly:get-option 'paper-size)
+  % and are scaled accordingly for other formats
+
+  top-margin-default = 5 \mm
+  bottom-margin-default = 6 \mm
 
   left-margin-default = 10 \mm
   right-margin-default = 10 \mm
 
-  head-separation = 4 \mm
-  foot-separation = 4 \mm
+  head-separation-default = 4 \mm
+  foot-separation-default = 4 \mm
+
+  indent-default = 15 \mm
+  short-indent-default = 0 \mm
 
   first-page-number = #1
   print-first-page-number = ##f
index 827fb24cabfa875f6b269a879bb089f33e272a08..4a7973abb1b39e1447cd3ea2e79fe44d7715ff32 100644 (file)
    (lambda (x) x)
    (map proc lst)))
 
-
-(define (flatten-list lst)
-  "Unnest LST"
-  (if (null? lst)
-      '()
-      (if (pair? (car lst))
-         (append (flatten-list (car lst)) (flatten-list  (cdr lst)))
-         (cons (car lst) (flatten-list (cdr lst))))))
+(define (flatten-list x)
+  "Unnest list."
+  (cond ((null? x) '())
+        ((not (pair? x)) (list x))
+        (else (append (flatten-list (car x))
+                      (flatten-list (cdr x))))))
 
 (define (list-minus a b)
   "Return list of elements in A that are not in B."
@@ -607,6 +605,29 @@ applied to function @var{getter}.")
 (define-public (symbol-key<? lst r)
   (string<? (symbol->string (car lst)) (symbol->string (car r))))
 
+(define-public (eval-carefully symbol module . default)
+  "Check if all symbols in expr SYMBOL are reachable
+   in module MODULE. In that case evaluate, otherwise
+   print a warning and set an optional DEFAULT."
+  (let* ((unavailable? (lambda (sym)
+                         (not (module-defined? module sym))))
+        (sym-unavailable (if (pair? symbol)
+                             (filter
+                               unavailable?
+                               (filter symbol? (flatten-list symbol)))
+                             (if (unavailable? symbol)
+                                  #t
+                                  '()))))
+    (if (null? sym-unavailable)
+        (eval symbol module)
+        (let* ((def (and (pair? default) (car default))))
+          (ly:programming-error
+            "cannot evaluate ~S in module ~S, setting to ~S"
+            (object->string symbol)
+            (object->string module)
+            (object->string def))
+          def))))
+
 ;;
 ;; don't confuse users with #<procedure .. > syntax.
 ;;
index 1eb3b59a1a2ee57983af29ff46eb25eb4c9f381a..0b5a60ec8d3371dd23275081dcddc0e164213681 100644 (file)
@@ -16,7 +16,7 @@
                    indent
                    ledger-line-thickness
                    left-margin
-                    left-margin-default
+                    left-margin-default-scaled
                    line-thickness
                    line-width
                    mm
@@ -24,7 +24,7 @@
                    paper-width
                    pt
                    right-margin
-                    right-margin-default
+                    right-margin-default-scaled
                    short-indent
                    staff-height
                    staff-space
@@ -213,13 +213,63 @@ size. SZ is in points"
 
 (define (set-paper-dimensions m w h)
   "M is a module (i.e. layout->scope_ )"
-  (begin
+  (let*
     ;; 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 'indent (/ w 14))
-    (module-define! m 'short-indent 0))
-    (module-remove! m 'line-width))
+    ((paper-default (eval-carefully
+                      (assoc-get
+                       (ly:get-option 'paper-size)
+                       paper-alist
+                       #f
+                       #t)
+                     m
+                     (cons w h)))
+     (scaleable-values `(("left-margin" . ,w)
+                         ("right-margin" . ,w)
+                         ("top-margin" . ,h)
+                         ("bottom-margin" . ,h)
+                         ("head-separation" . ,h)
+                         ("foot-separation" . ,h)
+                         ("indent" . ,w)
+                         ("short-indent" . ,w)))
+     (scaled-values
+       (map
+         (lambda (entry)
+           (let ((entry-symbol
+                  (string->symbol
+                     (string-append (car entry) "-default")))
+                (orientation (cdr entry)))
+             (if paper-default
+                 (cons (car entry)
+                       (round (* orientation
+                                 (/ (eval-carefully entry-symbol m 0)
+                                    (if (= orientation w)
+                                        (car paper-default)
+                                        (cdr paper-default))))))
+                 entry)))
+        scaleable-values)))
+
+  (module-define! m 'paper-width w)
+  (module-define! m 'paper-height h)
+  ;; Left and right margin are stored in renamed variables because
+  ;; they must not be overwritten.
+  ;; Output_def::normalize () needs to know
+  ;; whether the user set the value or not.
+  (module-define! m 'left-margin-default-scaled
+    (assoc-get "left-margin" scaled-values 0 #t))
+  (module-define! m 'right-margin-default-scaled
+    (assoc-get "right-margin" scaled-values 0 #t))
+  ;; Sometimes, lilypond-book doesn't estimate a correct line-width.
+  ;; Therefore, we need to unset line-width.
+  (module-remove! m 'line-width)
+  (set! scaled-values (assoc-remove!
+                        (assoc-remove! scaled-values "left-margin")
+                       "right-margin"))
+  (for-each
+     (lambda (value)
+        (let ((value-symbol (string->symbol (car value)))
+              (number (cdr value)))
+          (module-define! m value-symbol number)))
+     scaled-values)))
 
 (define (internal-set-paper-size module name landscape?)
   (define (swap x)