]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
Don't meddle with Ghostscript's choice of currentstrokeadjust
[lilypond.git] / ps / music-drawing-routines.ps
1 %!PS-Adobe-2.0
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 % llx lly urx ury page
39 /mark_page_link
40 {
41     /page exch def
42     /ury exch def
43     /urx exch def
44     /lly exch def
45     /llx exch def
46     [
47         /Rect [ llx lly urx ury ]
48         /Border [ 0 0 0 ]
49         /Page page
50         /Subtype /Link
51     /ANN
52     pdfmark
53 }
54 bind def
55
56 % from adobe tech note 5002.
57 /BeginEPSF { %def
58     /b4_Inc_state save def % Save state for cleanup
59     /dict_count countdictstack def % Count objects on dict stack
60     /op_count count 1 sub def % Count objects on operand stack
61     userdict begin % Push userdict on dict stack
62     /showpage { } def % Redefine showpage, { } = null proc
63     0 setgray 0 setlinecap % Prepare graphics state
64     1 setlinewidth 0 setlinejoin
65     10 setmiterlimit [ ] 0 setdash newpath
66     false setoverprint
67 } bind def
68
69 /EndEPSF { %def
70   count op_count sub {pop} repeat % Clean up stacks
71   countdictstack dict_count sub {end} repeat
72   b4_Inc_state restore
73 } bind def
74
75 /stroke_and_fill? {
76     {
77         gsave
78                 stroke
79         grestore
80         fill
81     }
82     {
83         stroke
84     }
85     ifelse
86 } bind def
87
88 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
89         exch
90         4 1 roll
91         add
92         3 1 roll
93         add
94         exch
95 } bind def
96
97 /draw_round_box % width height x y blot
98 {
99         dup
100         0.0 gt {
101                 setlinewidth % w h x y
102                 rmoveto % w h
103                 2 copy 0 ne exch 0 ne and
104                 {
105                     0 setlinecap
106                     1 setlinejoin
107                     currentpoint % w h x1 y1
108                     4 2 roll % x1 y1 w h
109                     4 copy
110                     rectfill
111                     rectstroke
112                 } {
113                     1 setlinecap
114                     rlineto stroke
115                 } ifelse
116         } {
117                 pop % w h x y
118                 rmoveto % w h
119                 currentpoint % w h x1 y1
120                 4 2 roll % x1 y1 w h
121                 rectfill
122         } ifelse
123 } bind def
124
125 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
126 {
127         setlinewidth %set to blot
128
129         0 setlinecap
130         1 setlinejoin
131
132         3 1 roll
133         /polygon_x
134         currentpoint
135         /polygon_y exch def
136         def
137         rmoveto % x(0) y(0)
138         { polygon_x polygon_y vector_add lineto } repeat % n times
139         closepath
140         stroke_and_fill?
141 } bind def
142
143 /draw_circle % filled? radius thickness draw_circle
144 {
145         setlinewidth    % f? r
146         currentpoint    % f? r x0 y0
147         3 2 roll        % f? x0 y0 r
148         dup 0 rmoveto
149         0 360 arc closepath
150         stroke_and_fill?
151 } bind def
152
153 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
154 {
155   setlinewidth % f? x-r y-r
156   /savematrix matrix currentmatrix def
157   scale % f?
158   currentpoint
159   1 0 rmoveto
160   1 0 360  arc closepath
161   savematrix setmatrix
162   stroke_and_fill?
163 } bind def
164
165 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
166 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
167 {
168   gsave
169   currentpoint translate
170   /thickness exch def
171   /endangle exch def
172   /startangle exch def
173   /y_radius exch def
174   /x_radius exch def
175   /endrad x_radius y_radius mul
176     x_radius x_radius mul
177     endangle cos endangle cos mul mul
178     y_radius y_radius mul
179     endangle sin endangle sin mul mul add sqrt div def
180   /endangle endangle sin endrad mul y_radius div
181     endangle cos endrad mul x_radius div atan def
182   /startrad x_radius y_radius mul
183     x_radius x_radius mul
184       startangle cos startangle cos mul mul
185     y_radius y_radius mul
186       startangle sin startangle sin mul mul add sqrt div def
187   /startangle startangle sin startrad mul y_radius div
188     startangle cos startrad mul x_radius div atan def
189   /connect exch def
190   /filled exch def
191   /savematrix matrix currentmatrix def
192   thickness setlinewidth
193   x_radius y_radius scale
194   startangle cos startangle sin moveto
195   0 0 1 startangle
196     startangle endangle eq { endangle 360 add } { endangle } ifelse
197     arc
198   connect {
199     startangle cos startangle sin moveto endangle cos endangle sin lineto }
200     if
201   savematrix setmatrix filled stroke_and_fill?
202   grestore
203 } bind def
204
205 /draw_line % dx dy x1 y1 thickness draw_line
206 {
207         setlinewidth % dx dy x1 y1
208         1 setlinecap
209         1 setlinejoin
210         rmoveto % dx dy
211         rlineto
212         stroke
213 } bind def
214
215 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
216 {
217         1 setlinecap
218         1 setlinejoin
219         setdash % dx dy thickness
220         setlinewidth %dx dy
221         rlineto
222         stroke
223         [] 0 setdash % reset dash pattern
224 } bind def
225
226 /print_glyphs % w dx dy glyph print_glyphs
227 {
228         {
229                 currentpoint %w dx dy glyph x0 y0
230                 5 2 roll %w x0 y0 dx dy glyph
231                 3 1 roll %w x0 y0 glyph dx dy
232                 rmoveto %w x0 y0 glyph
233                 glyphshow %w x0 y0
234                 moveto %w
235                 0 rmoveto
236         }repeat
237 }bind def
238 %end music-drawing-routines.ps