]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
* ps/music-drawing-routines.ps (draw_dashed_line): fix dash pattern bug.
[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 {
132         setlinewidth % w h x y
133         0 setlinecap
134         1 setlinejoin
135
136         rmoveto % w h
137         currentpoint % w h x1 y1
138         4 2 roll % x1 y1 w h
139         4 copy
140         rectfill
141         rectstroke
142 } bind def
143
144 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
145 {
146         setlinewidth %set to blot
147
148         0 setlinecap
149         1 setlinejoin
150
151         3 1 roll
152         /polygon_x
153         currentpoint
154         /polygon_y exch def
155         def
156         rmoveto % x(0) y(0)
157         { polygon_x polygon_y vector_add lineto } repeat % n times
158         closepath 
159         { %fill?
160                 stroke_and_fill
161         }{
162                 stroke
163         } ifelse
164 } bind def
165
166 /draw_repeat_slash % x-width width height draw_repeat_slash
167 {
168         2 index % duplicate x-width
169         1 setlinecap
170         1 setlinejoin
171         
172           0  rlineto % x-width 0
173              rlineto % width height
174         neg 0 rlineto % -x-width 0
175         closepath fill
176 } bind def
177
178 % this is for drawing slurs.
179 /draw_bezier_sandwich  % thickness controls
180 {
181         gsave
182         currentpoint translate
183     % round ending and round beginning
184     1 setlinejoin 1 setlinecap
185         setlinewidth
186         moveto
187         curveto
188         lineto
189         curveto
190         closepath
191         stroke_and_fill
192         grestore
193 } bind def
194
195 /draw_dot % radius x y draw_dot
196 {
197         rmoveto
198         currentpoint
199         3 2 roll
200         0 360 arc closepath stroke_and_fill
201 } bind def
202
203 /draw_circle % filled? radius thickness draw_circle
204 {
205         setlinewidth    % f? r
206         currentpoint    % f? r x0 y0
207         3 2 roll        % f? x0 y0 r
208         dup 0 rmoveto
209         0 360 arc closepath
210                 { stroke_and_fill } 
211                 { stroke }
212         ifelse
213 } bind def
214
215
216 /draw_line % dx dy x1 y1 thickness draw_line
217 {
218         setlinewidth % dx dy x1 y1
219         1 setlinecap
220         1 setlinejoin
221         rmoveto % dx dy
222         rlineto
223         stroke
224 } bind def
225
226 /draw_dashed_line % dx dy thickness dashpattern draw_dashed_line
227 {
228         1 setlinecap
229         1 setlinejoin
230         setdash % dx dy thickness
231         setlinewidth %dx dy
232         rlineto
233         stroke
234         [] 0 setdash % reset dash pattern
235 } bind def
236
237 /draw_dashed_slur % controls thickness dash
238 {
239 gsave
240         currentpoint translate
241         1 setlinecap
242         1 setlinejoin
243         setdash
244         setlinewidth
245         moveto
246         curveto
247         stroke
248 grestore
249 } bind def
250
251 /print_glyphs % dx dy glyph print_glyphs
252 {
253         {
254                 currentpoint %dx dy glyph x0 y0
255                 3 2 roll %dx dy x0 y0 glyph
256                 glyphshow % dx dy x0 y0
257                 moveto % dx dy
258                 rmoveto
259         }repeat
260 }bind def
261 %end music-drawing-routines.ps