2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2013--2015 Aleksandr Andreev <aleksandr.andreev@gmail.com>
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 "coherent-ligature-engraver.hh"
21 #include "font-interface.hh"
22 #include "international.hh"
23 #include "kievan-ligature.hh"
24 #include "paper-column.hh"
25 #include "rhythmic-head.hh"
27 #include "stream-event.hh"
30 #include "translator.icc"
32 class Kievan_ligature_engraver : public Coherent_ligature_engraver
36 virtual Spanner *create_ligature_spanner ();
37 virtual void build_ligature (Spanner *ligature,
38 vector<Grob_info> const &primitives);
39 DECLARE_TRANSLATOR_LISTENER (ligature);
42 TRANSLATOR_DECLARATIONS (Kievan_ligature_engraver);
43 TRANSLATOR_INHERIT (Coherent_ligature_engraver)
46 void fold_up_primitives (vector<Grob_info> const &primitives, Real padding, Real &min_length);
49 IMPLEMENT_TRANSLATOR_LISTENER (Kievan_ligature_engraver, ligature);
51 Kievan_ligature_engraver::listen_ligature (Stream_event *ev)
53 Ligature_engraver::listen_ligature (ev);
56 Kievan_ligature_engraver::Kievan_ligature_engraver ()
62 Kievan_ligature_engraver::create_ligature_spanner ()
64 return make_spanner ("KievanLigature", SCM_EOL);
68 Kievan_ligature_engraver::fold_up_primitives (vector<Grob_info> const &primitives,
69 Real padding, Real &min_length)
72 Real accumul_acc_space = 0.0;
73 // start us off with some padding on the left
76 for (vsize i = 0; i < primitives.size (); i++)
78 Item *current = dynamic_cast<Item *> (primitives[i].grob ());
79 Interval my_ext = current->extent (current, X_AXIS);
80 Real head_width = my_ext.length ();
84 // must keep track of accidentals in spacing problem
85 Grob *acc_gr = unsmob<Grob> (current->get_object ("accidental-grob"));
88 Interval acc_ext = acc_gr->extent (acc_gr, X_AXIS);
89 accumul_acc_space += acc_ext.length();
92 move_related_items_to_column (current, first->get_column (),
95 // check if we have any dots
96 if (size_t const dot_count = Rhythmic_head::dot_count (current))
98 Grob *dot_gr = Rhythmic_head::get_dots (current);
100 head_width += Font_interface::get_default_font (current)->
101 find_by_name ("dots.dotkievan").extent (X_AXIS).length() -
102 0.5 * (padding - accumul_acc_space);
104 dot_gr->translate_axis (0.5 * (padding - accumul_acc_space), X_AXIS);
107 // add more padding if we have an accidental coming up
108 if (i < primitives.size () - 1)
110 Item *next = dynamic_cast<Item *> (primitives[i + 1].grob ());
111 Grob *acc_gr = unsmob<Grob> (next->get_object ("accidental-grob"));
114 Interval acc_ext = acc_gr->extent (acc_gr, X_AXIS);
115 padding += acc_ext.length();
119 min_length += head_width + padding - accumul_acc_space;
126 Kievan_ligature_engraver::build_ligature (Spanner *ligature,
127 vector<Grob_info> const &primitives)
131 Real padding = robust_scm2double (ligature->get_property ("padding"), 0.0);
132 fold_up_primitives (primitives, padding, min_length);
133 if (robust_scm2double (ligature->get_property ("minimum-length"), 0.0)
135 ligature->set_property ("minimum-length", scm_from_double (min_length));
139 ADD_ACKNOWLEDGER (Kievan_ligature_engraver, rest);
140 ADD_ACKNOWLEDGER (Kievan_ligature_engraver, ligature_head);
142 ADD_TRANSLATOR (Kievan_ligature_engraver,
144 "Handle @code{Kievan_ligature_events} by glueing Kievan"