]> git.donarmstrong.com Git - lilypond.git/blob - scm/stencil.scm
*** empty log message ***
[lilypond.git] / scm / stencil.scm
1 ;;;; stencil.scm -- 
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;; 
5 ;;;; (c) 2003--2005 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   (cond
10    ((null? stils) empty-stencil)
11    ((null? (cdr stils)) (car stils))
12    (else (ly:stencil-combine-at-edge
13           (car stils) axis dir (stack-stencils axis dir padding (cdr stils))
14           padding))))
15
16 (define-public (stack-stencils-padding-list axis dir padding stils)
17   "Stack stencils STILS in direction AXIS, DIR, using a list of PADDING."
18   (cond
19    ((null? stils) empty-stencil)
20    ((null? (cdr stils)) (car stils))
21    (else (ly:stencil-combine-at-edge
22           (car stils) axis dir (stack-stencils-padding-list axis dir (cdr padding) (cdr stils))
23           (car padding)))))
24
25 (define-public (centered-stencil stencil)
26   "Center stencil @var{stencil} in both the X and Y directions"
27
28   (ly:stencil-aligned-to
29    (ly:stencil-aligned-to stencil X CENTER)
30    Y CENTER))
31
32 (define-public (stack-lines dir padding baseline stils)
33   "Stack vertically with a baseline-skip."
34   (if (null? stils)
35       empty-stencil
36       (if (null? (cdr stils))
37           (car stils)
38           (ly:stencil-combine-at-edge
39            (car stils) Y dir 
40            (stack-lines dir padding baseline (cdr stils))
41            padding baseline))))
42
43 (define-public (bracketify-stencil stil axis thick protusion padding)
44   "Add brackets around STIL, producing a new stencil."
45
46   (let* ((ext (ly:stencil-extent stil axis))
47          (lb (ly:bracket axis ext thick (- protusion)))
48          (rb (ly:bracket axis ext thick protusion)))
49     (set! stil
50           (ly:stencil-combine-at-edge stil (other-axis axis) 1 lb padding))
51     (set! stil
52           (ly:stencil-combine-at-edge stil (other-axis axis) -1 rb padding))
53     stil))
54
55 (define-public (make-filled-box-stencil xext yext)
56   "Make a filled box."
57   
58   (ly:make-stencil
59       (list 'filledbox (- (car xext)) (cdr xext)
60                        (- (car yext)) (cdr yext))
61       xext yext))
62
63 (define-public (box-grob-stencil grob)
64   "Make a box of exactly the extents of the grob.  The box precisely
65 encloses the contents.
66 "
67   (let* ((xext (ly:grob-extent grob grob 0))
68          (yext (ly:grob-extent grob grob 1))
69          (thick 0.1))
70     
71     (ly:stencil-add
72      (make-filled-box-stencil xext (cons (- (car yext) thick) (car yext)))
73      (make-filled-box-stencil xext (cons  (cdr yext) (+ (cdr yext) thick)))
74      (make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext)
75      (make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext))))
76
77 ;; TODO merge this and prev function. 
78 (define-public (box-stencil stil thick padding)
79   "Add a box around STIL, producing a new stencil."
80   (let* ((x-ext (interval-widen (ly:stencil-extent stil 0) padding))
81          (y-ext (interval-widen (ly:stencil-extent stil 1) padding))
82          (y-rule (make-filled-box-stencil (cons 0 thick) y-ext))
83          (x-rule (make-filled-box-stencil (interval-widen x-ext thick)
84                                            (cons 0 thick))))
85     
86     (set! stil (ly:stencil-combine-at-edge stil X 1 y-rule padding))
87     (set! stil (ly:stencil-combine-at-edge stil X -1 y-rule padding))
88     (set! stil (ly:stencil-combine-at-edge stil Y 1 x-rule 0.0))  
89     (set! stil (ly:stencil-combine-at-edge stil Y -1 x-rule 0.0))
90     
91     stil))
92
93 (define-public (fontify-text font-metric text)
94   "Set TEXT with font FONT-METRIC, returning a stencil."
95   (let* ((b (ly:text-dimension font-metric text)))
96     (ly:make-stencil
97      `(text ,font-metric ,text) (car b) (cdr b))))
98      
99 (define-public (fontify-text-white scale font-metric text)
100   "Set TEXT with scale factor s"
101   (let* ((b (ly:text-dimension font-metric text))
102          ;;urg -- workaround for using ps font
103          (c `(white-text ,(* 2 scale) ,text)))
104     ;;urg -- extent is not from ps font, but we hope it's close
105     (ly:make-stencil c (car b) (cdr b))))