]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
*** empty log message ***
[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
37 %<font> <encoding> <name> reencode-font
38 /reencode-font
39 {
40     /name exch def
41     /encoding exch def
42     dup length
43     dict begin {
44         1 index /FID ne {def} {pop
45         pop} ifelse
46     }
47     forall
48     /Encoding encoding
49     def currentdict
50     end
51     name exch definefont
52 } bind def
53
54
55 % llx lly urx ury URI
56 /mark_URI
57 {
58     /command exch def
59     /ury exch def
60     /urx exch def
61     /lly exch def
62     /llx exch def
63     [
64         /Rect [ llx lly urx ury ]
65         /Border [ 0 0 0 0 ]
66
67         /Action
68             <<
69                 /Subtype /URI
70                 /URI command
71             >>
72         /Subtype /Link
73     /ANN
74     pdfmark
75 }
76 bind def
77
78 /set_tex_dimen
79 {
80         cvr def
81 } bind def
82
83
84
85 /euclidean_length
86 {
87         1 copy mul exch 1 copy mul add sqrt
88 } bind def
89
90 % FIXME.  translate to middle of box.
91 % Nice rectangle with rounded corners
92 /draw_box % breapth width depth height
93 {
94 %       currentdict /testing known {
95                 %% real thin lines for testing
96                 /blot 0.005 def
97 %       }{
98 %               /blot blot-diameter def
99 %       } ifelse
100
101         0 setlinecap
102         blot setlinewidth
103         1 setlinejoin
104
105         blot 2 div sub /h exch def
106         blot 2 div sub /d exch def
107         blot 2 div sub /w exch def
108         blot 2 div sub /b exch def
109
110         b neg d neg moveto
111         b w add 0 rlineto
112         0 d h add rlineto
113         b w add neg 0 rlineto
114         0 d h add neg rlineto
115
116         currentdict /testing known {
117                 %% outline only, for testing:
118                 stroke
119         }{
120                 closepath gsave stroke grestore fill
121         } ifelse
122 } bind def
123
124
125 /draw_round_box % breapth width depth height blot
126 {
127         /blot exch def
128
129         0 setlinecap
130         blot setlinewidth
131         1 setlinejoin
132
133         blot 2 div sub /h exch def
134         blot 2 div sub /d exch def
135         blot 2 div sub /w exch def
136         blot 2 div sub /b exch def
137
138         b neg d neg moveto
139         b w add 0 rlineto
140         0 d h add rlineto
141         b w add neg 0 rlineto
142         0 d h add neg rlineto
143
144         currentdict /testing known {
145                 %% outline only, for testing:
146                 stroke
147         }{
148                 closepath gsave stroke grestore fill
149         } ifelse
150 } bind def
151
152 % Nice beam with rounded corners
153 /draw_beam % slope width thick  blot
154 {
155         /blot exch def
156         blot setlinewidth
157
158         0 setlinecap
159         1 setlinejoin
160
161         blot sub /t exch def
162         blot sub /w exch def
163         w mul /h exch def
164
165         blot 2 div t 2 div neg moveto
166         w h rlineto
167         0 t rlineto
168         w neg h neg rlineto
169         0 t neg rlineto
170
171         currentdict /testing known {
172                 %% outline only, for testing:
173                 stroke
174         }{
175                 closepath gsave stroke grestore fill
176         } ifelse
177 } bind def
178
179 /draw_polygon % x(n) y(n) x(n-1) y(n-1) ... x(1) y(1) n blot fill
180 {
181         /fillp exch def
182         /blot exch def
183
184         0 setlinecap
185         blot setlinewidth
186         1 setlinejoin
187
188         /points exch def
189         2 copy
190         moveto
191         1 1 points { pop lineto } for
192         closepath 
193         fillp {
194                 gsave stroke grestore fill
195         }{
196                 stroke
197         } ifelse
198 } bind def
199
200 /draw_repeat_slash % width slope thick
201 {
202         1 setlinecap
203         1 setlinejoin
204
205         /beamthick exch def
206         /slope exch def
207         /width exch def
208         beamthick beamthick slope div euclidean_length
209           /xwid exch def
210         0 0 moveto
211         xwid 0  rlineto
212         width slope width mul rlineto
213         xwid neg 0 rlineto
214       %  width neg width angle sin mul neg rlineto
215         closepath fill
216 } bind def
217
218 % this is for drawing slurs.
219 /draw_bezier_sandwich  % thickness controls
220 {
221     % round ending and round beginning
222     1 setlinejoin 1 setlinecap
223         setlinewidth
224         moveto
225         curveto
226         lineto
227         curveto
228         closepath
229         gsave
230         fill
231         grestore
232         stroke
233 } bind def
234
235 /draw_dot % x1 y2 R
236 {
237 %       0 360 arc fill stroke
238         0 360 arc closepath fill stroke
239 } bind def
240
241 /draw_circle % R T F
242 {
243         /filled exch def
244         setlinewidth
245         dup 0 moveto
246         0 exch 0 exch
247         0 360 arc closepath
248         gsave stroke grestore
249         filled { fill } if 
250 } bind def
251
252
253 %%%% JUNKME. use color & circle. 
254 /draw_white_dot % x1 y2 R
255 {
256 %       0 360 arc fill stroke
257         0 360 arc closepath % fill stroke
258 gsave
259  1 setgray fill
260 grestore
261 %       0 360 arc closepath % fill stroke
262   0.05 setlinewidth 0 setgray stroke
263 } bind def
264
265
266 %% JUNKME: Use color.  
267 /draw_white_text  % text scale font
268 {
269   %font
270   findfont
271   %scale
272   exch scalefont setfont
273   1 setgray
274   0 0 moveto
275   %-0.05 -0.05 moveto
276   % text
277   show
278 } bind def
279
280
281 /draw_dashed_line % dash thickness dx dy
282 {
283         1 setlinecap
284         1 setlinejoin
285         setdash
286         setlinewidth
287         0 0 moveto
288         lineto
289         stroke
290 } bind def
291
292 /draw_dashed_slur % dash thickness controls
293 {
294         1 setlinecap
295         1 setlinejoin
296         setdash
297         setlinewidth
298         8 -2 roll
299         moveto
300         curveto
301         stroke
302 } bind def
303
304
305 %end music-drawing-routines.ps