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