]> git.donarmstrong.com Git - lilypond.git/blob - scm/molecule.scm
ly- -> ly:
[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:combine-molecule-at-edge (car mols) axis dir 
8                                        (stack-molecules axis dir padding (cdr mols))
9                                        padding
10                                        )
11           )
12   ))
13
14
15
16
17 (define-public (fontify-text font-metric text)
18   "Set TEXT with font FONT-METRIC, returning a molecule."
19   (let* ((b  (ly:text-dimension font-metric text)))
20     (ly:make-molecule
21      (ly:fontify-atom font-metric `(text ,text)) (car b) (cdr b))
22     ))
23
24 (define-public (bracketify-molecule mol axis thick protusion padding)
25   "Add brackets around MOL, producing a new molecule."
26
27   (let* (
28          (ext (ly:get-molecule-extent mol axis))
29          (lb (ly:bracket axis ext thick (- protusion)))
30          (rb (ly:bracket axis ext thick protusion))
31          )
32     (set! mol (ly:combine-molecule-at-edge mol (other-axis  axis) 1 lb padding))
33     (set! mol (ly:combine-molecule-at-edge mol (other-axis  axis) -1 rb padding))
34     mol
35   ))
36
37
38
39 (define-public (box-molecule xext yext)
40   "Make a filled box."
41   
42   (ly:make-molecule
43       (list 'filledbox (- (car xext)) (cdr xext)
44                        (- (car yext)) (cdr yext))
45       xext yext)                       
46 )
47
48 (define-public (box-grob-molecule grob)
49   "Make a box of exactly the extents of the grob.  The box precisely
50 encloses the contents.
51 "
52   (let* ((xext (ly:get-extent grob grob 0))
53          (yext (ly:get-extent grob grob 1))
54          (mol (ly:make-molecule '() '(10000 . -10000) '(10000 . -10000)))
55          (thick 0.1)
56          )
57
58     (set! mol (ly:add-molecule mol (box-molecule xext (cons (- (car yext) thick) (car yext) ))))
59     (set! mol (ly:add-molecule mol (box-molecule xext (cons  (cdr yext) (+ (cdr yext) thick) ))))
60     (set! mol (ly:add-molecule mol (box-molecule (cons (cdr xext) (+ (cdr xext) thick)) yext)))
61     (set! mol (ly:add-molecule mol (box-molecule (cons (- (car xext) thick) (car xext)) yext)))
62     mol
63   ))