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