]> 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 /draw_round_box % x y width height blot
122 {
123         setlinewidth
124         0 setlinecap
125         1 setlinejoin
126
127         currentdict /testing known {
128                 %% outline only, for testing:
129         }{
130                 4 copy
131                 rectfill
132         } ifelse
133         rectstroke
134 } bind def
135
136 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
137 {
138         setlinewidth %set to blot
139
140         0 setlinecap
141         1 setlinejoin
142
143         3 1 roll
144         moveto % x(0) y(0)
145         { lineto } repeat % n times
146         closepath 
147         { %fill?
148                 stroke_and_fill
149         }{
150                 stroke
151         } ifelse
152 } bind def
153
154 /draw_repeat_slash % x-width width height
155 {
156         2 index % duplicate x-width
157         1 setlinecap
158         1 setlinejoin
159         
160         0 0 moveto
161           0  rlineto % x-width 0
162              rlineto % width height
163         neg 0 rlineto % -x-width 0
164         closepath fill
165 } bind def
166
167 % this is for drawing slurs.
168 /draw_bezier_sandwich  % thickness controls
169 {
170     % round ending and round beginning
171     1 setlinejoin 1 setlinecap
172         setlinewidth
173         moveto
174         curveto
175         lineto
176         curveto
177         closepath
178         stroke_and_fill
179 } bind def
180
181 /draw_dot % x1 y2 R
182 {
183 %       0 360 arc fill stroke
184         0 360 arc closepath stroke_and_fill
185 } bind def
186
187 /draw_circle % F R T
188 {
189         setlinewidth
190         dup 0 moveto
191         0 exch 0 exch
192         0 360 arc closepath
193                 { stroke_and_fill } 
194                 { stroke }
195         ifelse
196 } bind def
197
198
199 % JUNKME. use color & circle. 
200 /draw_white_dot % x1 y2 R
201 {
202 %       0 360 arc fill stroke
203         0 360 arc closepath % fill stroke
204 gsave
205  1 setgray fill
206 grestore
207 %       0 360 arc closepath % fill stroke
208   0.05 setlinewidth 0 setgray stroke
209 } bind def
210
211
212 % JUNKME: Use color.  
213 /draw_white_text  % text scale font
214 {
215   exch selectfont
216   1 setgray
217   0 0 moveto
218   %-0.05 -0.05 moveto
219   % text
220   show
221 } bind def
222
223
224 /draw_dashed_line % dash thickness dx dy
225 {
226         1 setlinecap
227         1 setlinejoin
228         setdash
229         setlinewidth
230         0 0 moveto
231         lineto
232         stroke
233 } bind def
234
235 /draw_dashed_slur % dash thickness controls
236 {
237         1 setlinecap
238         1 setlinejoin
239         setdash
240         setlinewidth
241         8 -2 roll
242         moveto
243         curveto
244         stroke
245 } bind def
246
247 /print_glyphs {
248         {
249                 currentpoint
250                 3 2 roll
251                 glyphshow
252                 moveto
253                 rmoveto
254         }repeat
255 }bind def
256 %end music-drawing-routines.ps