]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
* scm/output-gnome.scm: remove beam routine.
[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 /draw_polygon % x(n) y(n) x(n-1) y(n-1) ... x(1) y(1) n blot fill
153 {
154         /fillp exch def
155         /blot exch def
156
157         0 setlinecap
158         blot setlinewidth
159         1 setlinejoin
160
161         /points exch def
162         2 copy
163         moveto
164         1 1 points { pop lineto } for
165         closepath 
166         fillp {
167                 gsave stroke grestore fill
168         }{
169                 stroke
170         } ifelse
171 } bind def
172
173 /draw_repeat_slash % width slope thick
174 {
175         1 setlinecap
176         1 setlinejoin
177
178         /beamthick exch def
179         /slope exch def
180         /width exch def
181         beamthick beamthick slope div euclidean_length
182           /xwid exch def
183         0 0 moveto
184         xwid 0  rlineto
185         width slope width mul rlineto
186         xwid neg 0 rlineto
187       %  width neg width angle sin mul neg rlineto
188         closepath fill
189 } bind def
190
191 % this is for drawing slurs.
192 /draw_bezier_sandwich  % thickness controls
193 {
194     % round ending and round beginning
195     1 setlinejoin 1 setlinecap
196         setlinewidth
197         moveto
198         curveto
199         lineto
200         curveto
201         closepath
202         gsave
203         fill
204         grestore
205         stroke
206 } bind def
207
208 /draw_dot % x1 y2 R
209 {
210 %       0 360 arc fill stroke
211         0 360 arc closepath fill stroke
212 } bind def
213
214 /draw_circle % R T F
215 {
216         /filled exch def
217         setlinewidth
218         dup 0 moveto
219         0 exch 0 exch
220         0 360 arc closepath
221         gsave stroke grestore
222         filled { fill } if 
223 } bind def
224
225
226 %%%% JUNKME. use color & circle. 
227 /draw_white_dot % x1 y2 R
228 {
229 %       0 360 arc fill stroke
230         0 360 arc closepath % fill stroke
231 gsave
232  1 setgray fill
233 grestore
234 %       0 360 arc closepath % fill stroke
235   0.05 setlinewidth 0 setgray stroke
236 } bind def
237
238
239 %% JUNKME: Use color.  
240 /draw_white_text  % text scale font
241 {
242   %font
243   findfont
244   %scale
245   exch scalefont setfont
246   1 setgray
247   0 0 moveto
248   %-0.05 -0.05 moveto
249   % text
250   show
251 } bind def
252
253
254 /draw_dashed_line % dash thickness dx dy
255 {
256         1 setlinecap
257         1 setlinejoin
258         setdash
259         setlinewidth
260         0 0 moveto
261         lineto
262         stroke
263 } bind def
264
265 /draw_dashed_slur % dash thickness controls
266 {
267         1 setlinecap
268         1 setlinejoin
269         setdash
270         setlinewidth
271         8 -2 roll
272         moveto
273         curveto
274         stroke
275 } bind def
276
277
278 %end music-drawing-routines.ps