X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fpaper.scm;h=3208f4b82a90654b9fc5e1a55d0df0366303aa0a;hb=e90f0536f9be39ada0bef0aeb0d275dec3b2fb5b;hp=d3e299ddd80c4bd4d0646b16101067f9e014620d;hpb=a8c9e8a7ca320ab0df5fd32e717fd62cd7635ce6;p=lilypond.git diff --git a/scm/paper.scm b/scm/paper.scm index d3e299ddd8..3208f4b82a 100644 --- a/scm/paper.scm +++ b/scm/paper.scm @@ -1,34 +1,45 @@ -;;;; paper.scm -- manipulate the paper and layout block. +;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; source file of the GNU LilyPond music typesetter -;;;; -;;;; (c) 2004--2009 Han-Wen Nienhuys +;;;; Copyright (C) 2004--2011 Han-Wen Nienhuys +;;;; +;;;; LilyPond is free software: you can redistribute it and/or modify +;;;; it under the terms of the GNU General Public License as published by +;;;; the Free Software Foundation, either version 3 of the License, or +;;;; (at your option) any later version. +;;;; +;;;; LilyPond is distributed in the hope that it will be useful, +;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;;; GNU General Public License for more details. +;;;; +;;;; You should have received a copy of the GNU General Public License +;;;; along with LilyPond. If not, see . (define-public (set-paper-dimension-variables mod) (module-define! mod 'dimension-variables - '(after-title-space - before-title-space - between-system-padding - between-system-space - between-title-space - blot-diameter + '(blot-diameter bottom-margin cm - foot-separation - head-separation + footnote-footer-padding + footnote-padding horizontal-shift in indent + inner-margin + inner-margin-default-scaled ledger-line-thickness left-margin + left-margin-default-scaled line-thickness line-width mm - page-top-space + outer-margin + outer-margin-default-scaled paper-height paper-width pt right-margin + right-margin-default-scaled short-indent staff-height staff-space @@ -39,15 +50,15 @@ ;; !! 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) @@ -58,8 +69,10 @@ (setm! (lambda (sym val) (module-define! module sym val)))) - (setm! 'text-font-size (* 12 factor)) - + ;; Synchronized with the `text-font-size' + ;; binding in add-pango-fonts (see font.scm). + (setm! 'text-font-size (* 11 factor)) + (setm! 'output-scale ss) (setm! 'fonts (make-century-schoolbook-tree factor)) (setm! 'staff-height staff-height) @@ -67,21 +80,21 @@ (setm! 'line-thickness (calc-line-thickness ss pt)) - ;; sync with feta + ;; sync with feta (setm! 'ledger-line-thickness (+ (* 0.5 pt) (/ ss 10))) - ;; sync with feta + ;; sync with feta (setm! 'blot-diameter (* 0.4 pt)) )) (define-public (layout-set-absolute-staff-size sz) - "Function to be called inside a \\layout{} block to set the staff -size. SZ is in points" + "Set the absolute staff size inside of a @code{\\layout@{@}} block. +@var{sz} is in points." (layout-set-absolute-staff-size-in-module (current-module) sz)) (define-public (layout-set-staff-size sz) - "Function to be called inside a \\layout{} block to set the staff -size. SZ is in points" + "Set the staff size inside of a @code{\\layout@{@}} block. +@var{sz} is in points." (layout-set-absolute-staff-size (* (eval 'pt (current-module)) sz))) @@ -93,13 +106,13 @@ 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))) - + (if in-layout? (ly:warning (_ "set-global-staff-size: not in toplevel scope"))) @@ -211,46 +224,90 @@ size. SZ is in points" ("pa10" . (cons (* 26 mm) (* 35 mm))) ;; F4 used in southeast Asia and Australia ("f4" . (cons (* 210 mm) (* 330 mm))) - )) + ;; Used for very small @lilypond examples in the Documentation + ;; based on a8 size but landscape not portrait + ("a8landscape" . (cons (* 74 mm) (* 52 mm))) + )) ;; todo: take dimension arguments. (define (set-paper-dimensions m w h) "M is a module (i.e. layout->scope_ )" - (let* ((mm (eval 'mm m))) + (let* + ;; 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))) + ;; 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) . '()) + (("indent" . ,w) . '()) + (("short-indent" . ,w) . '()))) + (scaled-values + (map + (lambda (entry) + (let ((entry-symbol + (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) - (module-define! m 'line-width (- w - (ly:modules-lookup (list m) 'left-margin (* 10 mm)) - (ly:modules-lookup (list m) 'right-margin (* 10 mm)))) - - (module-define! m 'indent (/ w 14)) - (module-define! m 'short-indent 0) + ;; Sometimes, lilypond-book doesn't estimate a correct line-width. + ;; Therefore, we need to unset line-width. + (module-remove! m 'line-width) - ;; page layout - what to do with (printer specific!) margin settings? - - )) + (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) (cons (cdr x) (car x))) - - (let* ((entry (assoc name paper-alist)) + + (let* ((entry (assoc-get name paper-alist)) (is-paper? (module-defined? module 'is-paper)) (mm (eval 'mm module))) - + (cond ((not is-paper?) (ly:warning (_ "This is not a \\layout {} object, ~S") module)) - ((pair? entry) + (entry - (set! entry (eval (cdr entry) module)) + (set! entry (eval entry module)) (if landscape? (set! entry (swap entry))) (set-paper-dimensions module (car entry) (cdr entry)) (module-define! module 'papersizename name) - (module-define! module 'landscape + (module-define! module 'landscape (if landscape? #t #f))) (else (ly:warning (_ "Unknown paper size: ~a") name))))) @@ -270,11 +327,12 @@ size. SZ is in points" ;;; that in parse-scm.cc (ly:warning (_ "Must use #(set-paper-size .. ) within \\paper { ... }")))) -(define-public (scale-layout pap scale) - (let* ((new-pap (ly:output-def-clone pap)) - (dim-vars (ly:output-def-lookup pap 'dimension-variables)) - (old-scope (ly:output-def-scope pap)) - (scope (ly:output-def-scope new-pap))) +(define-public (scale-layout paper scale) + "Return a clone of the paper, scaled by the given scale factor." + (let* ((new-paper (ly:output-def-clone paper)) + (dim-vars (ly:output-def-lookup paper 'dimension-variables)) + (old-scope (ly:output-def-scope paper)) + (scope (ly:output-def-scope new-paper))) (for-each (lambda (v) @@ -282,13 +340,10 @@ size. SZ is in points" (val (if (variable? var) (variable-ref var) #f))) (if (number? val) - (module-define! scope v - (/ val scale)) - - ;; spurious warnings, eg. for paper-width, paper-height. - ;; (ly:warning (_ "not a number, ~S = ~S " v val)) + (module-define! scope v (/ val scale)) + ;; Cannot warn for non-numbers, eg. for paper-width, paper-height. ))) - dim-vars) - - new-pap)) + ;; Mark the clone. + (ly:output-def-set-variable! new-paper 'cloned #t) + new-paper))