]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
Merge master into nested-bookparts
[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 /set_tex_dimen
63 {
64         cvr def
65 } bind def
66
67 /stroke_and_fill {
68         gsave
69                 stroke
70         grestore
71         fill
72 } bind def
73
74 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
75         exch
76         4 1 roll
77         add
78         3 1 roll
79         add
80         exch
81 } bind def
82
83 /draw_round_box % width height x y blot
84 {
85         setlinewidth % w h x y
86         0 setlinecap
87         1 setlinejoin
88
89         rmoveto % w h
90         currentpoint % w h x1 y1
91         4 2 roll % x1 y1 w h
92         4 copy
93         rectfill
94         rectstroke
95 } bind def
96
97 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
98 {
99         setlinewidth %set to blot
100
101         0 setlinecap
102         1 setlinejoin
103
104         3 1 roll
105         /polygon_x
106         currentpoint
107         /polygon_y exch def
108         def
109         rmoveto % x(0) y(0)
110         { polygon_x polygon_y vector_add lineto } repeat % n times
111         closepath 
112         { %fill?
113                 stroke_and_fill
114         }{
115                 stroke
116         } ifelse
117 } bind def
118
119 /draw_repeat_slash % x-width width height draw_repeat_slash
120 {
121         2 index % duplicate x-width
122         1 setlinecap
123         1 setlinejoin
124         
125           0  rlineto % x-width 0
126              rlineto % width height
127         neg 0 rlineto % -x-width 0
128         closepath fill
129 } bind def
130
131 % this is for drawing slurs and barre-indicators.
132 /draw_bezier_sandwich  % thickness controls
133 {
134         gsave
135         currentpoint translate
136     % round ending and round beginning
137     1 setlinejoin 1 setlinecap
138         setlinewidth
139         moveto
140         curveto
141         lineto
142         curveto
143         closepath
144         stroke_and_fill
145         grestore
146 } bind def
147
148 /draw_dot % radius x y draw_dot
149 {
150         rmoveto
151         currentpoint
152         3 2 roll
153         0 360 arc closepath stroke_and_fill
154 } bind def
155
156 /draw_circle % filled? radius thickness draw_circle
157 {
158         setlinewidth    % f? r
159         currentpoint    % f? r x0 y0
160         3 2 roll        % f? x0 y0 r
161         dup 0 rmoveto
162         0 360 arc closepath
163                 { stroke_and_fill } 
164                 { stroke }
165         ifelse
166 } bind def
167
168 /draw_oval % filled? x-radius y-radius thickness draw_ellipse
169 {
170   setlinewidth % f? x-r y-r
171   /yrad exch def
172   /xrad exch def
173   xrad 0 rmoveto
174   0 yrad -2 xrad mul dup yrad exch 0 rcurveto
175   0 yrad neg dup 2 xrad mul dup 3 1 roll 0 rcurveto
176   closepath
177       { stroke_and_fill}
178       { stroke }
179   ifelse
180 } bind def
181
182 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
183 {
184   setlinewidth % f? x-r y-r
185   /savematrix matrix currentmatrix def
186   scale % f?
187   currentpoint
188   1 0 rmoveto
189   1 0 360  arc closepath
190   savematrix setmatrix
191              { stroke_and_fill}
192              { stroke }
193   ifelse
194 } bind def
195
196 /draw_line % dx dy x1 y1 thickness draw_line
197 {
198         setlinewidth % dx dy x1 y1
199         1 setlinecap
200         1 setlinejoin
201         rmoveto % dx dy
202         rlineto
203         stroke
204 } bind def
205
206 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
207 {
208         1 setlinecap
209         1 setlinejoin
210         setdash % dx dy thickness
211         setlinewidth %dx dy
212         rlineto
213         stroke
214         [] 0 setdash % reset dash pattern
215 } bind def
216
217 /draw_dashed_slur % controls thickness dash
218 {
219 gsave
220         currentpoint translate
221         1 setlinecap
222         1 setlinejoin
223         setdash
224         setlinewidth
225         8 2 roll
226         moveto
227         curveto
228         stroke
229 grestore
230 } bind def
231
232 /print_glyphs % dx dy glyph print_glyphs
233 {
234         {
235                 currentpoint %dx dy glyph x0 y0
236                 3 2 roll %dx dy x0 y0 glyph
237                 glyphshow % dx dy x0 y0
238                 moveto % dx dy
239                 rmoveto
240         }repeat
241 }bind def
242 %end music-drawing-routines.ps