]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
85434be8a8dca4d61e6ccdadcd5fce60d119647c
[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
6 %% TODO: use dicts or prefixes to prevent namespace pollution.
7
8 /pdfmark where
9 {pop} {userdict /pdfmark /cleartomark load put} ifelse
10
11 % from adobe tech note 5002. 
12 /BeginEPSF { %def
13     /b4_Inc_state save def % Save state for cleanup
14     /dict_count countdictstack def % Count objects on dict stack
15     /op_count count 1 sub def % Count objects on operand stack
16     userdict begin % Push userdict on dict stack
17     /showpage { } def % Redefine showpage, { } = null proc
18     0 setgray 0 setlinecap % Prepare graphics state
19     1 setlinewidth 0 setlinejoin
20     10 setmiterlimit [ ] 0 setdash newpath
21     /languagelevel where % If level not equal to 1 then
22     {pop languagelevel % set strokeadjust and
23     1 ne % overprint to their defaults.
24       {false setstrokeadjust false setoverprint
25       } if
26     } if
27 } bind def
28
29
30 /EndEPSF { %def
31   count op_count sub {pop} repeat % Clean up stacks
32   countdictstack dict_count sub {end} repeat
33   b4_Inc_state restore
34 } bind def 
35
36 % llx lly urx ury URI
37 /mark_URI
38 {
39     /command exch def
40     /ury exch def
41     /urx exch def
42     /lly exch def
43     /llx exch def
44     [
45         /Rect [ llx lly urx ury ]
46         /Border [ 0 0 0 0 ]
47
48         /Action
49             <<
50                 /Subtype /URI
51                 /URI command
52             >>
53         /Subtype /Link
54     /ANN
55     pdfmark
56 }
57 bind def
58
59 /set_tex_dimen
60 {
61         cvr def
62 } bind def
63
64
65
66 /euclidean_length
67 {
68         1 copy mul exch 1 copy mul add sqrt
69 } bind def
70
71 % FIXME.  translate to middle of box.
72 % Nice rectangle with rounded corners
73 /draw_box % breapth width depth height
74 {
75 %       currentdict /testing known {
76                 %% real thin lines for testing
77                 /blot 0.005 def
78 %       }{
79 %               /blot blot-diameter def
80 %       } ifelse
81
82         0 setlinecap
83         blot setlinewidth
84         1 setlinejoin
85
86         blot 2 div sub /h exch def
87         blot 2 div sub /d exch def
88         blot 2 div sub /w exch def
89         blot 2 div sub /b exch def
90
91         b neg d neg moveto
92         b w add 0 rlineto
93         0 d h add rlineto
94         b w add neg 0 rlineto
95         0 d h add neg rlineto
96
97         currentdict /testing known {
98                 %% outline only, for testing:
99                 stroke
100         }{
101                 closepath gsave stroke grestore fill
102         } ifelse
103 } bind def
104
105
106 /draw_round_box % breapth width depth height blot
107 {
108         /blot exch def
109
110         0 setlinecap
111         blot setlinewidth
112         1 setlinejoin
113
114         blot 2 div sub /h exch def
115         blot 2 div sub /d exch def
116         blot 2 div sub /w exch def
117         blot 2 div sub /b exch def
118
119         b neg d neg moveto
120         b w add 0 rlineto
121         0 d h add rlineto
122         b w add neg 0 rlineto
123         0 d h add neg rlineto
124
125         currentdict /testing known {
126                 %% outline only, for testing:
127                 stroke
128         }{
129                 closepath gsave stroke grestore fill
130         } ifelse
131 } bind def
132
133 % Nice beam with rounded corners
134 /draw_beam % slope width thick  blot
135 {
136         /blot exch def
137         blot setlinewidth
138
139         0 setlinecap
140         1 setlinejoin
141
142         blot sub /t exch def
143         blot sub /w exch def
144         w mul /h exch def
145
146         blot 2 div t 2 div neg moveto
147         w h rlineto
148         0 t rlineto
149         w neg h neg rlineto
150         0 t neg rlineto
151
152         currentdict /testing known {
153                 %% outline only, for testing:
154                 stroke
155         }{
156                 closepath gsave stroke grestore fill
157         } ifelse
158 } bind def
159
160 /draw_polygon % x(n) y(n) x(n-1) y(n-1) ... x(1) y(1) n blot fill
161 {
162         /fillp exch def
163         /blot exch def
164
165         0 setlinecap
166         blot setlinewidth
167         1 setlinejoin
168
169         /points exch def
170         2 copy
171         moveto
172         1 1 points { pop lineto } for
173         closepath 
174         fillp {
175                 gsave stroke grestore fill
176         }{
177                 stroke
178         } ifelse
179 } bind def
180
181 /draw_repeat_slash % width slope thick
182 {
183         1 setlinecap
184         1 setlinejoin
185
186         /beamthick exch def
187         /slope exch def
188         /width exch def
189         beamthick beamthick slope div euclidean_length
190           /xwid exch def
191         0 0 moveto
192         xwid 0  rlineto
193         width slope width mul rlineto
194         xwid neg 0 rlineto
195       %  width neg width angle sin mul neg rlineto
196         closepath fill
197 } bind def
198
199 % this is for drawing slurs.
200 /draw_bezier_sandwich  % thickness controls
201 {
202     % round ending and round beginning
203     1 setlinejoin 1 setlinecap
204         setlinewidth
205         moveto
206         curveto
207         lineto
208         curveto
209         closepath
210         gsave
211         fill
212         grestore
213         stroke
214 } bind def
215
216 /draw_dot % x1 y2 R
217 {
218 %       0 360 arc fill stroke
219         0 360 arc closepath fill stroke
220 } bind def
221
222 /draw_circle % R T F
223 {
224         /filled exch def
225         setlinewidth
226         dup 0 moveto
227         0 exch 0 exch
228         0 360 arc closepath
229         gsave stroke grestore
230         filled { fill } if 
231 } bind def
232
233
234
235 /draw_dashed_line % dash thickness dx dy
236 {
237         1 setlinecap
238         1 setlinejoin
239         setdash
240         setlinewidth
241         0 0 moveto
242         lineto
243         stroke
244 } bind def
245
246 /draw_dashed_slur % dash thickness controls
247 {
248         1 setlinecap
249         1 setlinejoin
250         setdash
251         setlinewidth
252         8 -2 roll
253         moveto
254         curveto
255         stroke
256 } bind def
257
258
259 %end music-drawing-routines.ps