]> git.donarmstrong.com Git - lilypond.git/blob - ps/music-drawing-routines.ps
Fixed errors in Catalan translation
[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 % 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     /languagelevel where % If level not equal to 1 then
67     {pop languagelevel % set strokeadjust and
68     1 ne % overprint to their defaults.
69       {false setstrokeadjust false setoverprint
70       } if
71     } if
72 } bind def
73
74 /EndEPSF { %def
75   count op_count sub {pop} repeat % Clean up stacks
76   countdictstack dict_count sub {end} repeat
77   b4_Inc_state restore
78 } bind def
79
80 /stroke_and_fill {
81         gsave
82                 stroke
83         grestore
84         fill
85 } bind def
86
87 /vector_add { % x1 y1 x2 y2 vector_add x1+x2 y1+y2
88         exch
89         4 1 roll
90         add
91         3 1 roll
92         add
93         exch
94 } bind def
95
96 /draw_round_box % width height x y blot
97 {
98         dup
99         0.0 gt {
100                 setlinewidth % w h x y
101                 rmoveto % w h
102                 2 copy 0 ne exch 0 ne and
103                 {
104                     0 setlinecap
105                     1 setlinejoin
106                     currentpoint % w h x1 y1
107                     4 2 roll % x1 y1 w h
108                     4 copy
109                     rectfill
110                     rectstroke
111                 } {
112                     1 setlinecap
113                     rlineto stroke
114                 } ifelse
115         } {
116                 pop % w h x y
117                 rmoveto % w h
118                 currentpoint % w h x1 y1
119                 4 2 roll % x1 y1 w h
120                 rectfill
121         } ifelse
122 } bind def
123
124 /draw_polygon % fill? x(n) y(n) x(n-1) y(n-1) ... x(0) y(0) n blot
125 {
126         setlinewidth %set to blot
127
128         0 setlinecap
129         1 setlinejoin
130
131         3 1 roll
132         /polygon_x
133         currentpoint
134         /polygon_y exch def
135         def
136         rmoveto % x(0) y(0)
137         { polygon_x polygon_y vector_add lineto } repeat % n times
138         closepath
139         { %fill?
140                 stroke_and_fill
141         }{
142                 stroke
143         } ifelse
144 } bind def
145
146 /draw_circle % filled? radius thickness draw_circle
147 {
148         setlinewidth    % f? r
149         currentpoint    % f? r x0 y0
150         3 2 roll        % f? x0 y0 r
151         dup 0 rmoveto
152         0 360 arc closepath
153                 { stroke_and_fill }
154                 { stroke }
155         ifelse
156 } bind def
157
158 /draw_ellipse % filled? x-radius y-radius thickness draw_ellipse
159 {
160   setlinewidth % f? x-r y-r
161   /savematrix matrix currentmatrix def
162   scale % f?
163   currentpoint
164   1 0 rmoveto
165   1 0 360  arc closepath
166   savematrix setmatrix
167              { stroke_and_fill}
168              { stroke }
169   ifelse
170 } bind def
171
172 /draw_partial_ellipse % filled connect x-radius y-radius startangle endangle thickness draw_partial_ellipse
173 % Note that filled is not boolean to permit for different graylevels (ie for trill keys)
174 {
175   gsave
176   currentpoint translate
177   /thickness exch def
178   /endangle exch def
179   /startangle exch def
180   /y_radius exch def
181   /x_radius exch def
182   /endrad x_radius y_radius mul
183     x_radius x_radius mul
184     endangle cos endangle cos mul mul
185     y_radius y_radius mul
186     endangle sin endangle sin mul mul add sqrt div def
187   /endangle endangle sin endrad mul y_radius div
188     endangle cos endrad mul x_radius div atan def
189   /startrad x_radius y_radius mul
190     x_radius x_radius mul
191       startangle cos startangle cos mul mul
192     y_radius y_radius mul
193       startangle sin startangle sin mul mul add sqrt div def
194   /startangle startangle sin startrad mul y_radius div
195     startangle cos startrad mul x_radius div atan def
196   /connect exch def
197   /filled exch def
198   /savematrix matrix currentmatrix def
199   thickness setlinewidth
200   x_radius y_radius scale
201   startangle cos startangle sin moveto
202   0 0 1 startangle
203     startangle endangle eq { endangle 360 add } { endangle } ifelse
204     arc
205   connect {
206     startangle cos startangle sin moveto endangle cos endangle sin lineto }
207     if
208   savematrix setmatrix filled { stroke_and_fill } { stroke } ifelse
209   grestore
210 } bind def
211
212 /draw_line % dx dy x1 y1 thickness draw_line
213 {
214         setlinewidth % dx dy x1 y1
215         1 setlinecap
216         1 setlinejoin
217         rmoveto % dx dy
218         rlineto
219         stroke
220 } bind def
221
222 /draw_dashed_line % dx dy thickness dashpattern offset draw_dashed_line
223 {
224         1 setlinecap
225         1 setlinejoin
226         setdash % dx dy thickness
227         setlinewidth %dx dy
228         rlineto
229         stroke
230         [] 0 setdash % reset dash pattern
231 } bind def
232
233 /print_glyphs % w dx dy glyph print_glyphs
234 {
235         {
236                 currentpoint %w dx dy glyph x0 y0
237                 5 2 roll %w x0 y0 dx dy glyph
238                 3 1 roll %w x0 y0 glyph dx dy
239                 rmoveto %w x0 y0 glyph
240                 glyphshow %w x0 y0
241                 moveto %w
242                 0 rmoveto
243         }repeat
244 }bind def
245 %end music-drawing-routines.ps