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