1 %!PS-Adobe-1.0: music-drawing-routines.ps
3 % Functions for direct and embedded PostScript
5 % Careful with double % as comment prefix.
6 % Any %%X comment is interpreted as DSC comments.
8 % TODO: use dicts or prefixes to prevent namespace pollution.
11 {pop} {userdict /pdfmark /cleartomark load put} ifelse
23 /Rect [ llx lly urx ury ]
38 % from adobe tech note 5002.
40 /b4_Inc_state save def % Save state for cleanup
41 /dict_count countdictstack def % Count objects on dict stack
42 /op_count count 1 sub def % Count objects on operand stack
43 userdict begin % Push userdict on dict stack
44 /showpage { } def % Redefine showpage, { } = null proc
45 0 setgray 0 setlinecap % Prepare graphics state
46 1 setlinewidth 0 setlinejoin
47 10 setmiterlimit [ ] 0 setdash newpath
48 /languagelevel where % If level not equal to 1 then
49 {pop languagelevel % set strokeadjust and
50 1 ne % overprint to their defaults.
51 {false setstrokeadjust false setoverprint
57 count op_count sub {pop} repeat % Clean up stacks
58 countdictstack dict_count sub {end} repeat
69 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
78 /draw_round_box % width height x y blot
80 setlinewidth % w h x y
85 currentpoint % w h x1 y1
92 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
94 setlinewidth %set to blot
105 { polygon_x polygon_y vector_add lineto } repeat % n times
114 /draw_repeat_slash % x-width width height draw_repeat_slash
116 2 index % duplicate x-width
120 0 rlineto % x-width 0
121 rlineto % width height
122 neg 0 rlineto % -x-width 0
126 % this is for drawing slurs and barre-indicators.
127 /draw_bezier_sandwich % x5 y5 x6 y6 x7 y7
131 % linewidth draw_bezier_sandwich
134 currentpoint translate
135 % round ending and round beginning
136 1 setlinejoin 1 setlinecap
147 /draw_dot % radius x y draw_dot
152 0 360 arc closepath stroke_and_fill
155 /draw_circle % filled? radius thickness draw_circle
158 currentpoint % f? r x0 y0
159 3 2 roll % f? x0 y0 r
167 /draw_oval % filled? x-radius y-radius thickness draw_ellipse
169 setlinewidth % f? x-r y-r
173 0 yrad -2 xrad mul dup yrad exch 0 rcurveto
174 0 yrad neg dup 2 xrad mul dup 3 1 roll 0 rcurveto
181 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
183 setlinewidth % f? x-r y-r
184 /savematrix matrix currentmatrix def
188 1 0 360 arc closepath
195 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
196 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
199 currentpoint translate
205 /endrad x_radius y_radius mul
206 x_radius x_radius mul
207 endangle cos endangle cos mul mul
208 y_radius y_radius mul
209 endangle sin endangle sin mul mul add sqrt div def
210 /endangle endangle sin endrad mul y_radius div
211 endangle cos endrad mul x_radius div atan def
212 /startrad x_radius y_radius mul
213 x_radius x_radius mul
214 startangle cos startangle cos mul mul
215 y_radius y_radius mul
216 startangle sin startangle sin mul mul add sqrt div def
217 /startangle startangle sin startrad mul y_radius div
218 startangle cos startrad mul x_radius div atan def
221 /savematrix matrix currentmatrix def
222 thickness setlinewidth
223 x_radius y_radius scale
224 startangle cos startangle sin moveto
226 startangle endangle eq { endangle 360 add } { endangle } ifelse
229 startangle cos startangle sin moveto endangle cos endangle sin lineto }
231 savematrix setmatrix filled { stroke_and_fill } { stroke } ifelse
235 /draw_connected_shape
238 currentpoint translate
241 /savematrix matrix currentmatrix def
247 shlen { } repeat shlen 2 eq { lineto } { curveto } ifelse
248 } repeat connect { closepath } if
249 savematrix setmatrix filled { stroke_and_fill } { stroke } ifelse
253 /draw_line % dx dy x1 y1 thickness draw_line
255 setlinewidth % dx dy x1 y1
263 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
267 setdash % dx dy thickness
271 [] 0 setdash % reset dash pattern
274 /draw_dashed_slur % controls thickness dash
277 currentpoint translate
289 /print_glyphs % w dx dy glyph print_glyphs
292 currentpoint %w dx dy glyph x0 y0
293 5 2 roll %w x0 y0 dx dy glyph
294 3 1 roll %w x0 y0 glyph dx dy
295 rmoveto %w x0 y0 glyph
301 %end music-drawing-routines.ps