]> git.donarmstrong.com Git - lilypond.git/commitdiff
New twoside mode.
authorMichael Käppler <xmichael-k@web.de>
Thu, 29 Oct 2009 10:38:45 +0000 (11:38 +0100)
committerNeil Puttock <n.puttock@gmail.com>
Thu, 5 Nov 2009 23:02:21 +0000 (23:02 +0000)
* This patch allows to specify different margins for odd and even
    pages by setting two-sided to true in the \paper block
  * The corresponding settings are inner- and outer-margin, there
    exists the possibility to set a binding-offset, too
  * These values are stored internally as left- and right-margin,
    though. Translation is done in page.scm:make-page-stencil
  * Small code cleanup in paper.scm:set-paper-dimensions

input/regression/paper-twosided-bcorr.ly [new file with mode: 0644]
input/regression/paper-twosided.ly [new file with mode: 0644]
lily/output-def.cc
ly/paper-defaults-init.ly
scm/page.scm
scm/paper.scm

diff --git a/input/regression/paper-twosided-bcorr.ly b/input/regression/paper-twosided-bcorr.ly
new file mode 100644 (file)
index 0000000..98d0cf4
--- /dev/null
@@ -0,0 +1,20 @@
+\version "2.13.8"
+
+\header {
+  texidoc = "In two-sided mode, a binding offset can be specified, which is added
+to the inner margin automatically."
+}
+
+someNotes = \relative c' { \repeat unfold 200 { c4 d e f } }
+
+\paper {
+  two-sided = ##t
+  inner-margin = 10 \mm
+  outer-margin = 20 \mm
+  binding-offset = 5 \mm
+}
+
+\book {
+  \score { \someNotes }
+}
+
diff --git a/input/regression/paper-twosided.ly b/input/regression/paper-twosided.ly
new file mode 100644 (file)
index 0000000..7376420
--- /dev/null
@@ -0,0 +1,19 @@
+\version "2.13.8"
+
+\header {
+  texidoc = "Two-sided mode allows you to use different margins for
+odd and even pages."
+}
+
+someNotes = \relative c' { \repeat unfold 200 { c4 d e f } }
+
+\paper {
+  two-sided = ##t
+  inner-margin = 10 \mm
+  outer-margin = 20 \mm
+}
+
+\book {
+  \score { \someNotes }
+}
+
index 3461e3c920cd727d121f6c4f7f0214dc96f442e6..0e29b23fb1933b2fa41bf24fdf79a69cc0c03f26 100644 (file)
@@ -135,13 +135,24 @@ Output_def::normalize ()
   Real paper_width;
   SCM scm_paper_width = c_variable ("paper-width");
 
+  bool twosided = to_boolean (c_variable ("two-sided"));
+  // We don't distinguish between outer-margin / left-margin and so on
+  // until page-stencil positioning in page.scm
   Real left_margin, left_margin_default;
-  SCM scm_left_margin_default = c_variable ("left-margin-default-scaled");
-  SCM scm_left_margin = c_variable ("left-margin");
+  SCM scm_left_margin_default = (twosided
+                                 ? c_variable ("outer-margin-default-scaled")
+                                 : c_variable ("left-margin-default-scaled"));
+  SCM scm_left_margin = (twosided
+                         ? c_variable ("outer-margin")
+                         : c_variable ("left-margin"));
 
   Real right_margin, right_margin_default;
-  SCM scm_right_margin_default = c_variable ("right-margin-default-scaled");
-  SCM scm_right_margin = c_variable ("right-margin");
+  SCM scm_right_margin_default = (twosided
+                                  ? c_variable ("inner-margin-default-scaled")
+                                  : c_variable ("right-margin-default-scaled"));
+  SCM scm_right_margin = (twosided
+                          ? c_variable ("inner-margin")
+                          : c_variable ("right-margin"));
 
   if (scm_paper_width == SCM_UNDEFINED
       || scm_left_margin_default == SCM_UNDEFINED
@@ -162,14 +173,18 @@ Output_def::normalize ()
     = paper_width - left_margin_default - right_margin_default;
   SCM scm_line_width = c_variable ("line-width");
 
+  Real binding_offset = 0;
+  if (twosided)
+    binding_offset = robust_scm2double (c_variable ("binding-offset"), 0);
+
   if (scm_line_width == SCM_UNDEFINED)
     {
       left_margin = ((scm_left_margin == SCM_UNDEFINED)
-                    ? left_margin_default
-                    : scm_to_double (scm_left_margin));
+                     ? 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));
+                      ? right_margin_default
+                      : scm_to_double (scm_right_margin)) + binding_offset;
       line_width = paper_width - left_margin - right_margin;
     }
   else
