summaryrefslogtreecommitdiff
path: root/mf
diff options
context:
space:
mode:
authorJanek Warchoł <lemniskata.bernoullego@gmail.com>2013-12-04 15:26:03 +0100
committerBenkő Pál <benko.pal@gmail.com>2013-12-20 00:04:05 +0100
commitb2ee405188663de7ce5e0e79af12f06726f511f8 (patch)
tree44cfc2740ffc8f196654f05eadb51b0e7521a056 /mf
parent166d6eab595c2e5a9a1538f9ab5a3810bd3f1b04 (diff)
font: parametrize and cleanup sharp code
Changes: * as much as possible is controlled by global parameters, * variables have more consistent names, * the functions are more consistently structured, * stem ends are placed in one line using explicit beam direction. The glyphs remain identical. It would be good to extract one global procedure that would draw all needed sharps (instead of having 6 similar ones), but i didn't have enough time to do this.
Diffstat (limited to 'mf')
-rw-r--r--mf/feta-sharps.mf474
1 files changed, 230 insertions, 244 deletions
diff --git a/mf/feta-sharps.mf b/mf/feta-sharps.mf
index 46937f9e4d..eeade7d207 100644
--- a/mf/feta-sharps.mf
+++ b/mf/feta-sharps.mf
@@ -1,119 +1,119 @@
-save sharp_beamheight;
-sharp_beamheight# := 0.3 staff_space# + stafflinethickness#;
-
%
% The beams of most sharps have horizontal endings (as if drawn with
% a square pen). [Wanske] does not mention this, so we'll just ignore
% this fact.
%
-def draw_meta_sharp (expr width, offset) =
- save beamwidth, beamslope;
- save ne, nw_dist;
- pair ne, nw_dist;
+save default_width, default_height, onestemmed_height;
+save default_interbeam_dist, triples_interbeam_dist;
+save default_beam_thickness, stem_thickness;
+
+default_width# := 1.1 staff_space#;
+default_height# := 3 staff_space#;
+onestemmed_height# := 2.66 staff_space#;
+define_pixels (default_width);
+
+default_interbeam_dist := 1.05 staff_space_rounded;
+triples_interbeam_dist := 1.2 staff_space_rounded;
+
+default_beam_thickness# := 0.3 staff_space# + stafflinethickness#;
+stem_thickness# := stafflinethickness# + .05 staff_space#;
+define_whole_blacker_pixels (stem_thickness);
- beamwidth := width;
- define_whole_vertical_blacker_pixels (sharp_beamheight);
+def draw_sharp_beam (expr length, y_offset) =
+ save beam_length;
+ save ne_beam_dir, nw_dist;
+ pair ne_beam_dir, nw_dist;
- clearxy;
+ beam_length := length;
- beamslope = sharp_beamheight / beamwidth;
+ define_whole_vertical_blacker_pixels (default_beam_thickness);
- pickup pencircle scaled 2 blot_diameter;
+ clearxy;
- rt x2 - lft x1 = beamwidth;
- z2 = z1 + whatever * (beamwidth, sharp_beamheight);
- .5 [z1, z3] = (.5 w, offset);
- x3 = x2;
- top y2 - bot y3 = sharp_beamheight;
- x4 = x1;
- top y1 - bot y4 = sharp_beamheight;
+ pickup pencircle scaled 2 blot_diameter;
- ne = unitvector (z2 - z1);
- nw_dist = (ne rotated 90) * blot_diameter;
+ rt x2 - lft x1 = beam_length;
+ z2 = z1 + whatever * (beam_length, default_beam_thickness);
+ .5 [z1, z3] = (.5 w, y_offset);
+ x3 = x2;
+ top y2 - bot y3 = default_beam_thickness;
+ x4 = x1;
+ top y1 - bot y4 = default_beam_thickness;
- fill lft z1{up}
- ... (z1 + nw_dist){ne}
- -- (z2 + nw_dist){ne}
- ... rt z2{down}
- -- rt z3{down}
- ... (z3 - nw_dist){-ne}
- -- (z4 - nw_dist){-ne}
- ... lft z4{up}
- -- cycle;
+ ne_beam_dir = unitvector (z2 - z1);
+ nw_dist = (ne_beam_dir rotated 90) * blot_diameter;
+
+ fill lft z1{up}
+ ... (z1 + nw_dist){ne_beam_dir}
+ -- (z2 + nw_dist){ne_beam_dir}
+ ... rt z2{down}
+ -- rt z3{down}
+ ... (z3 - nw_dist){-ne_beam_dir}
+ -- (z4 - nw_dist){-ne_beam_dir}
+ ... lft z4{up}
+ -- cycle;
labels (1, 2, 3, 4);
enddef;
-def draw_sharp(expr arrowup, arrowdown) =
- save stem, stemx, stemwidth;
- save outer_space, interbeam;
- save stemlength, extendleft, extendright, height, depth;
-
- stemwidth# := stafflinethickness# + .05 staff_space#;
- define_whole_blacker_pixels (stemwidth);
-
- interbeam := 1.05 staff_space_rounded;
-
- stemlength# := 1.5 staff_space#;
- define_pixels (stemlength);
-
- height# = stemlength#;
- depth# = stemlength#;
- extendright# = 0;
- extendleft# = 0;
- if arrowup:
- height# := height# + 1.2 staff_space#;
- extendright# := extendright# + 1.5 stafflinethickness#;
- fi;
- if arrowdown:
- depth# := depth# + 1.2 staff_space#;
- extendleft# := extendleft# + 1.5 stafflinethickness#;
- fi;
- define_pixels (extendleft, extendright);
- set_char_box (extendleft#, 1.1 staff_space#, depth#, height#);
-
- stem := 7 / 16 * w;
- stemx := hround stem;
- outer_space := hround ((w - stemx - stemwidth) / 2);
-
- w := 2 outer_space + stemx + stemwidth;
- d := d - feta_space_shift;
-
- draw_meta_sharp (w, -.5 interbeam);
- draw_meta_sharp (w, -.5 interbeam + vround interbeam);
-
- % expand the charbox so that it encloses the whole arrow;
- % this must not happen earlier because some commands above
- % still rely on the old width
- w := w + extendright;
-
- pickup pencircle scaled stemwidth;
-
- lft x5 = lft x6 = outer_space;
- lft x7 = lft x8 = outer_space + stemx;
- bot y5 = -stemlength;
- top y6 = vround (1.5 staff_space - stem * beamslope);
- bot y7 = -top y6 + feta_space_shift;
- top y8 = stemlength;
-
- labels (5, 6, 7, 8);
-
- draw_gridline (z5, z6, stemwidth);
- draw_gridline (z7, z8, stemwidth);
-
- if arrowup:
- draw_arrow (z8, stemwidth, up,
- stafflinethickness / 2 + stemwidth / 2, false);
- fi;
- if arrowdown:
- draw_arrow (z5, stemwidth, up,
- stafflinethickness / 2 + stemwidth / 2, true);
- fi;
-
+def draw_sharp (expr arrowup, arrowdown) =
+ save dist_between_stems;
+ save outer_space;
+ save half_height, interbeam_dist;
+
+ half_height# := 0.5 default_height#;
+ define_pixels (half_height);
+ interbeam_dist := default_interbeam_dist;
+
+ set_char_box (0, default_width#, half_height#, half_height#);
+ d := d - feta_space_shift;
+
+ dist_between_stems := hround (7 / 16 * default_width);
+ outer_space := hround ((w - dist_between_stems - stem_thickness) / 2);
+
+ w := 2 outer_space + dist_between_stems + stem_thickness;
+
+ draw_sharp_beam (w, -.5 interbeam_dist);
+ draw_sharp_beam (w, -.5 interbeam_dist + vround interbeam_dist);
+
+ % expand the charbox so that it encloses the whole arrow;
+ % this must not happen earlier because some commands above
+ % still rely on the old width
+ if arrowup:
+ w := w + 1.5 stafflinethickness;
+ h := h + 1.2 staff_space;
+ fi;
+ if arrowdown:
+ b := b + 1.5 stafflinethickness;
+ d := d + 1.2 staff_space;
+ fi;
+
+ pickup pencircle scaled stem_thickness;
+
+ lft x5 = lft x6 = outer_space;
+ lft x7 = lft x8 = outer_space + dist_between_stems;
+ bot y5 = -half_height;
+ top y8 = half_height;
+ z6 = z8 + whatever * ne_beam_dir;
+ bot y7 = -top y6 + feta_space_shift;
+
+ draw_gridline (z5, z6, stem_thickness);
+ draw_gridline (z7, z8, stem_thickness);
+
+ if arrowup:
+ draw_arrow (z8, stem_thickness, up,
+ stafflinethickness / 2 + stem_thickness / 2, false);
+ fi;
+ if arrowdown:
+ draw_arrow (z5, stem_thickness, up,
+ stafflinethickness / 2 + stem_thickness / 2, true);
+ fi;
+
+ labels (5, 6, 7, 8);
draw_staff_if_debugging (-2, 2);
enddef;
@@ -139,215 +139,201 @@ fet_endchar;
fet_beginchar ("1/2 Sharp", "sharp.slashslash.stem");
- save stem, stemwidth;
- save outer_space, interbeam;
-
- stemwidth# := stafflinethickness# + .05 staff_space#;
- define_whole_blacker_pixels (stemwidth);
+ save outer_space;
+ save half_height, interbeam_dist;
- interbeam := 1.05 staff_space_rounded;
+ half_height# := 0.5 onestemmed_height#;
+ define_pixels (half_height);
+ interbeam_dist := default_interbeam_dist;
- set_char_box (0, 0.7 staff_space#,
- 1.5 staff_space#, 1.5 staff_space#);
+ set_char_box (0, 0.7 staff_space#, half_height#, half_height#);
+ d := d - feta_space_shift;
- stem := 7 / 16 * w;
- outer_space := hround ((w - stemwidth) / 2);
+ outer_space := hround ((w - stem_thickness) / 2);
- w := 2 outer_space + stemwidth;
- d := d - feta_space_shift;
+ w := 2 outer_space + stem_thickness;
- draw_meta_sharp (w, -.5 interbeam);
- draw_meta_sharp (w, -.5 interbeam + vround interbeam);
+ draw_sharp_beam (w, -.5 interbeam_dist);
+ draw_sharp_beam (w, -.5 interbeam_dist + vround interbeam_dist);
- pickup pencircle scaled stemwidth;
+ pickup pencircle scaled stem_thickness;
- lft x5 = lft x6 = outer_space;
- top y6 = vround (1.5 staff_space - .5 stem);
- bot y5 = -top y6 + feta_space_shift;
+ lft x5 = lft x6 = outer_space;
+ top y6 = half_height;
+ bot y5 = -top y6 + feta_space_shift;
- labels (5, 6);
-
- draw_gridline (z5, z6, stemwidth);
+ draw_gridline (z5, z6, stem_thickness);
+ labels (5, 6);
draw_staff_if_debugging (-2, 2);
fet_endchar;
fet_beginchar ("Sharp (3 beams)", "sharp.slashslashslash.stemstem");
- save stem, stemx, stemwidth;
- save outer_space, interbeam;
- save sharp_beamheight;
-
- sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
-
- stemwidth# := stafflinethickness# + .05 staff_space#;
- define_whole_blacker_pixels (stemwidth);
+ save dist_between_stems;
+ save outer_space;
+ save half_height, interbeam_dist;
+ save default_beam_thickness;
- interbeam := 1.2 staff_space_rounded;
+ half_height# := 0.5 default_height#;
+ define_pixels (half_height);
+ interbeam_dist := triples_interbeam_dist;
- set_char_box (0, 1.1 staff_space#,
- 1.5 staff_space#, 1.5 staff_space#);
+ default_beam_thickness# := 0.22 staff_space# + stafflinethickness#;
- stem := 7 / 16 * w;
- stemx := hround stem;
- outer_space := hround ((w - stemx - stemwidth) / 2);
+ set_char_box (0, default_width#, half_height#, half_height#);
- w := 2 outer_space + stemx + stemwidth;
- d := d - feta_space_shift;
+ dist_between_stems := hround (7 / 16 * default_width);
+ outer_space := hround ((w - dist_between_stems - stem_thickness) / 2);
- draw_meta_sharp (.88 w, -.5 interbeam);
- draw_meta_sharp (.88 w, -.5 interbeam + vround interbeam);
- sharp_beamheight# := 1/.88 sharp_beamheight#;
- draw_meta_sharp (w, 0);
+ w := 2 outer_space + dist_between_stems + stem_thickness;
+ d := d - feta_space_shift;
- pickup pencircle scaled stemwidth;
+ draw_sharp_beam (.88 w, -.5 interbeam_dist);
+ draw_sharp_beam (.88 w, -.5 interbeam_dist + vround interbeam_dist);
+ default_beam_thickness# := 1/.88 default_beam_thickness#;
+ draw_sharp_beam (w, 0);
- lft x5 = lft x6 = outer_space;
- lft x7 = lft x8 = outer_space + stemx;
- bot y5 = -d;
- top y6 = vround (1.5 staff_space - stem * beamslope);
- bot y7 = -top y6 + feta_space_shift;
- top y8 = h;
+ pickup pencircle scaled stem_thickness;
- labels (5, 6, 7, 8);
+ lft x5 = lft x6 = outer_space;
+ lft x7 = lft x8 = outer_space + dist_between_stems;
+ bot y5 = -half_height;
+ top y8 = half_height;
+ z6 = z8 + whatever * ne_beam_dir;
+ bot y7 = -top y6 + feta_space_shift;
- draw_gridline (z5, z6, stemwidth);
- draw_gridline (z7, z8, stemwidth);
+ draw_gridline (z5, z6, stem_thickness);
+ draw_gridline (z7, z8, stem_thickness);
+ labels (5, 6, 7, 8);
draw_staff_if_debugging (-2, 2);
fet_endchar;
fet_beginchar ("1/2 Sharp (3 beams)", "sharp.slashslashslash.stem");
- save stem, stemx, stemwidth;
- save outer_space, interbeam;
- save sharp_beamheight;
+ save outer_space;
+ save half_height, interbeam_dist;
+ save default_beam_thickness;
- sharp_beamheight# := 0.22 staff_space# + stafflinethickness#;
+ half_height# := 0.5 onestemmed_height#;
+ define_pixels (half_height);
+ interbeam_dist := triples_interbeam_dist;
- stemwidth# := stafflinethickness# + .05 staff_space#;
- define_whole_blacker_pixels (stemwidth);
+ default_beam_thickness# := 0.22 staff_space# + stafflinethickness#;
- interbeam := 1.2 staff_space_rounded;
+ set_char_box (0, 0.95 staff_space#, half_height#, half_height#);
- set_char_box (0, 0.95 staff_space#,
- 1.3 staff_space#, 1.3 staff_space#);
+ outer_space := hround ((w - stem_thickness) / 2);
- stem := 7 / 16 * w;
- outer_space := hround ((w - stemwidth) / 2);
+ w := 2 outer_space + stem_thickness;
+ d := d - feta_space_shift;
- w := 2 outer_space + stemwidth;
- d := d - feta_space_shift;
+ draw_sharp_beam (.8 w, -.5 interbeam_dist);
+ draw_sharp_beam (.8 w, -.5 interbeam_dist + vround interbeam_dist);
+ default_beam_thickness# := 1/.8 default_beam_thickness#;
+ draw_sharp_beam (w, 0);
- draw_meta_sharp (.8 w, -.5 interbeam);
- draw_meta_sharp (.8 w, -.5 interbeam + vround interbeam);
- sharp_beamheight# := 1/.8 sharp_beamheight#;
- draw_meta_sharp (w, 0);
+ pickup pencircle scaled stem_thickness;
- pickup pencircle scaled stemwidth;
+ lft x5 = lft x6 = outer_space;
+ top y6 = half_height;
+ bot y5 = -top y6 + feta_space_shift;
- lft x5 = lft x6 = outer_space;
- top y6 = vround (1.5 staff_space - .5 stem);
- bot y5 = -top y6 + feta_space_shift;
- labels (5, 6);
-
- draw_gridline (z5, z6, stemwidth);
+ draw_gridline (z5, z6, stem_thickness);
+ labels (5, 6);
draw_staff_if_debugging (-2, 2);
fet_endchar;
fet_beginchar ("3/4 Sharp", "sharp.slashslash.stemstemstem");
- save stem, stemx, stemwidth;
- save outer_space, interbeam;
-
- stemwidth# := stafflinethickness# + .05 staff_space#;
- define_whole_blacker_pixels (stemwidth);
-
- interbeam := 1.05 staff_space_rounded;
+ save dist_between_stems;
+ save outer_space;
+ save half_height, interbeam_dist;
- set_char_box (0, 1.6 staff_space#,
- 1.5 staff_space#, 1.5 staff_space#);
+ half_height# := 0.5 default_height#;
+ define_pixels (half_height);
+ interbeam_dist := default_interbeam_dist;
- stem := 9 / 32 * w;
- stemx := hround stem;
- outer_space := hround ((w - 2 stemx - stemwidth) / 2);
+ set_char_box (0, 1.6 staff_space#, half_height#, half_height#);
+ d := d - feta_space_shift;
- w := 2 outer_space + 2 stemx + stemwidth;
- d := d - feta_space_shift;
+ dist_between_stems := hround (9 / 32 * w);
+ outer_space := hround ((w - 2 dist_between_stems - stem_thickness) / 2);
- draw_meta_sharp (w, -.5 interbeam);
- draw_meta_sharp (w, -.5 interbeam + vround interbeam);
+ w := 2 outer_space + 2 dist_between_stems + stem_thickness;
- pickup pencircle scaled stemwidth;
+ draw_sharp_beam (w, -.5 interbeam_dist);
+ draw_sharp_beam (w, -.5 interbeam_dist + vround interbeam_dist);
- lft x5 = lft x6 = outer_space;
- lft x7 = lft x8 = outer_space + stemx;
- lft x9 = lft x10 = outer_space + 2 stemx;
- bot y5 = -d;
- top y6 = vround (1.5 staff_space - 2 stem * beamslope);
- bot y9 = -top y6 + feta_space_shift;
- top y10 = h;
- y7 = .5 [y5, y9];
- y8 = .5 [y6, y10];
+ pickup pencircle scaled stem_thickness;
- labels (5, 6, 7, 8, 9, 10);
+ lft x5 = lft x6 = outer_space;
+ lft x9 = lft x10 = outer_space + dist_between_stems;
+ lft x7 = lft x8 = outer_space + 2 dist_between_stems;
+ bot y5 = -half_height;
+ top y8 = half_height;
+ z6 = z8 + whatever * ne_beam_dir;
+ bot y7 = -top y6 + feta_space_shift;
+ y9 = .5 [y5, y7];
+ y10 = .5 [y6, y8];
- draw_gridline (z5, z6, stemwidth);
- draw_gridline (z7, z8, stemwidth);
- draw_gridline (z9, z10, stemwidth);
+ draw_gridline (z5, z6, stem_thickness);
+ draw_gridline (z7, z8, stem_thickness);
+ draw_gridline (z9, z10, stem_thickness);
+ labels (5, 6, 7, 8, 9, 10);
draw_staff_if_debugging (-2, 2);
fet_endchar;
fet_beginchar ("Double Sharp", "doublesharp");
- save klaverblad, klaversteel;
- save pat;
- path pat;
-
- klaversteel = 1/15 staff_space;
- klaverblad = .4 staff_space - .5 stafflinethickness;
-
- set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
-
- z1 = (klaversteel, 0);
- z2 = (w / 2 - klaverblad / 10, h - klaverblad);
- z3 = (w / 2, h);
- z4 = z2 reflectedabout ((0, 0), (1, 1));
- z5 = z1 reflectedabout ((0, 0), (1, 1));
-
- labels (1, 2, 3, 4, 5);
-
- pickup pencircle scaled blot_diameter;
-
- x2 := hfloor (rt x2) - blot_diameter / 2;
- x3 := hfloor (rt x3) - blot_diameter / 2;
- y3 := vfloor (top y3) - blot_diameter / 2;
- y4 := vfloor (top y4) - blot_diameter / 2;
-
- pat = (rt z1){dir45}
- .. {right}(bot z2)
- .. rt z2
- -- rt z3{z3 - z2}
- .. top z3{z4 - z3}
- -- top z4{z4 - z3}
- .. (lft z4){down}
- .. {dir 225}(top z5);
- pat := pat
- -- reverse pat xscaled -1 shifted (-feta_eps, 0);
-
- % assure symmetry -- it's more important to center the glyph on the
- % staff line than centering it between staff lines, so we use
- % feta_shift, not feta_space_shift.
- h := h + feta_shift;
-
- fill pat shifted (0, feta_shift)
- -- reverse pat yscaled -1 shifted (0, -feta_eps)
- -- cycle;
+ save klaverblad, klaversteel;
+ save pat;
+ path pat;
+
+ klaversteel = 1/15 staff_space;
+ klaverblad = .4 staff_space - .5 stafflinethickness;
+
+ set_char_box (0, staff_space#, .5 staff_space#, .5 staff_space#);
+
+ z1 = (klaversteel, 0);
+ z2 = (w / 2 - klaverblad / 10, h - klaverblad);
+ z3 = (w / 2, h);
+ z4 = z2 reflectedabout ((0, 0), (1, 1));
+ z5 = z1 reflectedabout ((0, 0), (1, 1));
+
+ pickup pencircle scaled blot_diameter;
+
+ x2 := hfloor (rt x2) - blot_diameter / 2;
+ x3 := hfloor (rt x3) - blot_diameter / 2;
+ y3 := vfloor (top y3) - blot_diameter / 2;
+ y4 := vfloor (top y4) - blot_diameter / 2;
+
+ pat = (rt z1){dir45}
+ .. {right}(bot z2)
+ .. rt z2
+ -- rt z3{z3 - z2}
+ .. top z3{z4 - z3}
+ -- top z4{z4 - z3}
+ .. (lft z4){down}
+ .. {dir 225}(top z5);
+ pat := pat
+ -- reverse pat xscaled -1 shifted (-feta_eps, 0);
+
+ % assure symmetry -- it's more important to center the glyph on the
+ % staff line than centering it between staff lines, so we use
+ % feta_shift, not feta_space_shift.
+ h := h + feta_shift;
+
+ fill pat shifted (0, feta_shift)
+ -- reverse pat yscaled -1 shifted (0, -feta_eps)
+ -- cycle;
% ugh
currentpicture := currentpicture shifted (hround (w / 2), 0);
+ labels (1, 2, 3, 4, 5);
draw_staff_if_debugging (-2, 2);
fet_endchar;