]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
aa8cfa6527d4396669062d47b59efd31ae6024c5
[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_ellipse % filled? x-radius y-radius thickness draw_ellipse
169 {
170   setlinewidth % f? x-r y-r
171   /savematrix matrix currentmatrix def
172   scale % f?
173   currentpoint
174   1 0 rmoveto
175   1 0 360  arc closepath
176   savematrix setmatrix
177              { stroke_and_fill}
178              { stroke }
179   ifelse
180 } bind def
181
182 /draw_line % dx dy x1 y1 thickness draw_line
183 {
184         setlinewidth % dx dy x1 y1
185         1 setlinecap
186         1 setlinejoin
187         rmoveto % dx dy
188         rlineto
189         stroke
190 } bind def
191
192 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
193 {
194         1 setlinecap
195         1 setlinejoin
196         setdash % dx dy thickness
197         setlinewidth %dx dy
198         rlineto
199         stroke
200         [] 0 setdash % reset dash pattern
201 } bind def
202
203 /draw_dashed_slur % controls thickness dash
204 {
205 gsave
206         currentpoint translate
207         1 setlinecap
208         1 setlinejoin
209         setdash
210         setlinewidth
211         8 2 roll
212         moveto
213         curveto
214         stroke
215 grestore
216 } bind def
217
218 /print_glyphs % dx dy glyph print_glyphs
219 {
220         {
221                 currentpoint %dx dy glyph x0 y0
222                 3 2 roll %dx dy x0 y0 glyph
223                 glyphshow % dx dy x0 y0
224                 moveto % dx dy
225                 rmoveto
226         }repeat
227 }bind def
228 %end music-drawing-routines.ps