]> 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 % 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 % Emulation code from Postscript Language Reference.
11
12 /*SF
13 {
14         exch findfont exch
15         dup type /arraytype eq
16                 {makefont}
17                 {scalefont}
18         ifelse
19         setfont
20 } bind def
21
22 /languagelevel where
23         {pop languagelevel}
24         {1}
25 ifelse
26
27 2 lt
28         { /selectfont /*SF load def }
29 if
30
31 % end emulation code
32
33 /pdfmark where
34 {pop} {userdict /pdfmark /cleartomark load put} ifelse
35
36
37 % llx lly urx ury URI
38 /mark_URI
39 % It's possible to eliminate the coordinate variables by doing [ /Rect [ 7 3
40 % roll.  That is, however, kind of ugly.  It would be nice if this procedure
41 % were only included when PDF marks are enabled.
42 {
43     /command exch def
44     /ury exch def
45     /urx exch def
46     /lly exch def
47     /llx exch def
48     [
49         /Rect [ llx lly urx ury ]
50         
51         /Border [ 0 0 0 ]
52
53         /Action
54             <<
55                 /Subtype /URI
56                 /URI command
57             >>
58         /Subtype /Link
59     /ANN
60     pdfmark
61 }
62 bind def
63
64 % from adobe tech note 5002. 
65 /BeginEPSF { %def
66     /b4_Inc_state save def % Save state for cleanup
67     /dict_count countdictstack def % Count objects on dict stack
68     /op_count count 1 sub def % Count objects on operand stack
69     userdict begin % Push userdict on dict stack
70     /showpage { } def % Redefine showpage, { } = null proc
71     0 setgray 0 setlinecap % Prepare graphics state
72     1 setlinewidth 0 setlinejoin
73     10 setmiterlimit [ ] 0 setdash newpath
74     /languagelevel where % If level not equal to 1 then
75     {pop languagelevel % set strokeadjust and
76     1 ne % overprint to their defaults.
77       {false setstrokeadjust false setoverprint
78       } if
79     } if
80 } bind def
81
82 /EndEPSF { %def
83   count op_count sub {pop} repeat % Clean up stacks
84   countdictstack dict_count sub {end} repeat
85   b4_Inc_state restore
86 } bind def 
87
88
89 %<font> <encoding> <name> reencode-font
90 /reencode-font
91 {
92     /name exch def
93     /encoding exch def
94     dup length
95     dict begin {
96         1 index /FID ne {def} {pop
97         pop} ifelse
98     }
99     forall
100     /Encoding encoding
101     def currentdict
102     end
103     name exch definefont
104 } bind def
105
106
107
108 /set_tex_dimen
109 {
110         cvr def
111 } bind def
112
113
114 /stroke_and_fill {
115         gsave
116                 stroke
117         grestore
118         fill
119 } bind def
120
121 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
122         exch
123         4 1 roll
124         add
125         3 1 roll
126         add
127         exch
128 } bind def
129
130 /draw_round_box % width height x y blot
131 currentdict /testing known
132 {{
133         setlinewidth
134         0 setlinecap
135         1 setlinejoin
136         
137         rmoveto
138         currentpoint
139         4 2 roll
140         rectstroke
141 }}
142 {{
143         setlinewidth
144         0 setlinecap
145         1 setlinejoin
146
147         rmoveto
148         currentpoint
149         4 2 roll
150         4 copy
151         rectfill
152         rectstroke
153 }} ifelse bind def
154
155 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
156 {
157         setlinewidth %set to blot
158
159         0 setlinecap
160         1 setlinejoin
161
162         3 1 roll
163         /polygon_x
164         currentpoint
165         /polygon_y exch def
166         def
167         rmoveto % x(0) y(0)
168         { polygon_x polygon_y vector_add lineto } repeat % n times
169         closepath 
170         { %fill?
171                 stroke_and_fill
172         }{
173                 stroke
174         } ifelse
175 } bind def
176
177 /draw_repeat_slash % x-width width height
178 {
179         2 index % duplicate x-width
180         1 setlinecap
181         1 setlinejoin
182         
183           0  rlineto % x-width 0
184              rlineto % width height
185         neg 0 rlineto % -x-width 0
186         closepath fill
187 } bind def
188
189 % this is for drawing slurs.
190 /draw_bezier_sandwich  % thickness controls
191 {
192         gsave
193         currentpoint translate
194     % round ending and round beginning
195     1 setlinejoin 1 setlinecap
196         setlinewidth
197         moveto
198         curveto
199         lineto
200         curveto
201         closepath
202         stroke_and_fill
203         grestore
204 } bind def
205
206 /draw_dot % radius x y
207 {
208         rmoveto
209         currentpoint
210         3 2 roll
211         0 360 arc closepath stroke_and_fill
212 } bind def
213
214 /draw_circle % F R T
215 {
216         setlinewidth
217         dup 0 rmoveto
218         currentpoint 3 2 roll
219         0 360 arc closepath
220                 { stroke_and_fill } 
221                 { stroke }
222         ifelse
223 } bind def
224
225
226 /draw_line % dx dy x1 y1 thickness
227 {
228         setlinewidth
229         1 setlinecap
230         1 setlinejoin
231         rmoveto
232         rlineto
233         stroke
234 } bind def
235
236 /draw_dashed_line % dx dy thickness dashpattern
237 {
238         1 setlinecap
239         1 setlinejoin
240         setdash
241         setlinewidth
242         rlineto
243         stroke
244 } bind def
245
246 /draw_dashed_slur % controls thickness dash
247 {
248 gsave
249         currentpoint translate
250         1 setlinecap
251         1 setlinejoin
252         setdash
253         setlinewidth
254         moveto
255         curveto
256         stroke
257 grestore
258 } bind def
259
260 /print_glyphs {
261         {
262                 currentpoint
263                 3 2 roll
264                 glyphshow
265                 moveto
266                 rmoveto
267         }repeat
268 }bind def
269 %end music-drawing-routines.ps