]> git.donarmstrong.com Git - lilypond.git/blob - scm/molecule.scm
* make/lilypond.redhat.spec.in: require GUILE >= 1.6.4-7
[lilypond.git] / scm / molecule.scm
1
2 (define-public (stack-molecules axis dir padding mols)
3   "Stack molecules MOLS in direction AXIS,DIR, using PADDING."
4   (if (null? mols)
5       '()
6       (if (pair? mols)
7           (ly:molecule-combine-at-edge (car mols) axis dir 
8                                        (stack-molecules axis dir padding (cdr mols))
9                                        padding
10                                        )
11           )
12   ))
13
14
15 (define-public (stack-lines dir padding baseline mols)
16   "Stack vertically with a baseline-skip."
17   (if (null? mols)
18       '()
19       (if (null? (cdr mols))
20           (car mols)
21           (ly:molecule-combine-at-edge (car mols) Y dir 
22                                        (stack-lines dir padding baseline (cdr mols))
23                                        padding baseline
24                                        )
25           )
26   ))
27
28 (define-public (fontify-text font-metric text)
29   "Set TEXT with font FONT-METRIC, returning a molecule."
30   (let* ((b  (ly:text-dimension font-metric text)))
31     (ly:make-molecule
32      (ly:fontify-atom font-metric `(text ,text)) (car b) (cdr b))
33     ))
34
35 (define-public (bracketify-molecule mol axis thick protusion padding)
36   "Add brackets around MOL, producing a new molecule."
37
38   (let* (
39          (ext (ly:molecule-get-extent mol axis))
40          (lb (ly:bracket axis ext thick (- protusion)))
41          (rb (ly:bracket axis ext thick protusion))
42          )
43     (set! mol (ly:molecule-combine-at-edge mol (other-axis  axis) 1 lb padding))
44     (set! mol (ly:molecule-combine-at-edge mol (other-axis  axis) -1 rb padding))
45     mol
46   ))
47
48 (define-public (box-molecule xext yext)
49   "Make a filled box."
50   
51   (ly:make-molecule
52       (list 'filledbox (- (car xext)) (cdr xext)
53                        (- (car yext)) (cdr yext))
54       xext yext)                       
55 )
56
57
58 (define-public (box-grob-molecule grob)
59   "Make a box of exactly the extents of the grob.  The box precisely
60 encloses the contents.
61 "
62   (let* ((xext (ly:get-extent grob grob 0))
63          (yext (ly:get-extent grob grob 1))
64          (thick 0.1))
65
66     (ly:molecule-add (box-molecule xext (cons (- (car yext) thick) (car yext) ))
67                      (box-molecule xext (cons  (cdr yext) (+ (cdr yext) thick) ))
68                      (box-molecule (cons (cdr xext) (+ (cdr xext) thick)) yext)
69                      (box-molecule (cons (- (car xext) thick) (car xext)) yext))))
70
71
72 ;; TODO merge this and prev function. 
73 (define-public (box-molecule mol thick padding)
74   "Add a box around MOL, producing a new molecule."
75   (let* (
76          (x-ext (widen-interval (ly:molecule-get-extent mol 0) padding))
77          (y-ext (widen-interval (ly:molecule-get-extent mol 1) padding))
78          (x-rule (box-molecule (widen-interval x-ext thick)
79                                (cons 0 thick)))
80          (y-rule (box-molecule (cons 0 thick) y-ext)))
81     
82     (set! mol (ly:molecule-combine-at-edge mol 0 1 y-rule (* 0.5 padding)))
83     (set! mol (ly:molecule-combine-at-edge mol 0 -1  y-rule (* 0.5 padding)))
84     (set! mol (ly:molecule-combine-at-edge mol 1 1  x-rule 0.0))  
85     (set! mol (ly:molecule-combine-at-edge mol 1 -1 x-rule 0.0))
86     
87     mol))