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