]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
2ed8afd58351e8f2b2acb63d05c263fc69d1ebfd
[lilypond.git] / ps / music-drawing-routines.ps
1 %!PS-Adobe-1.0: lily.ps 
2 %
3 % Functions for direct and embedded PostScript
4
5 % round cappings 
6 1 setlinecap
7
8 /euclidean_length  
9
10         1 copy mul exch 1 copy mul add sqrt 
11 } bind def 
12
13 /draw_beam % width slope thick 
14
15         2 div /beam_thick exch def 
16         /beam_slope exch def 
17         /beam_wd exch def 
18         beam_slope beam_wd mul /beam_ht exch def 
19         0 beam_thick neg moveto  
20         beam_wd beam_ht rlineto  
21         0 beam_thick 2 mul rlineto 
22         0 beam_thick lineto 
23         closepath fill 
24 } bind def 
25
26 /draw_repeat_slash % width slope thick
27 {
28   /beamthick exch def
29   /slope exch def
30   /width exch def
31   beamthick beamthick slope div euclidean_length
32     /xwid exch def 
33   0 0 moveto
34   xwid 0  rlineto
35   width slope width mul rlineto
36   xwid neg 0 rlineto
37 %  width neg width angle sin mul neg rlineto
38   closepath fill
39 } bind def
40
41 /draw_hairpin % width start_h end_h thick
42 {
43   setlinewidth
44   /end_h exch def 
45   /start_h exch def
46   /wid exch def
47   0 start_h moveto
48   wid end_h lineto
49   stroke
50   0 start_h neg moveto
51   wid end_h neg lineto
52   stroke
53 } bind def
54
55 /draw_tuplet % height gap dx dy thick dir 
56
57         /dir exch def 
58         setlinewidth 
59         1 setlinecap 
60         1 setlinejoin 
61         /tuplet_dy exch def 
62         /tuplet_dx exch def 
63         /tuplet_gapx exch def 
64         /tuplet_h exch def 
65         tuplet_dy tuplet_dx div tuplet_gapx mul /tuplet_gapy exch def 
66
67
68         0 tuplet_h neg dir mul moveto 
69         0 0 lineto  
70         tuplet_dx tuplet_gapx sub 2 div  
71                 tuplet_dy tuplet_gapy sub 2 div  lineto 
72         tuplet_dx tuplet_gapx add 2 div  
73                 tuplet_dy tuplet_gapy add 2 div  moveto 
74         tuplet_dx tuplet_dy lineto 
75         tuplet_dx tuplet_dy tuplet_h dir neg mul add lineto 
76         stroke 
77 } bind def 
78
79 /draw_ez_ball % ch letter_col ball_col font
80 {
81         % font
82         findfont 0.7 scalefont setfont 
83         0.1 setlinewidth
84         0 0 moveto
85         0 setgray
86         0.5 0 0.5 0 360 arc closepath fill stroke
87         % ball_col
88         1 eq {
89                 0.01 setlinewidth
90                 1 setgray
91                 0.5 0 0.4 0 360 arc closepath
92                 fill stroke
93         } if 
94         % letter_col
95         setgray
96         % 0.25 is empiric centering. Change to taste
97         0.25 -0.25 moveto
98         % ch
99         show
100 } bind def
101
102 % Simple, but does it work everywhere?
103 % Han-Wen reports that one printer (brand?) at cs.uu.nl chokes on this,
104 % reverted for now -- jcn
105 %
106 % The filled circles are drawn by setting the linewidth
107 % to 2*radius and drawing a point.
108 /simple_draw_ez_ball % ch letter_col ball_col font
109 {
110         % font
111         findfont 0.85 scalefont setfont
112         /origin { 0.45 0 } def
113         0 setgray
114         1.1 setlinewidth
115         origin moveto
116         origin lineto stroke
117         % ball_col
118         setgray
119         0.9 setlinewidth
120         origin moveto
121         origin lineto stroke
122         % letter_col
123         setgray
124         % 0.25 is empiric centering. Change to taste
125         origin moveto
126         -0.28 -0.30 rmoveto
127         % ch
128         show
129 } bind def
130
131 /draw_volta % h w thick vert_start vert_end 
132
133         /vert_end exch def 
134         /vert_start exch def 
135         setlinewidth 
136         /volta_w exch def 
137         /volta_h exch def 
138         1 setlinecap 
139         1 setlinejoin 
140         vert_start 0 eq { 
141                 0 0 moveto 
142                 0 volta_h lineto 
143         } if 
144         0 volta_h moveto 
145         volta_w volta_h lineto 
146         vert_end 0 eq { 
147                 volta_w 0 lineto 
148         } if 
149         stroke 
150 } bind def 
151
152 % this is for drawing slurs. 
153 /draw_bezier_sandwich  % thickness controls 
154
155         setlinewidth 
156         moveto 
157         curveto 
158         lineto 
159         curveto 
160         gsave 
161         fill 
162         grestore 
163         stroke 
164 } bind def 
165
166 /draw_dashed_line % dash thickness dx dy
167
168         1 setlinecap 
169         1 setlinejoin 
170         setdash 
171         setlinewidth 
172         0 0 moveto
173         lineto
174         stroke 
175 } bind def 
176
177 /draw_dashed_slur % dash thickness controls
178
179         1 setlinecap 
180         1 setlinejoin 
181         setdash 
182         setlinewidth 
183         8 -2 roll 
184         moveto 
185         curveto 
186         stroke 
187 } bind def 
188
189
190
191 /bracket_traject 
192
193         /traject_ds exch def 
194         /traject_alpha exch def 
195         traject_ds traject_alpha sin mul add 
196         exch 
197         traject_ds traject_alpha cos mul add 
198         exch 
199 } bind def 
200
201
202
203 /half_bracket
204
205 %6 
206         0 0 
207 %5a 
208         bracket_thick arch_height add half_height arch_thick sub arch_width add 
209         arch_angle arch_height -0.15 mul bracket_traject 
210 %5b 
211         bracket_thick 0.5 mul half_height 
212         0 arch_height 0.5 mul bracket_traject 
213 %5c 
214         0 half_height 
215 %4a 
216         bracket_thick half_height arch_thick sub 
217         0 arch_height 0.4 mul bracket_traject 
218 %4b 
219         bracket_thick arch_height add half_height arch_thick sub arch_width add 
220         arch_angle arch_height -0.25 mul bracket_traject 
221 %4c 
222         bracket_thick arch_height add half_height arch_thick sub arch_width add 
223 %3 
224         bracket_thick half_height arch_thick sub 
225 %2 
226         bracket_thick 0 
227 %1 
228         0 0 
229 } bind def 
230
231 /draw_half_bracket { 
232         moveto 
233         lineto 
234         lineto 
235         curveto 
236         curveto 
237         lineto 
238         gsave 
239         fill 
240         grestore 
241 } bind def 
242
243 /draw_bracket % arch_angle arch_width arch_height bracket_height arch_thick bracket_thick
244
245         % urg
246
247         /bracket_thick exch def
248         /arch_thick exch def
249         /bracket_height exch def
250         /arch_height exch def
251         /arch_width exch def
252         /arch_angle exch def
253
254         bracket_height 2 div bracket_thick add /half_height exch def 
255         bracket_thick 0.5 mul setlinewidth
256         1 setlinecap 
257         1 setlinejoin 
258         half_bracket 
259         20 copy 
260         1 -1 scale 
261         draw_half_bracket 
262         stroke 
263         1 -1 scale 
264         draw_half_bracket 
265         stroke 
266 } bind def 
267