]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[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
14 % llx lly urx ury URI
15 /mark_URI
16 {
17     /uri exch def
18     /ury exch def
19     /urx exch def
20     /lly exch def
21     /llx exch def
22     [
23         /Rect [ llx lly urx ury ]
24         
25         /Border [ 0 0 0 ]
26
27         /Action
28             <<
29                 /Subtype /URI
30                 /URI uri
31             >>
32         /Subtype /Link
33     /ANN
34     pdfmark
35 }
36 bind def
37
38 % from adobe tech note 5002. 
39 /BeginEPSF { %def
40     /b4_Inc_state save def % Save state for cleanup
41     /dict_count countdictstack def % Count objects on dict stack
42     /op_count count 1 sub def % Count objects on operand stack
43     userdict begin % Push userdict on dict stack
44     /showpage { } def % Redefine showpage, { } = null proc
45     0 setgray 0 setlinecap % Prepare graphics state
46     1 setlinewidth 0 setlinejoin
47     10 setmiterlimit [ ] 0 setdash newpath
48     /languagelevel where % If level not equal to 1 then
49     {pop languagelevel % set strokeadjust and
50     1 ne % overprint to their defaults.
51       {false setstrokeadjust false setoverprint
52       } if
53     } if
54 } bind def
55
56 /EndEPSF { %def
57   count op_count sub {pop} repeat % Clean up stacks
58   countdictstack dict_count sub {end} repeat
59   b4_Inc_state restore
60 } bind def 
61
62
63 %<font> <encoding> <name> reencode-font
64 /reencode-font
65 {
66     /name exch def
67     /encoding exch def
68     dup length
69     dict begin {
70         1 index /FID ne {def} {pop
71         pop} ifelse
72     }
73     forall
74     /Encoding encoding
75     def currentdict
76     end
77     name exch definefont
78 } bind def
79
80
81
82 /set_tex_dimen
83 {
84         cvr def
85 } bind def
86
87
88 /stroke_and_fill {
89         gsave
90                 stroke
91         grestore
92         fill
93 } bind def
94
95 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
96         exch
97         4 1 roll
98         add
99         3 1 roll
100         add
101         exch
102 } bind def
103
104 /draw_round_box % width height x y blot
105 {
106         setlinewidth % w h x y
107         0 setlinecap
108         1 setlinejoin
109
110         rmoveto % w h
111         currentpoint % w h x1 y1
112         4 2 roll % x1 y1 w h
113         4 copy
114         rectfill
115         rectstroke
116 } bind def
117
118 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
119 {
120         setlinewidth %set to blot
121
122         0 setlinecap
123         1 setlinejoin
124
125         3 1 roll
126         /polygon_x
127         currentpoint
128         /polygon_y exch def
129         def
130         rmoveto % x(0) y(0)
131         { polygon_x polygon_y vector_add lineto } repeat % n times
132         closepath 
133         { %fill?
134                 stroke_and_fill
135         }{
136                 stroke
137         } ifelse
138 } bind def
139
140 /draw_repeat_slash % x-width width height draw_repeat_slash
141 {
142         2 index % duplicate x-width
143         1 setlinecap
144         1 setlinejoin
145         
146           0  rlineto % x-width 0
147              rlineto % width height
148         neg 0 rlineto % -x-width 0
149         closepath fill
150 } bind def
151
152 % this is for drawing slurs.
153 /draw_bezier_sandwich  % thickness controls
154 {
155         gsave
156         currentpoint translate
157     % round ending and round beginning
158     1 setlinejoin 1 setlinecap
159         setlinewidth
160         moveto
161         curveto
162         lineto
163         curveto
164         closepath
165         stroke_and_fill
166         grestore
167 } bind def
168
169 /draw_dot % radius x y draw_dot
170 {
171         rmoveto
172         currentpoint
173         3 2 roll
174         0 360 arc closepath stroke_and_fill
175 } bind def
176
177 /draw_circle % filled? radius thickness draw_circle
178 {
179         setlinewidth    % f? r
180         currentpoint    % f? r x0 y0
181         3 2 roll        % f? x0 y0 r
182         dup 0 rmoveto
183         0 360 arc closepath
184                 { stroke_and_fill } 
185                 { stroke }
186         ifelse
187 } bind def
188
189
190 /draw_line % dx dy x1 y1 thickness draw_line
191 {
192         setlinewidth % dx dy x1 y1
193         1 setlinecap
194         1 setlinejoin
195         rmoveto % dx dy
196         rlineto
197         stroke
198 } bind def
199
200 /draw_dashed_line % dx dy thickness dashpattern draw_dashed_line
201 {
202         1 setlinecap
203         1 setlinejoin
204         setdash % dx dy thickness
205         setlinewidth %dx dy
206         rlineto
207         stroke
208         [] 0 setdash % reset dash pattern
209 } bind def
210
211 /draw_dashed_slur % controls thickness dash
212 {
213 gsave
214         currentpoint translate
215         1 setlinecap
216         1 setlinejoin
217         setdash
218         setlinewidth
219         8 2 roll
220         moveto
221         curveto
222         stroke
223 grestore
224 } bind def
225
226 /print_glyphs % dx dy glyph print_glyphs
227 {
228         {
229                 currentpoint %dx dy glyph x0 y0
230                 3 2 roll %dx dy x0 y0 glyph
231                 glyphshow % dx dy x0 y0
232                 moveto % dx dy
233                 rmoveto
234         }repeat
235 }bind def
236 %end music-drawing-routines.ps