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
100 setlinewidth % w h x y
105 currentpoint % w h x1 y1
113 currentpoint % w h x1 y1
119 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
121 setlinewidth %set to blot
132 { polygon_x polygon_y vector_add lineto } repeat % n times
141 /draw_circle % filled? radius thickness draw_circle
144 currentpoint % f? r x0 y0
145 3 2 roll % f? x0 y0 r
153 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
155 setlinewidth % f? x-r y-r
156 /savematrix matrix currentmatrix def
160 1 0 360 arc closepath
167 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
168 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
171 currentpoint translate
177 /endrad x_radius y_radius mul
178 x_radius x_radius mul
179 endangle cos endangle cos mul mul
180 y_radius y_radius mul
181 endangle sin endangle sin mul mul add sqrt div def
182 /endangle endangle sin endrad mul y_radius div
183 endangle cos endrad mul x_radius div atan def
184 /startrad x_radius y_radius mul
185 x_radius x_radius mul
186 startangle cos startangle cos mul mul
187 y_radius y_radius mul
188 startangle sin startangle sin mul mul add sqrt div def
189 /startangle startangle sin startrad mul y_radius div
190 startangle cos startrad mul x_radius div atan def
193 /savematrix matrix currentmatrix def
194 thickness setlinewidth
195 x_radius y_radius scale
196 startangle cos startangle sin moveto
198 startangle endangle eq { endangle 360 add } { endangle } ifelse
201 startangle cos startangle sin moveto endangle cos endangle sin lineto }
203 savematrix setmatrix filled { stroke_and_fill } { stroke } ifelse
207 /draw_line % dx dy x1 y1 thickness draw_line
209 setlinewidth % dx dy x1 y1
217 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
221 setdash % dx dy thickness
225 [] 0 setdash % reset dash pattern
228 /print_glyphs % w dx dy glyph print_glyphs
231 currentpoint %w dx dy glyph x0 y0
232 5 2 roll %w x0 y0 dx dy glyph
233 3 1 roll %w x0 y0 glyph dx dy
234 rmoveto %w x0 y0 glyph
240 %end music-drawing-routines.ps