lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Paper default margins - revised


From: Michael Käppler
Subject: Re: [PATCH] Paper default margins - revised
Date: Sat, 03 Oct 2009 15:41:53 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20071114)


Hopefully no whitespace / style issues this time.
Argh... forget this.

Here's a revised version.

Cheers,
Michael
>From cf099ca1134b02a813e47109c684a8a100b04253 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Michael=20K=C3=A4ppler?= <address@hidden>
Date: Sat, 12 Sep 2009 21:55:17 +0200
Subject: [PATCH] Let default margins depend on paper size.

* 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
---
 input/regression/paper-default-margins.ly |   32 +++++++++++++++
 lily/output-def.cc                        |    4 +-
 ly/paper-defaults-init.ly                 |   14 +++++--
 scm/lily-library.scm                      |   11 +++++
 scm/paper.scm                             |   59 +++++++++++++++++++++++++----
 5 files changed, 106 insertions(+), 14 deletions(-)
 create mode 100644 input/regression/paper-default-margins.ly

diff --git a/input/regression/paper-default-margins.ly 
b/input/regression/paper-default-margins.ly
new file mode 100644
index 0000000..4bb9a27
--- /dev/null
+++ b/input/regression/paper-default-margins.ly
@@ -0,0 +1,32 @@
+\version "2.13.4"
+
+\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 }
+
+\book {
+  \paper { }
+  \markup { If the paper size remains default, the margin values from
+            paper-defaults-init.ly remain unchanged. }
+  \score { \relative c' { \someNotes \someNotes}}
+}
+
+\book {
+  \paper {
+    #(set-paper-size "a6")
+  }
+  \markup { For other paper sizes, margins are scaled accordingly. }
+  \score { \relative c' { \someNotes }}
+}
+
+\book {
+  \paper {
+    #(set-paper-size "a2")
+  }
+  \score { \relative c' { \someNotes \someNotes \someNotes}}
+}
diff --git a/lily/output-def.cc b/lily/output-def.cc
index 4a1ce21..3461e3c 100644
--- a/lily/output-def.cc
+++ b/lily/output-def.cc
@@ -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
diff --git a/ly/paper-defaults-init.ly b/ly/paper-defaults-init.ly
index 4db5459..0345319 100644
--- a/ly/paper-defaults-init.ly
+++ b/ly/paper-defaults-init.ly
@@ -88,14 +88,20 @@
 
   check-consistency = ##t
 
-  top-margin = 5 \mm
-  bottom-margin = 6 \mm
+  % This 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
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 827fb24..03b376c 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -607,6 +607,17 @@ 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)
+  (if (module-defined? module symbol)
+      (eval symbol module)
+      (let* ((def (and (not (null? default)) (car default))))
+        (ly:programming-error
+          "cannot evaluate symbol ~S in module ~S, setting to ~S"
+          (object->string symbol)
+          (object->string module)
+          (object->string def))
+        def)))
+
 ;;
 ;; don't confuse users with #<procedure .. > syntax.
 ;;
diff --git a/scm/paper.scm b/scm/paper.scm
index 1eb3b59..a3ae873 100644
--- a/scm/paper.scm
+++ b/scm/paper.scm
@@ -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,56 @@ 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))
+    ((mm (eval-carefully 'mm m 1))
+     (paper-default (eval
+                      (assoc-get
+                       (ly:get-option 'paper-size)
+                       paper-alist
+                       (cons (* 210 mm) (* 279 mm)))
+                     m))
+     (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))
+  (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)
-- 
1.6.0.2


reply via email to

[Prev in Thread] Current Thread [Next in Thread]