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