3 ;;;; source file of the GNU LilyPond music typesetter
5 ;;;; (c) 2003--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 (define-public (stack-stencils axis dir padding stils)
8 "Stack stencils STILS in direction AXIS, DIR, using PADDING."
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))
16 (define-public (stack-stencils-padding-list axis dir padding stils)
17 "Stack stencils STILS in direction AXIS, DIR, using a list of PADDING."
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))
25 (define-public (centered-stencil stencil)
26 "Center stencil @var{stencil} in both the X and Y directions"
27 (ly:stencil-aligned-to (ly:stencil-aligned-to stencil X CENTER) Y CENTER))
29 (define-public (stack-lines dir padding baseline stils)
30 "Stack vertically with a baseline-skip."
33 (if (null? (cdr stils))
35 (ly:stencil-combine-at-edge
37 (stack-lines dir padding baseline (cdr stils))
40 (define-public (bracketify-stencil stil axis thick protusion padding)
41 "Add brackets around STIL, producing a new stencil."
43 (let* ((ext (ly:stencil-extent stil axis))
44 (lb (ly:bracket axis ext thick (- protusion)))
45 (rb (ly:bracket axis ext thick protusion)))
47 (ly:stencil-combine-at-edge stil (other-axis axis) 1 lb padding))
49 (ly:stencil-combine-at-edge stil (other-axis axis) -1 rb padding))
52 (define-public (make-filled-box-stencil xext yext)
56 (list 'round-filled-box (- (car xext)) (cdr xext)
57 (- (car yext)) (cdr yext) 0.0)
60 (define-public (make-circle-stencil radius thickness fill)
61 "Make a circle of radius @var{radius} and thickness @var{thickness}"
63 (list 'circle radius thickness fill)
64 (cons (- radius) radius)
65 (cons (- radius) radius)))
67 (define-public (box-grob-stencil grob)
68 "Make a box of exactly the extents of the grob. The box precisely
69 encloses the contents.
71 (let* ((xext (ly:grob-extent grob grob 0))
72 (yext (ly:grob-extent grob grob 1))
76 (make-filled-box-stencil xext (cons (- (car yext) thick) (car yext)))
77 (make-filled-box-stencil xext (cons (cdr yext) (+ (cdr yext) thick)))
78 (make-filled-box-stencil (cons (cdr xext) (+ (cdr xext) thick)) yext)
79 (make-filled-box-stencil (cons (- (car xext) thick) (car xext)) yext))))
81 ;; TODO merge this and prev function.
82 (define-public (box-stencil stencil thickness padding)
83 "Add a box around STENCIL, producing a new stencil."
84 (let* ((x-ext (interval-widen (ly:stencil-extent stencil 0) padding))
85 (y-ext (interval-widen (ly:stencil-extent stencil 1) padding))
86 (y-rule (make-filled-box-stencil (cons 0 thickness) y-ext))
87 (x-rule (make-filled-box-stencil
88 (interval-widen x-ext thickness) (cons 0 thickness))))
89 (set! stencil (ly:stencil-combine-at-edge stencil X 1 y-rule padding))
90 (set! stencil (ly:stencil-combine-at-edge stencil X -1 y-rule padding))
91 (set! stencil (ly:stencil-combine-at-edge stencil Y 1 x-rule 0.0))
92 (set! stencil (ly:stencil-combine-at-edge stencil Y -1 x-rule 0.0))
95 (define-public (circle-stencil stencil thickness padding)
96 "Add a circle around STENCIL, producing a new stencil."
97 (let* ((x-ext (ly:stencil-extent stencil 0))
98 (y-ext (ly:stencil-extent stencil 1))
99 (diameter (max (- (cdr x-ext) (car x-ext))
100 (- (cdr y-ext) (car y-ext))))
101 (radius (+ (/ diameter 2) padding thickness)))
103 (centered-stencil stencil) (make-circle-stencil radius thickness #f))))
105 (define-public (fontify-text font-metric text)
106 "Set TEXT with font FONT-METRIC, returning a stencil."
107 (let* ((b (ly:text-dimension font-metric text)))
109 `(text ,font-metric ,text) (car b) (cdr b))))
111 (define-public (fontify-text-white scale font-metric text)
112 "Set TEXT with scale factor s"
113 (let* ((b (ly:text-dimension font-metric text))
114 ;;urg -- workaround for using ps font
115 (c `(white-text ,(* 2 scale) ,text)))
116 ;;urg -- extent is not from ps font, but we hope it's close
117 (ly:make-stencil c (car b) (cdr b))))
119 (define-public (dimension-arrows destination)
120 "Draw twosided arrow from here to @var{destination}"
125 (rotate (lambda (z ang)
126 (* (make-polar 1 ang)
128 (complex-to-offset (lambda (z)
129 (list (real-part z) (imag-part z))))
131 (z-dest (+ (* e_x (car destination)) (* e_y (cdr destination))))
132 (e_z (/ z-dest (magnitude z-dest)))
133 (triangle-points '(-1+0.25i
136 (p1s (map (lambda (z)
137 (+ z-dest (rotate z (angle z-dest))))
139 (p2s (map (lambda (z)
140 (rotate z (angle (- z-dest))))
145 `(polygon (quote ,(concatenate (map complex-to-offset p1s)))
150 `(polygon (quote ,(concatenate (map complex-to-offset p2s)))
155 (start (complex-to-offset (/ (* e_z shorten-line) 2)))
156 (end (complex-to-offset (- z-dest (/ (* e_z shorten-line) 2))))
158 (line (ly:make-stencil
159 `(draw-line ,thickness
160 ,(car start) ,(cadr start)
161 ,(car end) ,(cadr end)
163 (cons (min 0 (car destination))
164 (min 0 (cdr destination)))
165 (cons (max 0 (car destination))
166 (max 0 (cdr destination)))))
168 (result (ly:stencil-add arrow-2 arrow-1 line)))