2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2001--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond 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.
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.
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/>.
20 #include "accidental-interface.hh"
21 #include "font-interface.hh"
22 #include "international.hh"
24 #include "output-def.hh"
25 #include "paper-column.hh"
30 parenthesize (Grob *me, Stencil m)
33 = Font_interface::get_default_font (me);
35 = font->find_by_name ("accidentals.leftparen");
37 = font->find_by_name ("accidentals.rightparen");
39 m.add_at_edge (X_AXIS, LEFT, Stencil (open), 0);
40 m.add_at_edge (X_AXIS, RIGHT, Stencil (close), 0);
45 /* If this gets called before line breaking, we will return a non-trivial
46 extent even if we belong to a tie and won't actually get printed. */
48 get_extent (Grob *me, Axis a)
50 Stencil *s = unsmob_stencil (Accidental_interface::get_stencil (me));
53 return ly_interval2scm (s->extent (a));
54 return ly_interval2scm (Interval ());
57 MAKE_SCHEME_CALLBACK (Accidental_interface, height, 1);
59 Accidental_interface::height (SCM smob)
61 return get_extent (unsmob_grob (smob), Y_AXIS);
64 MAKE_SCHEME_CALLBACK (Accidental_interface, width, 1);
66 Accidental_interface::width (SCM smob)
68 return get_extent (unsmob_grob (smob), X_AXIS);
71 MAKE_SCHEME_CALLBACK (Accidental_interface, pure_height, 3);
73 Accidental_interface::pure_height (SCM smob, SCM start_scm, SCM)
75 Item *me = dynamic_cast<Item*> (unsmob_grob (smob));
76 int start = scm_to_int (start_scm);
77 int rank = me->get_column ()->get_rank ();
79 if (to_boolean (me->get_property ("forced"))
80 || !unsmob_grob (me->get_object ("tie"))
81 || (rank == start + 1 && /* we are at the start of a line */
82 !to_boolean (me->get_property ("hide-tied-accidental-after-break"))))
84 Stencil *s = unsmob_stencil (get_stencil (me));
86 return ly_interval2scm (s->extent (Y_AXIS));
89 return ly_interval2scm (Interval ());
93 Accidental_interface::accurate_boxes (Grob *me, Grob **common)
96 b[X_AXIS] = me->extent (me, X_AXIS);
97 b[Y_AXIS] = me->extent (me, Y_AXIS);
101 bool parens = to_boolean (me->get_property ("parenthesized"));
105 if (!to_boolean (me->get_property ("restore-first"))
108 SCM alist = me->get_property ("glyph-name-alist");
109 SCM alt = me->get_property ("alteration");
110 string glyph_name = robust_scm2string (ly_assoc_get (alt, alist, SCM_BOOL_F),
113 if (glyph_name == "accidentals.flat"
114 || glyph_name == "accidentals.mirroredflat")
120 we could make the stem thinner, but that places the flats
124 glyph_name == "accidentals.mirroredflat" ? LEFT : RIGHT;
125 stem[X_AXIS][bulb_dir] = stem[X_AXIS].center ();
128 To prevent vertical alignment for 6ths
131 bulb[Y_AXIS][UP] *= .35;
133 boxes.push_back (bulb);
134 boxes.push_back (stem);
136 else if (glyph_name == "accidentals.natural")
142 lstem[Y_AXIS] *= 1.1;
143 rstem[Y_AXIS] *= 1.1;
145 belly[Y_AXIS] *= 0.75;
146 lstem[X_AXIS][RIGHT] *= .33;
147 rstem[X_AXIS][LEFT] = rstem[X_AXIS].linear_combination (1.0 / 3.0);
148 lstem[Y_AXIS][DOWN] = belly[Y_AXIS][DOWN];
149 rstem[Y_AXIS][UP] = belly[Y_AXIS][UP];
150 boxes.push_back (belly);
151 boxes.push_back (lstem);
152 boxes.push_back (rstem);
155 TODO: add support for, double flat.
162 Offset o (me->relative_coordinate (common[X_AXIS], X_AXIS),
163 me->relative_coordinate (common[Y_AXIS], Y_AXIS));
165 for (vsize i = boxes.size (); i--;)
166 boxes[i].translate (o);
171 MAKE_SCHEME_CALLBACK (Accidental_interface, print, 1);
173 Accidental_interface::print (SCM smob)
175 Grob *me = unsmob_grob (smob);
176 Grob *tie = unsmob_grob (me->get_object ("tie"));
179 (to_boolean (me->get_property ("hide-tied-accidental-after-break"))
180 || (!tie->original () && !to_boolean (me->get_property ("forced")))))
186 return get_stencil (me);
190 Accidental_interface::get_stencil (Grob *me)
192 Font_metric *fm = Font_interface::get_default_font (me);
194 SCM alist = me->get_property ("glyph-name-alist");
195 SCM alt = me->get_property ("alteration");
196 SCM glyph_name = ly_assoc_get (alt, alist, SCM_BOOL_F);
198 if (!scm_is_string (glyph_name))
200 me->warning (_f ("Could not find glyph-name for alteration %s",
201 ly_scm_write_string (alt).c_str ()));
205 Stencil mol (fm->find_by_name (ly_scm2string (glyph_name)));
206 if (to_boolean (me->get_property ("restore-first")))
209 this isn't correct for ancient accidentals, but they don't
210 use double flats/sharps anyway.
212 Stencil acc (fm->find_by_name ("accidentals.natural"));
215 me->warning (_ ("natural alteration glyph not found"));
217 mol.add_at_edge (X_AXIS, LEFT, acc, 0.1);
220 if (to_boolean (me->get_property ("parenthesized")))
221 mol = parenthesize (me, mol);
223 return mol.smobbed_copy ();
227 ADD_INTERFACE (Accidental_interface,
228 "A single accidental.",
235 "hide-tied-accidental-after-break "