Re: Paper default margins

View: New views
9 Messages — Rating Filter:   Alert me  

Parent Message unknown Re: Paper default margins

by Neil Puttock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/18 Michael Käppler <xmichael-k@...>:

> I've expanded the regtests to get enough pages.
> Ready to apply?

\book {
   \score {
-    {
+    \relative c' {
       a b c d R1
-      \repeat unfold 26 {a4 b c d}
+      \repeat unfold 40 {a4 b c d}
     }
   }
 }

You don't need to change this test.

I think you'll have to split paper-default-margins.ly into separate
files, otherwise it won't work; due to the multiple \book blocks, only
the first book will appear.

+             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."

no indent for these lines

+  % This margins apply to the default paper format given by
(ly:get-option 'paper-size)

% These

+(define-public (all-items lst)

This is rather vaguely named, and looks similar to flatten-list.  I
think it would be better to keep flatten-list, but amend it to support
pairs.

I wonder why it can't be much simpler (while supporting flattening of
pairs without changing their positions):

(define (flatten-list x)
    (cond ((null? x) '())
          ((not (pair? x)) (list x))
          (else (append (flatten-list (car x))
                        (flatten-list (cdr x))))))

+        (let* ((def (and (not (null? default)) (car default))))

(let ((def (and (pair? default) (car default))))

+      (let* ((entry-symbol

(let ((
space before tab

+     (string->symbol

space before tab

+        (let* ((value-symbol (string->symbol (car value)))

(let ((

Regards,
Neil

[0001-Let-default-margins-depend-on-paper-size.patch]

From 2630603f64a8a1d5a6f74aeace9f421cf2379afd Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...>
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

* Modify input/regression/page-turn-page-breaking-auto-first-page.ly to work
  with the new margin sizes
---
 .../page-turn-page-breaking-auto-first-page.ly     |    4 +-
 .../page-turn-page-breaking-auto-first-page2.ly    |    4 +-
 input/regression/paper-default-margins.ly          |   32 ++++++++++
 lily/output-def.cc                                 |    4 +-
 ly/paper-defaults-init.ly                          |   14 +++-
 scm/lily-library.scm                               |   41 ++++++++++++
 scm/paper.scm                                      |   66 +++++++++++++++++---
 7 files changed, 147 insertions(+), 18 deletions(-)
 create mode 100644 input/regression/paper-default-margins.ly

diff --git a/input/regression/page-turn-page-breaking-auto-first-page.ly b/input/regression/page-turn-page-breaking-auto-first-page.ly
index a9c3f31..0aa5570 100644
--- a/input/regression/page-turn-page-breaking-auto-first-page.ly
+++ b/input/regression/page-turn-page-breaking-auto-first-page.ly
@@ -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/page-turn-page-breaking-auto-first-page2.ly b/input/regression/page-turn-page-breaking-auto-first-page2.ly
index a71c222..7161e0e 100644
--- a/input/regression/page-turn-page-breaking-auto-first-page2.ly
+++ b/input/regression/page-turn-page-breaking-auto-first-page2.ly
@@ -25,9 +25,9 @@ number to 2 in order to avoid a bad page turn."
 
 \book {
   \score {
-    {
+    \relative c' {
       a b c d R1
-      \repeat unfold 26 {a4 b c d}
+      \repeat unfold 40 {a4 b c d}
     }
   }
 }
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..88c2e8d 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -399,6 +399,24 @@
       (cons (cons (car coords) (cadr coords))
     (ly:list->offsets accum (cddr coords)))))
 
+(define-public (all-items lst)
+  "Concatenate all layers of a list into one.
+   The elements' order is not preserved.
+   Example: '(2 '('bla' . 'blu') 'p 54) ->
+   '(2 'p 54 'bla' 'blu')"
+  (let* ((pairs (filter pair? lst))
+         (pair->listpart
+           (lambda (pair)
+             (list (car pair) (cdr pair))))
+         (deflated-pairs (apply append
+                   (map pair->listpart pairs)))
+         (deflated-lst
+           (append
+             (lset-difference eqv? lst pairs) deflated-pairs)))
+    (if (null? (filter pair? deflated-lst))
+      deflated-lst
+      (all-items deflated-lst))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; numbers
 
@@ -607,6 +625,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? (all-items symbol)))
+      (if (unavailable? symbol)
+           #t
+   '()))))
+    (if (null? sym-unavailable)
+        (eval symbol module)
+        (let* ((def (and (not (null? 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.
 ;;
diff --git a/scm/paper.scm b/scm/paper.scm
index 1eb3b59..ea95a57 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,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)
--
1.6.0.2



_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Michael Käppler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Neil,
thanks for your review. It's all ok (Though it's hard to see how simple
it could have been with flatten-list...)
However, I don't understand the thing about the old regtests. I thought
that both page-turn-page-breaking-auto-first-page*.ly would need two
pages to demonstrate the functionality. But they both had just one after
the change, don't they?
Which one shall I do not change and why?

Regards,
Michael


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Neil Puttock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/23 Michael Käppler <xmichael-k@...>:

> However, I don't understand the thing about the old regtests. I thought that
> both page-turn-page-breaking-auto-first-page*.ly would need two pages to
> demonstrate the functionality. But they both had just one after the change,
> don't they?
> Which one shall I do not change and why?

Change the snippet which appears in the regression test results
(page-turn-page-breaking-auto-first-page.ly).

In the case of page-turn-breaking-auto-first-page2.ly, though the
snippet would easily fit on one page (try removing the
Page_turn_engraver and the setting for auto-first-page to verify this)
the second page is generated automatically when auto-first-page = ##t,
since there would normally be a page break after the full-bar rest
(which would look bad).

Regards,
Neil


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Michael Käppler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here you are.
What about the docs patch?

Regards,
Michael


From 3cda0a2d5326b2359784ca1e10b04b078abd2cb9 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...>
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

* Modify input/regression/page-turn-page-breaking-auto-first-page.ly to work
  with the new margin sizes
---
 .../page-turn-page-breaking-auto-first-page.ly     |    4 +-
 input/regression/paper-default-margins-a2.ly       |   16 +++++
 input/regression/paper-default-margins-a6.ly       |   18 +++++
 input/regression/paper-default-margins-def.ly      |   17 +++++
 lily/output-def.cc                                 |    4 +-
 ly/paper-defaults-init.ly                          |   14 +++-
 scm/lily-library.scm                               |   37 +++++++++---
 scm/paper.scm                                      |   66 +++++++++++++++++---
 8 files changed, 152 insertions(+), 24 deletions(-)
 create mode 100644 input/regression/paper-default-margins-a2.ly
 create mode 100644 input/regression/paper-default-margins-a6.ly
 create mode 100644 input/regression/paper-default-margins-def.ly

diff --git a/input/regression/page-turn-page-breaking-auto-first-page.ly b/input/regression/page-turn-page-breaking-auto-first-page.ly
index a9c3f31..0aa5570 100644
--- a/input/regression/page-turn-page-breaking-auto-first-page.ly
+++ b/input/regression/page-turn-page-breaking-auto-first-page.ly
@@ -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-a2.ly b/input/regression/paper-default-margins-a2.ly
new file mode 100644
index 0000000..add59da
--- /dev/null
+++ b/input/regression/paper-default-margins-a2.ly
@@ -0,0 +1,16 @@
+\version "2.13.6"
+
+\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 "a2")
+}
+
+\score { \relative c' { \someNotes \someNotes \someNotes}}
diff --git a/input/regression/paper-default-margins-a6.ly b/input/regression/paper-default-margins-a6.ly
new file mode 100644
index 0000000..3973be9
--- /dev/null
+++ b/input/regression/paper-default-margins-a6.ly
@@ -0,0 +1,18 @@
+\version "2.13.6"
+
+\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")
+}
+
+\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
index 0000000..cd7d2e2
--- /dev/null
+++ b/input/regression/paper-default-margins-def.ly
@@ -0,0 +1,17 @@
+\version "2.13.6"
+
+\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 { }
+
+\markup { If the paper size remains default, the margin values from
+            paper-defaults-init.ly remain unchanged. }
+
+\score { \relative c' { \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 df7a63b..8be089f 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
+  % 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
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 827fb24..4a7973a 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -333,14 +333,12 @@
    (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.
 ;;
diff --git a/scm/paper.scm b/scm/paper.scm
index 1eb3b59..0b5a60e 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,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)
--
1.6.0.2


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Neil Puttock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/25 Michael Käppler <xmichael-k@...>:
> Here you are.

LGTM.

If you can sort out the following issues, I think it'll be ready for applying.

-) The a2 test is too wide.  I think having the a6 test should suffice
to show the scaled values.

-) The \version strings need updating to 2.13.7.

-) The new regtests (including the ones from your previous patch)
would benefit from having explicit \book blocks.

> What about the docs patch?

I'll look at that once this is sorted.

Cheers,
Neil


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Michael Käppler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Neil,
I hope I've lost nothing.

Regards,
Michael

From aa34f02a9eb85aaa39d3ff45f31597d279330461 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...>
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

* Modify input/regression/page-turn-page-breaking-auto-first-page.ly to work
  with the new margin sizes
---
 .../page-turn-page-breaking-auto-first-page.ly     |    4 +-
 input/regression/paper-default-margins-a6.ly       |   24 +++++++
 input/regression/paper-default-margins-def.ly      |   23 +++++++
 input/regression/paper-margins-consistency.ly      |    4 +-
 input/regression/paper-margins-left-margin.ly      |    4 +-
 input/regression/paper-margins-line-width.ly       |    4 +-
 input/regression/paper-margins-no-checks.ly        |    4 +-
 input/regression/paper-margins-overrun.ly          |    4 +-
 input/regression/paper-margins-right-margin.ly     |    4 +-
 input/regression/paper-margins.ly                  |    4 +-
 lily/output-def.cc                                 |    4 +-
 ly/paper-defaults-init.ly                          |   14 +++-
 scm/lily-library.scm                               |   37 +++++++++---
 scm/paper.scm                                      |   66 +++++++++++++++++---
 14 files changed, 169 insertions(+), 31 deletions(-)
 create mode 100644 input/regression/paper-default-margins-a6.ly
 create mode 100644 input/regression/paper-default-margins-def.ly

diff --git a/input/regression/page-turn-page-breaking-auto-first-page.ly b/input/regression/page-turn-page-breaking-auto-first-page.ly
index a9c3f31..0aa5570 100644
--- a/input/regression/page-turn-page-breaking-auto-first-page.ly
+++ b/input/regression/page-turn-page-breaking-auto-first-page.ly
@@ -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
index 0000000..163a9bf
--- /dev/null
+++ b/input/regression/paper-default-margins-a6.ly
@@ -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
index 0000000..82afc4d
--- /dev/null
+++ b/input/regression/paper-default-margins-def.ly
@@ -0,0 +1,23 @@
+\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 { }
+
+\book {
+  \markup { If the paper size remains default, the margin values from
+            paper-defaults-init.ly remain unchanged. }
+  \score {
+    \relative c' {
+      \someNotes
+      \someNotes
+    }
+  }
+}
diff --git a/input/regression/paper-margins-consistency.ly b/input/regression/paper-margins-consistency.ly
index 1b58b15..a3a7a40 100644
--- a/input/regression/paper-margins-consistency.ly
+++ b/input/regression/paper-margins-consistency.ly
@@ -16,4 +16,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-left-margin.ly b/input/regression/paper-margins-left-margin.ly
index 5876196..efb9981 100644
--- a/input/regression/paper-margins-left-margin.ly
+++ b/input/regression/paper-margins-left-margin.ly
@@ -10,4 +10,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   left-margin = 40 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-line-width.ly b/input/regression/paper-margins-line-width.ly
index bf6e14d..e38f57f 100644
--- a/input/regression/paper-margins-line-width.ly
+++ b/input/regression/paper-margins-line-width.ly
@@ -10,4 +10,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-no-checks.ly b/input/regression/paper-margins-no-checks.ly
index 119235e..5f3e783 100644
--- a/input/regression/paper-margins-no-checks.ly
+++ b/input/regression/paper-margins-no-checks.ly
@@ -13,6 +13,8 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   check-consistency = ##f
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
 
 
diff --git a/input/regression/paper-margins-overrun.ly b/input/regression/paper-margins-overrun.ly
index ebe4269..1492de9 100644
--- a/input/regression/paper-margins-overrun.ly
+++ b/input/regression/paper-margins-overrun.ly
@@ -15,4 +15,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 200 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-right-margin.ly b/input/regression/paper-margins-right-margin.ly
index 40091b4..a2c5977 100644
--- a/input/regression/paper-margins-right-margin.ly
+++ b/input/regression/paper-margins-right-margin.ly
@@ -10,4 +10,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   right-margin = 40 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly
index 99d5841..52e09a9 100644
--- a/input/regression/paper-margins.ly
+++ b/input/regression/paper-margins.ly
@@ -10,5 +10,7 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
 
 \paper { }
 
-\score { \someNotes }
+\book {
+  \score { \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 df7a63b..8be089f 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
+  % 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
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 827fb24..4a7973a 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -333,14 +333,12 @@
    (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.
 ;;
diff --git a/scm/paper.scm b/scm/paper.scm
index 1eb3b59..0b5a60e 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,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)
--
1.6.0.2


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Neil Puttock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/26 Michael Käppler <xmichael-k@...>:
> Hi Neil,
> I hope I've lost nothing.

Looks fine.

Sorry to be a pain, but there's one more thing I missed: all the
regtests which rely on default settings need to reset the default
paper size, otherwise the line-width setting from the lilypond-book
preamble messes up the spacing.

Thanks,
Neil


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Michael Käppler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Neil,
> Looks fine.
>  
Good.
> Sorry to be a pain, but there's one more thing I missed: all the
> regtests which rely on default settings need to reset the default
> paper size, otherwise the line-width setting from the lilypond-book
> preamble messes up the spacing.
>  
Okay. I hadn't thought about this. Fixed now.

Cheers,
Michael

From 99e7ed230c22109e7c93ff26dcbbcd26a76a5539 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Michael=20K=C3=A4ppler?= <xmichael-k@...>
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

* Modify input/regression/page-turn-page-breaking-auto-first-page.ly to work
  with the new margin sizes
---
 .../page-turn-page-breaking-auto-first-page.ly     |    4 +-
 input/regression/paper-default-margins-a6.ly       |   24 +++++++
 input/regression/paper-default-margins-def.ly      |   25 ++++++++
 input/regression/paper-margins-consistency.ly      |    4 +-
 input/regression/paper-margins-left-margin.ly      |    5 +-
 input/regression/paper-margins-line-width.ly       |    4 +-
 input/regression/paper-margins-no-checks.ly        |    4 +-
 input/regression/paper-margins-overrun.ly          |    4 +-
 input/regression/paper-margins-right-margin.ly     |    5 +-
 input/regression/paper-margins.ly                  |    8 ++-
 lily/output-def.cc                                 |    4 +-
 ly/paper-defaults-init.ly                          |   14 +++-
 scm/lily-library.scm                               |   37 +++++++++---
 scm/paper.scm                                      |   66 +++++++++++++++++---
 14 files changed, 176 insertions(+), 32 deletions(-)
 create mode 100644 input/regression/paper-default-margins-a6.ly
 create mode 100644 input/regression/paper-default-margins-def.ly

diff --git a/input/regression/page-turn-page-breaking-auto-first-page.ly b/input/regression/page-turn-page-breaking-auto-first-page.ly
index a9c3f31..0aa5570 100644
--- a/input/regression/page-turn-page-breaking-auto-first-page.ly
+++ b/input/regression/page-turn-page-breaking-auto-first-page.ly
@@ -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
index 0000000..163a9bf
--- /dev/null
+++ b/input/regression/paper-default-margins-a6.ly
@@ -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
index 0000000..8e22229
--- /dev/null
+++ b/input/regression/paper-default-margins-def.ly
@@ -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
+    }
+  }
+}
diff --git a/input/regression/paper-margins-consistency.ly b/input/regression/paper-margins-consistency.ly
index 1b58b15..a3a7a40 100644
--- a/input/regression/paper-margins-consistency.ly
+++ b/input/regression/paper-margins-consistency.ly
@@ -16,4 +16,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-left-margin.ly b/input/regression/paper-margins-left-margin.ly
index 5876196..23268e2 100644
--- a/input/regression/paper-margins-left-margin.ly
+++ b/input/regression/paper-margins-left-margin.ly
@@ -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 }
+}
diff --git a/input/regression/paper-margins-line-width.ly b/input/regression/paper-margins-line-width.ly
index bf6e14d..e38f57f 100644
--- a/input/regression/paper-margins-line-width.ly
+++ b/input/regression/paper-margins-line-width.ly
@@ -10,4 +10,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 100 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-no-checks.ly b/input/regression/paper-margins-no-checks.ly
index 119235e..5f3e783 100644
--- a/input/regression/paper-margins-no-checks.ly
+++ b/input/regression/paper-margins-no-checks.ly
@@ -13,6 +13,8 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   check-consistency = ##f
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
 
 
diff --git a/input/regression/paper-margins-overrun.ly b/input/regression/paper-margins-overrun.ly
index ebe4269..1492de9 100644
--- a/input/regression/paper-margins-overrun.ly
+++ b/input/regression/paper-margins-overrun.ly
@@ -15,4 +15,6 @@ someNotes = \relative c' { \repeat unfold 40 { c4 d e f } }
   line-width = 200 \mm
 }
 
-\score { \someNotes }
+\book {
+  \score { \someNotes }
+}
diff --git a/input/regression/paper-margins-right-margin.ly b/input/regression/paper-margins-right-margin.ly
index 40091b4..eaa4b1a 100644
--- a/input/regression/paper-margins-right-margin.ly
+++ b/input/regression/paper-margins-right-margin.ly
@@ -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 }
+}
diff --git a/input/regression/paper-margins.ly b/input/regression/paper-margins.ly
index 99d5841..2953891 100644
--- a/input/regression/paper-margins.ly
+++ b/input/regression/paper-margins.ly
@@ -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 }
+}
 
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 df7a63b..8be089f 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
+  % 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
diff --git a/scm/lily-library.scm b/scm/lily-library.scm
index 827fb24..4a7973a 100644
--- a/scm/lily-library.scm
+++ b/scm/lily-library.scm
@@ -333,14 +333,12 @@
    (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.
 ;;
diff --git a/scm/paper.scm b/scm/paper.scm
index 1eb3b59..0b5a60e 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,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)
--
1.6.0.2


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Re: Paper default margins

by Neil Puttock :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/10/28 Michael Käppler <xmichael-k@...>:

> Okay. I hadn't thought about this. Fixed now.

I only noticed it myself yesterday for reasons which should become
clear if you check out the attached PNG. ;)

Thanks for all the work you've done on this patch.  I've just pushed
it to master, so we can move on to the documentation.

Regards,
Neil


_______________________________________________
lilypond-devel mailing list
lilypond-devel@...
http://lists.gnu.org/mailman/listinfo/lilypond-devel

lily-0e5001ae.png (49K) Download Attachment