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
70 count op_count sub {pop} repeat % Clean up stacks
71 countdictstack dict_count sub {end} repeat
89 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
98 /draw_round_box % width height x y blot
101 matrix currentmatrix 5 1 roll
102 currentpoint translate newpath translate
103 2 copy 0 min exch 0 min exch translate
105 currentlinewidth 0 eq
109 0 1 index 2 div moveto
118 1 index 2 div 0 moveto
125 0 0 4 2 roll rectfill
132 2 copy 0 eq exch 0 eq or
141 currentstrokeadjust {
142 currentlinewidth 2 div
143 0 0 2 index 180 270 arc
144 2 index 0 2 index 270 360 arc
146 0 2 index 3 -1 roll 90 180 arc
150 2 copy add currentlinewidth add 10 add % large enough
152 2 index 1 index neg lineto
153 2 index 1 index lineto
154 0 exch lineto closepath
156 0 1 index 2 div moveto
157 currentlinewidth add setlinewidth
166 2 copy add currentlinewidth add 10 add % large enough
170 neg 1 index lineto closepath
172 1 index 2 div 0 moveto
173 exch currentlinewidth add setlinewidth
190 0 0 4 2 roll 4 copy rectstroke rectfill
200 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
202 setlinewidth %set to blot
213 { polygon_x polygon_y vector_add lineto } repeat % n times
218 /draw_circle % filled? radius thickness draw_circle
221 currentpoint % f? r x0 y0
222 3 2 roll % f? x0 y0 r
228 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
230 setlinewidth % f? x-r y-r
231 /savematrix matrix currentmatrix def
235 1 0 360 arc closepath
240 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
241 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
244 currentpoint translate
250 /endrad x_radius y_radius mul
251 x_radius x_radius mul
252 endangle cos endangle cos mul mul
253 y_radius y_radius mul
254 endangle sin endangle sin mul mul add sqrt div def
255 /endangle endangle sin endrad mul y_radius div
256 endangle cos endrad mul x_radius div atan def
257 /startrad x_radius y_radius mul
258 x_radius x_radius mul
259 startangle cos startangle cos mul mul
260 y_radius y_radius mul
261 startangle sin startangle sin mul mul add sqrt div def
262 /startangle startangle sin startrad mul y_radius div
263 startangle cos startrad mul x_radius div atan def
266 /savematrix matrix currentmatrix def
267 thickness setlinewidth
268 x_radius y_radius scale
269 startangle cos startangle sin moveto
271 startangle endangle eq { endangle 360 add } { endangle } ifelse
274 startangle cos startangle sin moveto endangle cos endangle sin lineto }
276 savematrix setmatrix filled stroke_and_fill?
280 /draw_line % dx dy x1 y1 thickness draw_line
282 setlinewidth % dx dy x1 y1
289 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
292 setdash % dx dy thickness
296 [] 0 setdash % reset dash pattern
299 /print_glyphs % w dx dy glyph print_glyphs
302 currentpoint %w dx dy glyph x0 y0
303 5 2 roll %w x0 y0 dx dy glyph
304 3 1 roll %w x0 y0 glyph dx dy
305 rmoveto %w x0 y0 glyph
311 %end music-drawing-routines.ps