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