]> git.donarmstrong.com Git - lilypond.git/blob - ps/lilyponddefs.ps
37cfbf2dd659d1a9fdc79f89cde49f8929628e5a
[lilypond.git] / ps / lilyponddefs.ps
1 %!PS-Adobe-2.0: lilyponddefs.ps
2 %
3 % Functions for direct PostScript output
4
5 % /setgray { 1 add } bind def
6
7 % To let gs load fonts from builddir, do:
8 % export GS_LIB=$(pwd)/mf/out:/usr/share/texmf/fonts/type1/bluesky/cm
9
10 /staff-line-thickness lilypondpaperlinethickness def
11 /staff-height lilypondpaperstaffheight def
12 /line-width lilypondpaperlinewidth def
13
14 % FIXME: why isn't this set (by default) by lily?
15 % /text-height lilypondpapertextheight def
16
17 /lily-output-units 2.83464  def  %% milimeter
18 % /lily-output-units 0.996264  def  %% true points.
19
20 /output-scale lilypondpaperoutputscale lily-output-units mul def
21
22 /set-ps-scale-to-lily-scale { output-scale output-scale scale } bind def
23
24 /paper-size { lilypondpaperpapersize } bind def
25
26 %% FIXME: base-line-skip is too big, is this RIGHT?
27 %% /line-height 14 staff-space mul def
28 %% /base-line-skip lilypondpaperlineheight def
29 %%/base-line-skip lilypondpaperlineheight lilypondpaperoutputscale div def
30 /base-line-skip 0 def
31
32 /init-paper {
33         gsave
34         .1 setlinewidth
35         clippath pathbbox newpath
36         /vsize exch def
37         /hsize exch def pop pop pop pop
38         % FIXME
39         /top-margin 2 def
40         hsize line-width sub 2 div /left-margin exch def
41         grestore
42 } bind def
43
44 /place-box
45 {
46         /object exch def
47         gsave
48         %exch translate
49         translate
50         0 0 moveto
51         object
52         grestore
53 } bind def
54
55 %% http://bibliofile.mc.duke.edu/gww/fonts/postscript-utilities/encoding-vectors.html
56
57 %/FONTLENGTH 256 bind def
58
59 %<font> <encoding> <name> reencode-font
60 /reencode-dict 5 dict def
61 /reencode-font
62 {
63     reencode-dict
64     begin
65     /name exch def
66     /encoding exch def
67     /base-font exch def
68     % note: Needs ps level 2
69     /font base-font maxlength dict def
70     base-font {
71         exch dup dup /FID ne exch /Encoding ne and
72         { exch font 3 1 roll put }
73         { pop pop } ifelse
74     } forall
75     font /FontName name put
76     font /Encoding encoding put
77     name font definefont pop
78     end
79 } bind def
80
81 /start-page
82 {
83     %/line-x left-margin output-scale div def
84     %/line-y vsize top-margin sub def
85     /line-x 0 def
86     /line-y vsize def
87 } bind def
88
89 /stop-page
90 {
91     showpage
92 } bind def
93
94 % dump using baselineskip, fold to new page
95 /start-system % height
96 {
97         dup base-line-skip gt {
98                 /line-height exch def
99         }
100         {
101                 pop /line-height base-line-skip def
102         } ifelse
103         line-y top-margin sub base-line-skip lt {
104                 showpage
105                 /line-y vsize top-margin sub def
106         } if
107         gsave
108         line-x line-y translate
109 } bind def
110
111 /stop-system
112
113         /the-line exch def
114         the-line
115         stroke
116         grestore
117         line-y line-height output-scale mul sub /line-y exch def
118 } bind def
119
120 % FIXME: font definitions should come from LilyPond
121 %        built-in ps fonts are ugly
122 /huge-bold-font {
123         /Palatino-Bold findfont 20.7 scalefont setfont
124 } bind def
125
126 /Large-bold-font {
127         /Palatino-Bold findfont 17.3 scalefont setfont
128 } bind def
129
130 /large-bold-font {
131         /Palatino-Bold findfont 14.4 scalefont setfont
132 } bind def
133
134 /large-font {
135         /Palatino-Roman findfont 14.4 scalefont setfont
136 } bind def
137
138 /large-smallcaps-font {
139         % urg
140         /Bookman-Light findfont 14.4 scalefont setfont
141 } bind def
142
143 /normal-font {
144         /Palatino-Roman findfont 12 scalefont setfont
145 } bind def
146
147 /footnote-font {
148         /Palatino-Roman findfont 10 scalefont setfont
149 } bind def
150
151 /get-text-dimensions % path .. width height
152 {
153         dup true charpath pathbbox
154         newpath
155         line-x line-y moveto
156         exch 4 -1 roll
157         sub
158         3 1 roll
159         exch sub
160 } bind def
161
162 /set-centered
163 {
164         line-x line-y moveto
165         get-text-dimensions
166         neg line-y add /line-y exch def
167         neg line-width add 2 div 0 rmoveto
168         show
169 } bind def
170
171 /set-left
172 {
173         line-x line-y moveto
174         get-text-dimensions
175         neg line-y add /line-y exch def
176         pop
177         show
178 } bind def
179
180 /set-right
181 {
182         line-x line-y moveto
183         get-text-dimensions
184         neg line-y add /line-y exch def
185         neg line-width add 0 rmoveto
186         show
187 } bind def
188
189 /make-lilypond-title
190 {
191         currentdict /lilyponddedication known {
192                 normal-font lilyponddedication set-centered
193                 line-y 10 sub /line-y exch def
194         } if
195         currentdict /lilypondtitle known {
196                 huge-bold-font lilypondtitle set-centered
197                 line-y 5 sub /line-y exch def
198         } if
199         currentdict /lilypondsubtitle known {
200                 Large-bold-font lilypondsubtitle set-centered
201                 line-y 5 sub /line-y exch def
202         } if
203         currentdict /lilypondsubsubtitle known {
204                 large-bold-font lilypondsubsubtitle set-centered
205         } if
206         line-y /mini-page exch def
207         currentdict /lilypondcomposer known {
208                 large-smallcaps-font lilypondcomposer set-right
209                 line-y 2 sub /line-y exch def
210         } if
211         currentdict /lilypondopus known {
212                 normal-font lilypondopus set-right
213                 line-y 3 sub /line-y exch def
214         } if
215         currentdict /lilypondarranger known {
216                 normal-font lilypondarranger set-right
217                 line-y 3 sub /line-y exch def
218         } if
219         currentdict /lilypondpoet known {
220                 mini-page /line-y exch def
221                 normal-font lilypondpoet set-left
222                 line-y 3 sub /line-y exch def
223         } if
224         currentdict /lilypondtexttranslator known {
225                 normal-font lilypondtexttranslator set-left
226                 line-y 3 sub /line-y exch def
227         } if
228         currentdict /lilypondinstrument known {
229                 large-font lilypondinstrument set-centered
230         } if
231         currentdict /lilypondpiece known {
232                 large-smallcaps-font lilypondpiece set-left
233         } if
234 } bind def
235
236 /end-lilypond-output
237 {
238         /line-y top-margin def
239         footnote-font lilypondtagline set-left
240         showpage
241 } bind def
242
243 /turnOnExperimentalFeatures { } bind def
244
245 staff-line-thickness setlinewidth
246
247 % set postscript paper size
248 paper-size
249
250 % initialise paper dimensions
251 staff-height init-paper
252
253 %/line-x left-margin output-scale div def
254 %/line-y vsize top-margin sub def
255 /line-x 0 def
256 /line-y vsize def
257
258 % end lilyponddefs.ps