1 %!PS-Adobe-1.0: music-drawing-routines.ps
3 % Functions for direct and embedded PostScript
6 %% TODO: use dicts or prefixes to prevent namespace pollution.
9 {pop} {userdict /pdfmark /cleartomark load put} ifelse
22 /Rect [ llx lly urx ury ]
45 1 copy mul exch 1 copy mul add sqrt
48 % FIXME. translate to middle of box.
49 % Nice rectangle with rounded corners
50 /draw_box % breapth width depth height
52 % currentdict /testing known {
53 %% real thin lines for testing
56 % /blot blot-diameter def
63 blot 2 div sub /h exch def
64 blot 2 div sub /d exch def
65 blot 2 div sub /w exch def
66 blot 2 div sub /b exch def
74 currentdict /testing known {
75 %% outline only, for testing:
78 closepath gsave stroke grestore fill
83 /draw_round_box % breapth width depth height blot
91 blot 2 div sub /h exch def
92 blot 2 div sub /d exch def
93 blot 2 div sub /w exch def
94 blot 2 div sub /b exch def
100 0 d h add neg rlineto
102 currentdict /testing known {
103 %% outline only, for testing:
106 closepath gsave stroke grestore fill
110 % Nice beam with rounded corners
111 /draw_beam % slope width thick blot
123 blot 2 div t 2 div neg moveto
129 currentdict /testing known {
130 %% outline only, for testing:
133 closepath gsave stroke grestore fill
137 /draw_polygon % x(n) y(n) x(n-1) y(n-1) ... x(1) y(1) n blot
148 1 1 points {pop lineto} for
149 currentdict /testing known {
150 %% outline only, for testing:
153 closepath gsave stroke grestore fill
157 /draw_repeat_slash % width slope thick
165 beamthick beamthick slope div euclidean_length
169 width slope width mul rlineto
171 % width neg width angle sin mul neg rlineto
176 /draw_white_text % text scale font
181 exch scalefont setfont
189 /draw_ez_ball % ch letter_col ball_col font
192 findfont 0.7 scalefont setfont
196 0.5 0 0.5 0 360 arc closepath fill stroke
201 0.5 0 0.4 0 360 arc closepath
206 % 0.25 is empiric centering. Change to taste
212 % Simple, but does it work everywhere?
213 % Han-Wen reports that one printer (brand?) at cs.uu.nl chokes on this,
214 % reverted for now -- jcn
216 % The filled circles are drawn by setting the linewidth
217 % to 2*radius and drawing a point.
218 /simple_draw_ez_ball % ch letter_col ball_col font
221 findfont 0.85 scalefont setfont
222 /origin { 0.45 0 } def
234 % 0.25 is empiric centering. Change to taste
241 % this is for drawing slurs.
242 /draw_bezier_sandwich % thickness controls
244 % round ending and round beginning
245 1 setlinejoin 1 setlinecap
260 % 0 360 arc fill stroke
261 0 360 arc closepath fill stroke
269 0 360 arc closepath stroke
272 /draw_white_dot % x1 y2 R
274 % 0 360 arc fill stroke
275 0 360 arc closepath % fill stroke
279 % 0 360 arc closepath % fill stroke
280 0.05 setlinewidth 0 setgray stroke
283 /draw_dashed_line % dash thickness dx dy
294 /draw_dashed_slur % dash thickness controls
307 % a b c d subvec == a-c b-d
315 % centre? zzwidth zzheight thickness x0 y0 x1 y1
320 4 2 roll % zzuw zzh th x1 y1 x0 y0
323 subvec % zzuw zzh th dx dy
325 2 copy euclidean_length /l exch def
330 l exch div round /n exch def
332 /zzw l n 2 mul div def
334 uy zzh mul 2 div ux zzh mul -2 div rmoveto
337 ux zzw mul uy zzh mul sub
338 uy zzw mul ux zzh mul add
340 ux zzw mul uy zzh mul add
341 uy zzw mul ux zzh mul sub
346 ux l mul uy l mul rlineto
355 /traject_alpha exch def
356 traject_ds traject_alpha sin mul add
358 traject_ds traject_alpha cos mul add
369 bracket_thick arch_height add half_height arch_thick sub arch_width add
370 arch_angle arch_height -0.15 mul bracket_traject
372 bracket_thick 0.5 mul half_height
373 0 arch_height 0.5 mul bracket_traject
377 bracket_thick half_height arch_thick sub
378 0 arch_height 0.4 mul bracket_traject
380 bracket_thick arch_height add half_height arch_thick sub arch_width add
381 arch_angle arch_height -0.25 mul bracket_traject
383 bracket_thick arch_height add half_height arch_thick sub arch_width add
385 bracket_thick half_height arch_thick sub
404 /draw_bracket % arch_angle arch_width arch_height bracket_height arch_thick bracket_thick
408 /bracket_thick exch def
410 /bracket_height exch def
411 /arch_height exch def
415 bracket_height 2 div bracket_thick add /half_height exch def
416 bracket_thick 0.5 mul setlinewidth
429 %end music-drawing-routines.ps