@@ -177,15 +192,15 @@ Output_def::normalize ()
       line_width = scm_to_double (scm_line_width);
       if (scm_left_margin == SCM_UNDEFINED)
         {
-         // Vertically center systems if only line-width is given
-         if (scm_right_margin == SCM_UNDEFINED)
+          // Vertically center systems if only line-width is given
+          if (scm_right_margin == SCM_UNDEFINED)
             {
               left_margin = (paper_width - line_width) / 2;
               right_margin = left_margin;
             }
           else
             {
-              right_margin = scm_to_double (scm_right_margin);
+              right_margin = scm_to_double (scm_right_margin) + binding_offset;
               left_margin = paper_width - line_width - right_margin;
             }
         }
@@ -194,7 +209,7 @@ Output_def::normalize ()
           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));
+                           : scm_to_double (scm_right_margin)) + binding_offset;
         }
     }
 
index 8be089f618fb70ae3fd5321f6f7dd4ba0a365204..8089b3be71a36d75843be0ff3b784158d57868f5 100644 (file)
@@ -87,6 +87,7 @@
   \include "titling-init.ly"
 
   check-consistency = ##t
+  two-sided = ##f
 
   % These margins apply to the default paper format given by (ly:get-option 'paper-size)
   % and are scaled accordingly for other formats
   left-margin-default = 10 \mm
   right-margin-default = 10 \mm
 
+  inner-margin-default = 10 \mm
+  outer-margin-default = 20 \mm
+  binding-offset-default = 0 \mm
+
   head-separation-default = 4 \mm
   foot-separation-default = 4 \mm
 
index 959402c4069ea1de3f7b38f83fecb671c8e38b31..3c81b7bd2e4fe419acf0335b60d048ea3adc7152 100644 (file)
@@ -15,7 +15,7 @@
            page-printable-height
            layout->page-init
            page-lines
-           page-force 
+           page-force
            page-penalty
            page-configuration
            page-lines
@@ -23,7 +23,7 @@
            page-system-numbers
            page-stencil
            page-free-height
-           page? 
+           page?
            ))
 
 (use-modules (lily)
@@ -46,9 +46,9 @@
 
     (page-set-property! p 'head-stencil (page-header p))
     (page-set-property! p 'foot-stencil (page-footer p))
-    
+
     p))
-       
+
 (define page-property ly:prob-property)
 (define page-set-property! ly:prob-set-property!)
 (define (page-property? page sym)
@@ -56,7 +56,7 @@
 (define (page? x)  (ly:prob-type? x 'page))
 
 
-;; define accessors. 
+;; define accessors.
 (for-each
  (lambda (j)
    (module-define!
@@ -64,7 +64,7 @@
     (string->symbol (format "page-~a" j))
     (lambda (pg)
       (page-property pg j))))
+
  '(page-number prev lines force penalty lines))
 
 (define (page-system-numbers page)
@@ -81,7 +81,7 @@
 
        (if (not (number? (ly:prob-property sys 'Y-offset)))
           (ly:prob-set-property! sys 'Y-offset off))))
-   
+
    (zip (page-property page 'lines)
        (page-property page 'configuration))))
 
                             (ly:stencil-add stencil
                                             (ly:stencil-translate-axis y 6 X))))))
     (add-stencil
-     (ly:stencil-translate-axis 
+     (ly:stencil-translate-axis
       (annotate-y-interval layout "paper-height"
                           (cons (- paper-height) 0)
                           #t)
       1 X))
     (add-stencil
-     (ly:stencil-translate-axis 
+     (ly:stencil-translate-axis
       (annotate-y-interval layout "top-margin"
                           (cons (- top-margin) 0)
                           #t)
       2 X))
     (add-stencil
-     (ly:stencil-translate-axis 
+     (ly:stencil-translate-axis
       (annotate-y-interval layout "bottom-margin"
                           (cons (- paper-height) (- bottom-margin paper-height))
                           #t)
 
 
 (define (page-header-or-footer page dir)
-    (let*
+  (let*
       ((paper-book (page-property page 'paper-book))
        (layout (ly:paper-book-paper paper-book))
        (scopes (ly:paper-book-scopes paper-book))
                'make-footer))
        (header-proc (ly:output-def-lookup layout sym)))
 
-      (if (procedure? header-proc)
-         (header-proc layout scopes number is-last-bookpart is-bookpart-last-page)
-         #f)))
+    (if (procedure? header-proc)
+       (header-proc layout scopes number is-last-bookpart is-bookpart-last-page)
+       #f)))
 
 
 (define (page-header page)
       ((paper-height (ly:output-def-lookup layout 'paper-height))
        (paper-width (ly:output-def-lookup layout 'paper-width))
        (left-margin (ly:output-def-lookup layout 'left-margin))
+       (right-margin (ly:output-def-lookup layout 'right-margin))
        (bottom-edge (- paper-height
                       (ly:output-def-lookup layout 'bottom-margin)) )
        (top-margin (ly:output-def-lookup layout 'top-margin))
        )
-    
+
     `((paper-height . ,paper-height)
       (paper-width . ,paper-width)
       (left-margin . ,left-margin)
+      (right-margin . ,right-margin)
       (top-margin . ,top-margin)
       (bottom-edge . ,bottom-edge)
       )))
 
 (define (make-page-stencil page)
   "Construct a stencil representing the page from PAGE."
-  
+
 
   (page-translate-systems page)
   (let*
        (number (page-page-number page))
 
        ;; TODO: naming paper-height/paper-width not analogous to TeX.
-       
+
        (system-xoffset (ly:output-def-lookup layout 'horizontal-shift 0.0))
        (system-separator-markup (ly:output-def-lookup layout 'system-separator-markup))
        (system-separator-stencil (if (markup? system-separator-markup)
                                                       (layout-extract-page-properties layout)
                                                       system-separator-markup)
                                     #f))
-       
+
        (page-stencil (ly:make-stencil '()))
 
        (last-system #f)
                                                                  (cons
                                                                   (+ system-xoffset x)
                                                                   (- 0 y (prop 'top-margin)))
-                                                                 
+
                                                                  )))))
        (add-system
        (lambda (system)
        (set! page-stencil
              (ly:stencil-add page-stencil
                              (annotate-space-left page))))
-    
+
     (if (and (ly:stencil? foot)
             (not (ly:stencil-empty? foot)))
        (set! page-stencil
                      (+ (- (prop 'bottom-edge))
                         (- (car (ly:stencil-extent foot Y)))))))))
 
-    (set! page-stencil
-         (ly:stencil-translate page-stencil (cons (prop 'left-margin) 0)))
+    (if (ly:output-def-lookup layout 'two-sided #f)
+       (set! page-stencil
+             (ly:stencil-translate page-stencil
+                                   (cons (prop (if (even? number)
+                                                   'left-margin
+                                                   'right-margin))
+                                         0)))
+       (set! page-stencil
+             (ly:stencil-translate page-stencil (cons (prop 'left-margin) 0))))
 
     ;; annotation.
     (if (annotate? layout)
        (set! page-stencil (annotate-page layout page-stencil)))
 
     page-stencil))
-              
+
 
 (define-public (page-stencil page)
   (if (not (ly:stencil? (page-property page 'stencil)))
 
       ;; todo: make tweakable.
       ;; via property + callbacks.
-      
+
       (page-set-property! page 'stencil (make-page-stencil page)))
   (page-property page 'stencil))
 
       ((paper-book (page-property page 'paper-book))
        (layout (ly:paper-book-paper paper-book))
        (h (- (ly:output-def-lookup layout 'paper-height)
-              (ly:output-def-lookup layout 'top-margin)
-              (ly:output-def-lookup layout 'bottom-margin)))
-       
+            (ly:output-def-lookup layout 'top-margin)
+            (ly:output-def-lookup layout 'bottom-margin)))
+
        (head (page-property page 'head-stencil))
        (foot (page-property page 'foot-stencil))
        (available
           (if (ly:stencil? foot)
               (interval-length (ly:stencil-extent foot Y))
               0))))
-    
+
     ;; (display (list "\n available" available head foot))
     available))
 
 (define (page-printable-height page)
   (if (not (number? (page-property page 'printable-height)))
       (page-set-property! page 'printable-height (calc-printable-height page)))
-  
+
   (page-property page 'printable-height))
 
index 0b5a60ec8d3371dd23275081dcddc0e164213681..bb529c6c8766ad455f2507cf32a7ff22c19bc373 100644 (file)
                    horizontal-shift
                    in
                    indent
+                   inner-margin
+                   inner-margin-default-scaled
                    ledger-line-thickness
                    left-margin
                     left-margin-default-scaled
                    line-thickness
                    line-width
                    mm
+                   outer-margin
+                   outer-margin-default-scaled
                    paper-height
                    paper-width
                    pt
 
   ;; !! synchronize with feta-params.mf
   (let*
-    ((x1 (* 4.125 pt))
-     (x0 (* 5 pt))
-     (f1 (* 0.47 pt))
-     (f0 (* 0.50 pt)))
+      ((x1 (* 4.125 pt))
+       (x0 (* 5 pt))
+       (f1 (* 0.47 pt))
+       (f0 (* 0.50 pt)))
 
     (/
      (+
       (* f1 (- staff-space x0))
-          (* f0 (- x1 staff-space)))
+      (* f0 (- x1 staff-space)))
      (- x1 x0))))
 
 (define-public (layout-set-absolute-staff-size-in-module module staff-height)
@@ -89,9 +93,9 @@ size. SZ is in points"
         (in-layout? (or (module-defined? current-mod 'is-paper)
                         (module-defined? current-mod 'is-layout)))
 
-        ; maybe not necessary.
-        ; but let's be paranoid. Maybe someone still refers to the
-        ; old one.
+        ;; maybe not necessary.
+        ;; but let's be paranoid. Maybe someone still refers to the
+        ;; old one.
         (new-paper (ly:output-def-clone pap))
 
         (new-scope (ly:output-def-scope new-paper)))
@@ -207,68 +211,67 @@ size. SZ is in points"
     ("pa10" . (cons (* 26 mm) (* 35 mm)))
     ;; F4 used in southeast Asia and Australia
     ("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*
-    ;; page layout - what to do with (printer specific!) margin settings?
-    ((paper-default (eval-carefully
-                      (assoc-get
+      ;; page layout - what to do with (printer specific!) margin settings?
+      ((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
+                      m
+                      (cons w h)))
+       ;; Horizontal margins, marked with 'preserve, 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.
+       (scaleable-values `((("left-margin" . ,w) . preserve)
+                          (("right-margin" . ,w) . preserve)
+                          (("inner-margin" . ,w) . preserve)
+                          (("outer-margin" . ,w) . preserve)
+                          (("binding-offset" . ,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)))
+                 (string->symbol
+                  (string-append (caar entry) "-default")))
+                (orientation (cdar entry)))
+            (if paper-default
+                (cons (if (eq? (cdr entry) 'preserve)
+                          (string-append (caar entry) "-default-scaled")
+                          (caar 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
+    (module-define! m 'paper-width w)
+    (module-define! m 'paper-height h)
+    ;; Sometimes, lilypond-book doesn't estimate a correct line-width.
+    ;; Therefore, we need to unset line-width.
+    (module-remove! m 'line-width)
+
+    (for-each
      (lambda (value)
-        (let ((value-symbol (string->symbol (car value)))
-              (number (cdr value)))
-          (module-define! m value-symbol number)))
+       (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?)