]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / ps / music-drawing-routines.ps
1 %!PS-Adobe-1.0: music-drawing-routines.ps
2 %
3 % Functions for direct and embedded PostScript
4
5 % Careful with double % as comment prefix.
6 % Any %%X comment is interpreted as DSC comments.
7
8 % TODO: use dicts or prefixes to prevent namespace pollution.
9
10 /pdfmark where
11 {pop} {userdict /pdfmark /cleartomark load put} ifelse
12
13
14 % llx lly urx ury URI
15 /mark_URI
16 {
17     /uri exch def
18     /ury exch def
19     /urx exch def
20     /lly exch def
21     /llx exch def
22     [
23         /Rect [ llx lly urx ury ]
24         
25         /Border [ 0 0 0 ]
26
27         /Action
28             <<
29                 /Subtype /URI
30                 /URI uri
31             >>
32         /Subtype /Link
33     /ANN
34     pdfmark
35 }
36 bind def
37
38 % from adobe tech note 5002.
39 /BeginEPSF { %def
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
52       } if
53     } if
54 } bind def
55
56 /EndEPSF { %def
57   count op_count sub {pop} repeat % Clean up stacks
58   countdictstack dict_count sub {end} repeat
59   b4_Inc_state restore
60 } bind def
61
62 /stroke_and_fill {
63         gsave
64                 stroke
65         grestore
66         fill
67 } bind def
68
69 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
70         exch
71         4 1 roll
72         add
73         3 1 roll
74         add
75         exch
76 } bind def
77
78 /draw_round_box % width height x y blot
79 {
80         setlinewidth % w h x y
81         0 setlinecap
82         1 setlinejoin
83
84         rmoveto % w h
85         currentpoint % w h x1 y1
86         4 2 roll % x1 y1 w h
87         4 copy
88         rectfill
89         rectstroke
90 } bind def
91
92 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
93 {
94         setlinewidth %set to blot
95
96         0 setlinecap
97         1 setlinejoin
98
99         3 1 roll
100         /polygon_x
101         currentpoint
102         /polygon_y exch def
103         def
104         rmoveto % x(0) y(0)
105         { polygon_x polygon_y vector_add lineto } repeat % n times
106         closepath
107         { %fill?
108                 stroke_and_fill
109         }{
110                 stroke
111         } ifelse
112 } bind def
113
114 /draw_repeat_slash % x-width width height draw_repeat_slash
115 {
116         2 index % duplicate x-width
117         1 setlinecap
118         1 setlinejoin
119         
120           0  rlineto % x-width 0
121              rlineto % width height
122         neg 0 rlineto % -x-width 0
123         closepath fill
124 } bind def
125
126 % this is for drawing slurs and barre-indicators.
127 /draw_bezier_sandwich  % x5 y5 x6 y6 x7 y7
128                        % x4 y4
129                        % x1 y1 x2 y2 x3 y3
130                        % x0 y0
131                        % linewidth draw_bezier_sandwich
132 {
133         gsave
134         currentpoint translate
135         % round ending and round beginning
136         1 setlinejoin 1 setlinecap
137         setlinewidth
138         moveto
139         curveto
140         lineto
141         curveto
142         closepath
143         stroke_and_fill
144         grestore
145 } bind def
146
147 /draw_dot % radius x y draw_dot
148 {
149         rmoveto
150         currentpoint
151         3 2 roll
152         0 360 arc closepath stroke_and_fill
153 } bind def
154
155 /draw_circle % filled? radius thickness draw_circle
156 {
157         setlinewidth    % f? r
158         currentpoint    % f? r x0 y0
159         3 2 roll        % f? x0 y0 r
160         dup 0 rmoveto
161         0 360 arc closepath
162                 { stroke_and_fill }
163                 { stroke }
164         ifelse
165 } bind def
166
167 /draw_oval % filled? x-radius y-radius thickness draw_ellipse
168 {
169   setlinewidth % f? x-r y-r
170   /yrad exch def
171   /xrad exch def
172   xrad 0 rmoveto
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
175   closepath
176       { stroke_and_fill}
177       { stroke }
178   ifelse
179 } bind def
180
181 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
182 {
183   setlinewidth % f? x-r y-r
184   /savematrix matrix currentmatrix def
185   scale % f?
186   currentpoint
187   1 0 rmoveto
188   1 0 360  arc closepath
189   savematrix setmatrix
190              { stroke_and_fill}
191              { stroke }
192   ifelse
193 } bind def
194
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)
197 {
198   gsave
199   currentpoint translate
200   /thickness exch def
201   /endangle exch def
202   /startangle exch def
203   /y_radius exch def
204   /x_radius exch def
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
219   /connect exch def
220   /filled exch def
221   /savematrix matrix currentmatrix def
222   thickness setlinewidth
223   x_radius y_radius scale
224   startangle cos startangle sin moveto
225   0 0 1 startangle
226     startangle endangle eq { endangle 360 add } { endangle } ifelse
227     arc
228   connect {
229     startangle cos startangle sin moveto endangle cos endangle sin lineto }
230     if
231   savematrix setmatrix filled { stroke_and_fill } { stroke } ifelse
232   grestore
233 } bind def
234
235 /draw_line % dx dy x1 y1 thickness draw_line
236 {
237         setlinewidth % dx dy x1 y1
238         1 setlinecap
239         1 setlinejoin
240         rmoveto % dx dy
241         rlineto
242         stroke
243 } bind def
244
245 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
246 {
247         1 setlinecap
248         1 setlinejoin
249         setdash % dx dy thickness
250         setlinewidth %dx dy
251         rlineto
252         stroke
253         [] 0 setdash % reset dash pattern
254 } bind def
255
256 /draw_dashed_slur % controls thickness dash
257 {
258 gsave
259         currentpoint translate
260         1 setlinecap
261         1 setlinejoin
262         setdash
263         setlinewidth
264         8 2 roll
265         moveto
266         curveto
267         stroke
268 grestore
269 } bind def
270
271 /print_glyphs % w dx dy glyph print_glyphs
272 {
273         {
274                 currentpoint %w dx dy glyph x0 y0
275                 5 2 roll %w x0 y0 dx dy glyph
276                 3 1 roll %w x0 y0 glyph dx dy
277                 rmoveto %w x0 y0 glyph
278                 glyphshow %w x0 y0
279                 moveto %w
280                 0 rmoveto
281         }repeat
282 }bind def
283 %end music-drawing-routines.ps