]> git.donarmstrong.com Git - lilypond.git/blob - mf/feta-params.mf
Add '-dcrop' option to ps and svg backends
[lilypond.git] / mf / feta-params.mf
1 % Feta (not the Font-En-Tja) music font -- global parameters for both feta and parmesan fonts
2 % This file is part of LilyPond, the GNU music typesetter.
3 %
4 % Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 %
6 % The LilyPond font is free software: you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation, either version 3 of the License, or
9 % (at your option) any later version, or under the SIL Open Font License.
10 %
11 % LilyPond is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 % GNU General Public License for more details.
15 %
16 % You should have received a copy of the GNU General Public License
17 % along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 stafflines := 5;
20
21 %
22 % The design size of a staff should really be the
23 % staff_space, but we use staffsize for historical reasons.
24 %
25
26 staff_space# := staffsize# / (stafflines - 1);
27 staff_space_rounded# := staff_space#;
28
29
30 %
31 % Measuring on pocket scores turns out: stafflinethickness is
32 % largely independent on staff size, and generally about 0.5 pt.
33 %
34 % By request of WL, we tune down the blackness a little
35 % for increased contrast with beams.
36 %
37
38 %% !! synchronize with paper.scm
39
40 save fixed_line_thickness, variable_line_factor;
41 fixed_line_thickness + variable_line_factor * 5 pt# = 0.50 pt#;
42 fixed_line_thickness + variable_line_factor * 4.125 pt# = 0.47 pt#;
43
44 stafflinethickness# := fixed_line_thickness
45                        + variable_line_factor * staff_space#;
46 stafflinethickness_rounded# := stafflinethickness#;
47
48 %
49 % The following tunes the general blackness of the glyphs.
50 %
51
52 linethickness# := stafflinethickness#;          %% 0.5 pt#;
53 linethickness_rounded# := linethickness#;
54
55 %
56 % bigger puff_up_factor, relatively thicker stafflines.
57 %
58 %   20 pt = puff_up_factor 0
59 %   10 pt = puff_up_factor 1
60 %
61
62 puff_up_factor = (linethickness# - 0.1 staff_space#) / (0.1 staff_space#);
63
64
65 stemthickness# := 1.3 stafflinethickness#;
66 stemthickness_rounded# := stemthickness#;
67 ledgerlinethickness# := 2 stafflinethickness#;
68 ledgerlinethickness_rounded# := ledgerlinethickness#;
69
70 define_pixels (staff_space, stemthickness, stafflinethickness,
71                ledgerlinethickness, linethickness);
72 define_whole_pixels (staff_space_rounded);
73 define_whole_blacker_pixels (stemthickness_rounded);
74 define_whole_vertical_blacker_pixels (stafflinethickness_rounded,
75                                       ledgerlinethickness_rounded,
76                                       linethickness_rounded);
77
78 if ledgerlinethickness_rounded > 2 stafflinethickness_rounded:
79         ledgerlinethickness_rounded := 2 stafflinethickness_rounded;
80 fi;
81
82 %
83 % Because of the engraving/stamping process, no traditional
84 % characters have sharp edges and corners.
85 % The following variable controls the amount of `roundness'.
86 %
87 % This is not a meta variable: it is related to absolute sizes.
88 %
89 % FIXME: According to [Wanske], only outside corners should be round
90 %        I don't think we do this anywhere -- jcn
91 %
92
93 blot_diameter# = .40 pt#;
94 if (blot_diameter# * hppp) < 1:
95         blot_diameter# := 1 / hppp;
96 fi
97 if (blot_diameter# * vppp) < 1:
98         blot_diameter# := 1 / vppp;
99 fi
100
101 define_pixels (blot_diameter);
102
103
104 %
105 % symmetry
106 % --------
107 %
108 % Some glyphs have to be positioned exactly between stafflines (clefs,
109 % note heads).  This needs some care at lower resolutions.
110 %
111 % Most glyphs use the staffline thickness and the space between two
112 % staff lines as the fundamental parameters.  The latter is the distance
113 % between the middle of one staff line to the middle of the next.  To
114 % say it differently, the value `staff_space' is the sum of one staff line
115 % thickness and the whitespace between two adjacent staff lines.
116 %
117 % Normally, feta's vertical origin for glyphs is either the middle
118 % between two staff lines or the middle of a staff line.  For example, the
119 % lower edge of the central staff line is at the vertical position
120 % `-<staffline thickness> / 2', and the upper edge at
121 % `<staffline thickness> / 2'.  Here we need a value rounded to an integer
122 % (the feta code uses `stafflinethickness_rounded' for that purpose).
123 %
124 % If we have an odd number of pixels as the staffline thickness, Metafont
125 % rounds `-stafflinethickness_rounded / 2' towards zero and
126 % `stafflinethickness_rounded / 2' towards infinity.  Example: `round -1.5'
127 % yields -1, `round 1.5' yields 2.  The whitespace between staff lines is
128 % handled similarly.  If we assume that stafflinethickness_rounded is odd,
129 % we have the following cases:
130 %
131 % o The glyph is centered between three stafflines or five stafflines
132 %   (clef, `c' meter).  We have this:
133 %
134 %          ___________  a
135 %          ___________  1
136 %          ___________  a
137 %
138 %                            whitespace
139 %
140 %          ___________  a
141 %   ...... ___________  1 ..................  x axis
142 %          ___________  a
143 %
144 %                            whitespace
145 %
146 %          ___________  a
147 %          ___________  1
148 %          ___________  a
149 %
150 %   As can be seen, we get symmetry if we split staff lines into two
151 %   equal parts `a' and a pixel line with thickness 1.  Consequently, we
152 %   use the following algorithm:
153 %
154 %   . Decrease the height `h' by 1 temporarily.
155 %
156 %   . Compute the path for the upper half of the glyph.
157 %
158 %   . Mirror the path at the x axis.
159 %
160 %   . Shift the upper half one pixel up and connect it with the lower path.
161 %
162 %   . Restore height and decrease `d' by 1.
163 %
164 % o The glyph is centered between two or four staff lines, and the origin is
165 %   the middle of the whitespace.  Assuming that the whitespace consists of
166 %   an odd number of pixels, we have this:
167 %
168 %          -----------
169 %                       b
170 %                       1
171 %                       b
172 %          ___________
173 %                       b
174 %   ..................  1  .................  x axis
175 %                       b
176 %          ___________
177 %                       b
178 %                       1
179 %                       b
180 %          ___________
181 %
182 %   For symmetrical glyphs, this leads to a similar algorithm as above.
183 %   Glyphs which can't be constructed from an upper and lower part need
184 %   to be handled differently, namely to shift up the vertical center by
185 %   half a pixel:
186 %
187 %          ___________
188 %                       b
189 %
190 %                       0.5
191 %   ..................  0.5 ................  x axis
192 %
193 %                       b
194 %          ___________
195 %
196
197 feta_eps := 0;
198 feta_shift := 0;
199 feta_space_shift := 0;
200
201 % Use this for paths with a slant of 45 degrees to assure that
202 % the middle point of a penpos gets covered.
203 pair feta_offset;
204 feta_offset := (0, 0);
205
206 if known miterlimit:
207         pickup nullpen;
208 else:
209         feta_eps := eps;
210
211         if odd stafflinethickness_rounded:
212                 feta_shift := 1;
213         fi;
214
215         if odd (staff_space_rounded - stafflinethickness_rounded):
216                 feta_space_shift := 1;
217         fi;
218
219         feta_offset := (0.5, 0.5);
220
221         pickup pencircle scaled 1;
222 fi;
223
224 feta_fillpen := savepen;
225
226 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227 % Notehead width and height are defined here.
228 %
229 %
230 % Slope of slash.  From scm/grob-description.scm.  How to auto-copy?
231 slash_slope := 1.7;
232
233 % Thickness of slash lines.  Quarter notes get 1.5slt width.
234 slash_thick# := 2/3 * 0.48 staff_space#;
235
236 %
237 % Hand-engraved music often has balls extending above and below
238 % the lines.  If you like that, modify overdone heads (unit:
239 % stafflinethickness).
240 %
241
242 %% FIXME
243 % There is a problem with noteheads slightly extending beyond the staff
244 % lines.  This is due to the fact that staff_space + stafflinethickness
245 % is sometimes an odd number, so the nothead height and depth are not
246 % integers.  Then, when the font is converted to an outline font, the
247 % system rounds up the 0.5 left over from dividing the notehead height
248 % in two, and the notehead extends slightly beyond the staff line.
249 % In order to resolve this problem, we use overdone_heads to slightly
250 % reduce the notehead height.  Empirically, we have determined that 
251 % reducing by 10% of stafflinethickness solves the problem.
252
253 overdone_heads = -0.1;
254 noteheight# := staff_space# + (1 + overdone_heads) * stafflinethickness#;
255
256 define_pixels (slash_thick);
257 define_whole_vertical_pixels (noteheight);
258
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 %
261 % This is used to draw all elliptical notes; it also sets
262 % black_notehead_width, so it should be called in any file that
263 % needs the value of black_notehead_width.
264 %
265 % SLANT moves both extrema on the long axis (by SLANT * ELLIPTICITY,
266 % so SLANT = -1, puts the extreme on the long axis next to the short
267 % axis one).
268 %
269
270 def draw_outside_ellipse (expr ellipticity, tilt, superness, slant) =
271         save attachment_y;
272         save pat;
273         path pat;
274
275         pat := superellipse ((ellipticity, 0), (-slant * ellipticity, 1.0),
276                              (-ellipticity, 0), (slant * ellipticity, -1.0),
277                              superness);
278         pat := pat rotated tilt;
279
280         save top_point, right_point;
281         pair top_point, right_point;
282
283         top_point := directionpoint left of pat;
284         right_point := directionpoint up of pat;
285
286         save scaling, width;
287
288         scaling# := noteheight# / (2 ypart (top_point));
289         width# := 2 xpart (right_point) * scaling#;
290         define_pixels (scaling, width);
291        set_char_box (0, width#, noteheight# / 2, noteheight# / 2);
292
293         d := d - feta_space_shift;
294
295         % attachment Y
296         charwy := ypart (right_point) * scaling#;
297         charwx := width#;
298
299         pat := pat scaled scaling shifted (w / 2, .5 (h - d));
300
301         width := hround width;
302
303         if test_outlines = 1:
304                 draw pat;
305         else:
306                 fill pat;
307         fi;
308 enddef;
309
310
311 def draw_quarter_path =
312         draw_outside_ellipse (1.49 - puff_up_factor / 3.0, 31, 0.707, 0);
313 enddef;
314
315 test_outlines := 0;
316 draw_quarter_path;
317 black_notehead_width# := charwd;
318
319 define_pixels (slash_thick);
320 define_whole_vertical_pixels (noteheight);
321
322