]> git.donarmstrong.com Git - lilypond.git/blob - scm/stencil.scm
* scm/define-markup-commands.scm (smallcaps): New markup command.
[lilypond.git] / scm / stencil.scm
1 ;;;; stenicil.scm -- 
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c)  2003--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6
7 (define-public (stack-stencils axis dir padding stils)
8   "Stack stencils STILS in direction AXIS,DIR, using PADDING."
9   (if (null? stils)
10       '()
11       (if (pair? stils)
12           (ly:stencil-combine-at-edge
13            (car stils) axis dir (stack-stencils axis dir padding (cdr stils))
14            padding))))
15
16 (define-public (stack-lines dir padding baseline stils)
17   "Stack vertically with a baseline-skip."
18   (if (null? stils)
19       '()
20       (if (null? (cdr stils))
21           (car stils)
22           (ly:stencil-combine-at-edge
23            (car stils) Y dir 
24            (stack-lines dir padding baseline (cdr stils))
25            padding baseline))))
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 (define-public (bracketify-stencil stil axis thick protusion padding)
34   "Add brackets around STIL, producing a new stencil."
35
36   (let* ((ext (ly:stencil-get-extent stil axis))
37          (lb (ly:bracket axis ext thick (- protusion)))
38          (rb (ly:bracket axis ext thick protusion)))
39     (set! stil
40           (ly:stencil-combine-at-edge stil (other-axis axis) 1 lb padding))
41     (set! stil
42           (ly:stencil-combine-at-edge stil (other-axis axis) -1 rb padding))
43     stil))
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 (define-public (box-grob-stencil grob)
55   "Make a box of exactly the extents of the grob.  The box precisely
56 encloses the contents.
57 "
58   (let* ((xext (ly:grob-extent grob grob 0))
59          (yext (ly:grob-extent grob grob 1))
60          (thick 0.1))
61
62     (ly:stencil-add
63      (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 ;; TODO merge this and prev function. 
69 (define-public (box-stencil stil thick padding)
70   "Add a box around STIL, producing a new stencil."
71   (let* ((x-ext (interval-widen (ly:stencil-get-extent stil 0) padding))
72          (y-ext (interval-widen (ly:stencil-get-extent stil 1) padding))
73          (y-rule (make-filled-box-stencil (cons 0 thick) y-ext))
74          (x-rule (make-filled-box-stencil (interval-widen x-ext thick)
75                                            (cons 0 thick))))
76     
77     (set! stil (ly:stencil-combine-at-edge stil X 1 y-rule padding))
78     (set! stil (ly:stencil-combine-at-edge stil X -1 y-rule padding))
79     (set! stil (ly:stencil-combine-at-edge stil Y 1 x-rule 0.0))  
80     (set! stil (ly:stencil-combine-at-edge stil Y -1 x-rule 0.0))
81     
82     stil))