]> git.donarmstrong.com Git - lilypond.git/blob - ps/lilyponddefs.ps
Do header and footer.
[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 } bind def
86
87 /stop-page
88 {
89     showpage
90 } bind def
91
92 % dump using baselineskip, fold to new page
93 /start-system % height
94 {
95         dup base-line-skip gt {
96                 /line-height exch def
97         }
98         {
99                 pop /line-height base-line-skip def
100         } ifelse
101         line-y top-margin sub base-line-skip lt {
102                 showpage
103                 /line-y vsize top-margin sub def
104         } if
105         gsave
106         line-x line-y translate
107 } bind def
108
109 /stop-system
110
111         /the-line exch def
112         the-line
113         stroke
114         grestore
115         line-y line-height output-scale mul sub /line-y exch def
116 } bind def
117
118 % FIXME: font definitions should come from LilyPond
119 %        built-in ps fonts are ugly
120 /huge-bold-font {
121         /Palatino-Bold findfont 20.7 scalefont setfont
122 } bind def
123
124 /Large-bold-font {
125         /Palatino-Bold findfont 17.3 scalefont setfont
126 } bind def
127
128 /large-bold-font {
129         /Palatino-Bold findfont 14.4 scalefont setfont
130 } bind def
131
132 /large-font {
133         /Palatino-Roman findfont 14.4 scalefont setfont
134 } bind def
135
136 /large-smallcaps-font {
137         % urg
138         /Bookman-Light findfont 14.4 scalefont setfont
139 } bind def
140
141 /normal-font {
142         /Palatino-Roman findfont 12 scalefont setfont
143 } bind def
144
145 /footnote-font {
146         /Palatino-Roman findfont 10 scalefont setfont
147 } bind def
148
149 /get-text-dimensions % path .. width height
150 {
151         dup true charpath pathbbox
152         newpath
153         line-x line-y moveto
154         exch 4 -1 roll
155         sub
156         3 1 roll
157         exch sub
158 } bind def
159
160 /set-centered
161 {
162         line-x line-y moveto
163         get-text-dimensions
164         neg line-y add /line-y exch def
165         neg line-width add 2 div 0 rmoveto
166         show
167 } bind def
168
169 /set-left
170 {
171         line-x line-y moveto
172         get-text-dimensions
173         neg line-y add /line-y exch def
174         pop
175         show
176 } bind def
177
178 /set-right
179 {
180         line-x line-y moveto
181         get-text-dimensions
182         neg line-y add /line-y exch def
183         neg line-width add 0 rmoveto
184         show
185 } bind def
186
187 /make-lilypond-title
188 {
189         currentdict /lilyponddedication known {
190                 normal-font lilyponddedication set-centered
191                 line-y 10 sub /line-y exch def
192         } if
193         currentdict /lilypondtitle known {
194                 huge-bold-font lilypondtitle set-centered
195                 line-y 5 sub /line-y exch def
196         } if
197         currentdict /lilypondsubtitle known {
198                 Large-bold-font lilypondsubtitle set-centered
199                 line-y 5 sub /line-y exch def
200         } if
201         currentdict /lilypondsubsubtitle known {
202                 large-bold-font lilypondsubsubtitle set-centered
203         } if
204         line-y /mini-page exch def
205         currentdict /lilypondcomposer known {
206                 large-smallcaps-font lilypondcomposer set-right
207                 line-y 2 sub /line-y exch def
208         } if
209         currentdict /lilypondopus known {
210                 normal-font lilypondopus set-right
211                 line-y 3 sub /line-y exch def
212         } if
213         currentdict /lilypondarranger known {
214                 normal-font lilypondarranger set-right
215                 line-y 3 sub /line-y exch def
216         } if
217         currentdict /lilypondpoet known {
218                 mini-page /line-y exch def
219                 normal-font lilypondpoet set-left
220                 line-y 3 sub /line-y exch def
221         } if
222         currentdict /lilypondtexttranslator known {
223                 normal-font lilypondtexttranslator set-left
224                 line-y 3 sub /line-y exch def
225         } if
226         currentdict /lilypondinstrument known {
227                 large-font lilypondinstrument set-centered
228         } if
229         currentdict /lilypondpiece known {
230                 large-smallcaps-font lilypondpiece set-left
231         } if
232 } bind def
233
234 /end-lilypond-output
235 {
236         /line-y top-margin def
237         footnote-font lilypondtagline set-left
238         showpage
239 } bind def
240
241 /turnOnExperimentalFeatures { } bind def
242
243 staff-line-thickness setlinewidth
244
245 % set postscript paper size
246 paper-size
247
248 % initialise paper dimensions
249 staff-height init-paper
250
251 % end lilyponddefs.ps