]> git.donarmstrong.com Git - lilypond.git/blob - scm/stencil.scm
* scm/output-gnome.scm (FIXME-glyph-string): New function. Cannot
[lilypond.git] / scm / stencil.scm
1 ;;;; stencil.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   (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-lines dir padding baseline stils)
17   "Stack vertically with a baseline-skip."
18   (if (null? stils)
19       empty-stencil
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 (bracketify-stencil stil axis thick protusion padding)
28   "Add brackets around STIL, producing a new stencil."
29
30   (let* ((ext (ly:stencil-extent stil axis))
31          (lb (ly:bracket axis ext thick (- protusion)))
32          (rb (ly:bracket axis ext thick protusion)))
33     (set! stil
34           (ly:stencil-combine-at-edge stil (other-axis axis) 1 lb padding))
35     (set! stil
36           (ly:stencil-combine-at-edge stil (other-axis axis) -1 rb padding))
37     stil))
38
39 (define-public (make-filled-box-stencil xext yext)
40   "Make a filled box."
41   
42   (ly:make-stencil
43       (list 'filledbox (- (car xext)) (cdr xext)
44                        (- (car yext)) (cdr yext))
45       xext yext))
46
47 (define-public (box-grob-stencil grob)
48   "Make a box of exactly the extents of the grob.  The box precisely
49 encloses the contents.
50 "
51   (let* ((xext (ly:grob-extent grob grob 0))
52          (yext (ly:grob-extent grob grob 1))
53          (thick 0.1))
54     
55     (ly:stencil-add
56      (make-filled-box-stencil xext (cons (- (car yext) thick) (car yext)))
57      (make-filled-box-stencil xext (cons  (cdr yext) (+ (cdr yext) thick)))
58      (make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext)
59      (make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext))))
60
61 ;; TODO merge this and prev function. 
62 (define-public (box-stencil stil thick padding)
63   "Add a box around STIL, producing a new stencil."
64   (let* ((x-ext (interval-widen (ly:stencil-extent stil 0) padding))
65          (y-ext (interval-widen (ly:stencil-extent stil 1) padding))
66          (y-rule (make-filled-box-stencil (cons 0 thick) y-ext))
67          (x-rule (make-filled-box-stencil (interval-widen x-ext thick)
68                                            (cons 0 thick))))
69     
70     (set! stil (ly:stencil-combine-at-edge stil X 1 y-rule padding))
71     (set! stil (ly:stencil-combine-at-edge stil X -1 y-rule padding))
72     (set! stil (ly:stencil-combine-at-edge stil Y 1 x-rule 0.0))  
73     (set! stil (ly:stencil-combine-at-edge stil Y -1 x-rule 0.0))
74     
75     stil))
76
77 (define-public (fontify-text font-metric text)
78   "Set TEXT with font FONT-METRIC, returning a stencil."
79   (let* ((b (ly:text-dimension font-metric text)))
80     (ly:make-stencil
81      `(text ,font-metric ,text) (car b) (cdr b))))
82      
83 (define-public (fontify-text-white scale font-metric text)
84   "Set TEXT with scale factor s"
85   (let* ((b (ly:text-dimension font-metric text))
86          ;;urg -- workaround for using ps font
87          (c `(white-text ,(* 2 scale) ,text)))
88     ;;urg -- extent is not from ps font, but we hope it's close
89     (ly:make-stencil c (car b) (cdr b))))