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 % llx lly urx ury page
47 /Rect [ llx lly urx ury ]
56 % from adobe tech note 5002.
58 /b4_Inc_state save def % Save state for cleanup
59 /dict_count countdictstack def % Count objects on dict stack
60 /op_count count 1 sub def % Count objects on operand stack
61 userdict begin % Push userdict on dict stack
62 /showpage { } def % Redefine showpage, { } = null proc
63 0 setgray 0 setlinecap % Prepare graphics state
64 1 setlinewidth 0 setlinejoin
65 10 setmiterlimit [ ] 0 setdash newpath
66 /languagelevel where % If level not equal to 1 then
67 {pop languagelevel % set strokeadjust and
68 1 ne % overprint to their defaults.
69 {false setstrokeadjust false setoverprint
75 count op_count sub {pop} repeat % Clean up stacks
76 countdictstack dict_count sub {end} repeat
87 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
96 /draw_round_box % width height x y blot
98 setlinewidth % w h x y
103 currentpoint % w h x1 y1
110 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
112 setlinewidth %set to blot
123 { polygon_x polygon_y vector_add lineto } repeat % n times
132 /draw_repeat_slash % x-width width height draw_repeat_slash
134 2 index % duplicate x-width
138 0 rlineto % x-width 0
139 rlineto % width height
140 neg 0 rlineto % -x-width 0
144 % this is for drawing slurs and barre-indicators.
145 /draw_bezier_sandwich % x5 y5 x6 y6 x7 y7
149 % linewidth draw_bezier_sandwich
152 currentpoint translate
153 % round ending and round beginning
154 1 setlinejoin 1 setlinecap
165 /draw_dot % radius x y draw_dot
170 0 360 arc closepath stroke_and_fill
173 /draw_circle % filled? radius thickness draw_circle
176 currentpoint % f? r x0 y0
177 3 2 roll % f? x0 y0 r
185 /draw_oval % filled? x-radius y-radius thickness draw_ellipse
187 setlinewidth % f? x-r y-r
191 0 yrad -2 xrad mul dup yrad exch 0 rcurveto
192 0 yrad neg dup 2 xrad mul dup 3 1 roll 0 rcurveto
199 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
201 setlinewidth % f? x-r y-r
202 /savematrix matrix currentmatrix def
206 1 0 360 arc closepath
213 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
214 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
217 currentpoint translate
223 /endrad x_radius y_radius mul
224 x_radius x_radius mul
225 endangle cos endangle cos mul mul
226 y_radius y_radius mul
227 endangle sin endangle sin mul mul add sqrt div def
228 /endangle endangle sin endrad mul y_radius div
229 endangle cos endrad mul x_radius div atan def
230 /startrad x_radius y_radius mul
231 x_radius x_radius mul
232 startangle cos startangle cos mul mul
233 y_radius y_radius mul
234 startangle sin startangle sin mul mul add sqrt div def
235 /startangle startangle sin startrad mul y_radius div
236 startangle cos startrad mul x_radius div atan def
239 /savematrix matrix currentmatrix def
240 thickness setlinewidth
241 x_radius y_radius scale
242 startangle cos startangle sin moveto
244 startangle endangle eq { endangle 360 add } { endangle } ifelse
247 startangle cos startangle sin moveto endangle cos endangle sin lineto }
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