]> git.donarmstrong.com Git - lilypond.git/blob - scm/layout-beam.scm
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scm / layout-beam.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2000--2015 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;;
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
9 ;;;;
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ;;;; GNU General Public License for more details.
14 ;;;;
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
17
18 (define check-beam-quant
19   (lambda (posl posr)
20     (lambda (beam posns)
21       "Check whether BEAM has POSL and POSR quants.  POSL are (POSITION
22 . QUANT) pairs, where QUANT is -1 (hang), 0 (center), 1 (sit) or -2/ 2 (inter)
23
24 "
25       (let* ((thick (ly:grob-property beam 'beam-thickness))
26              (layout (ly:grob-layout beam))
27              (lthick (ly:output-def-lookup layout 'line-thickness))
28              (staff-thick lthick) ; fixme.
29              (quant->coord (lambda (p q)
30                              (if (= 2 (abs q))
31                                  (+ p (/ q 4.0))
32                                  (+ p (- (* 0.5 q thick) (* 0.5 q lthick))))))
33              (want-l (quant->coord (car posl) (cdr posl)))
34              (want-r (quant->coord (car posr) (cdr posr)))
35              (almost-equal (lambda (x y) (< (abs (- x y)) 1e-3))))
36
37         (if (or (not (almost-equal want-l (car posns)))
38                 (not (almost-equal want-r (cdr posns))))
39             (begin
40               (ly:warning (_ "Error in beam quanting.  Expected (~S,~S) found ~S.")
41                           want-l want-r posns)
42               (set! (ly:grob-property beam 'annotation)
43                     (format #f "(~S,~S)" want-l want-r))))
44         posns))))
45
46 (define check-beam-slope-sign
47   (lambda (comparison)
48     (lambda (beam posns)
49       "Check whether the slope of BEAM is correct wrt. COMPARISON."
50       (let* ((slope-sign (- (cdr posns) (car posns)))
51              (correct (comparison slope-sign 0)))
52         (if (not correct)
53             (begin
54               (ly:warning (_ "Error in beam quanting.  Expected ~S 0, found ~S.")
55                           (procedure-name comparison) slope-sign)
56               (set! (ly:grob-property beam 'annotation)
57                     (format #f "~S 0" (procedure-name comparison))))
58             (set! (ly:grob-property beam 'annotation) ""))
59         posns))))
60
61
62 (define-public (check-quant-callbacks l r)
63   (lambda (grob)
64     ((check-beam-quant l r)
65      grob
66      (beam::place-broken-parts-individually grob))))
67
68
69 (define-public (check-slope-callbacks comparison)
70   (lambda (grob)
71     ((check-beam-slope-sign comparison)
72      grob
73      (beam::place-broken-parts-individually grob))))