+ Grob *nu = Note_column::first_head (cu);
+ Grob *nd = Note_column::first_head (cd);
+
+ vector<int> ups = Stem::note_head_positions (Note_column::get_stem (cu));
+ vector<int> dps = Stem::note_head_positions (Note_column::get_stem (cd));
+
+ /* Too far apart to collide. */
+ if (ups[0] > dps.back () + 1)
+ return;
+
+ /* Merge heads if the notes lie the same line, or if the "stem-up-note" is
+ above the "stem-down-note". */
+ bool merge_possible = (ups[0] >= dps[0]) && (ups.back () >= dps.back ());
+
+ /* Do not merge notes typeset in different style. */
+ if (!ly_is_equal (nu->get_property ("style"),
+ nd->get_property ("style")))
+ merge_possible = false;
+
+ int upball_type = Rhythmic_head::duration_log (nu);
+ int dnball_type = Rhythmic_head::duration_log (nd);
+
+ /* Do not merge whole notes (or longer, like breve, longa, maxima). */
+ if (merge_possible && (upball_type <= 0 || dnball_type <= 0))
+ merge_possible = false;
+
+ if (merge_possible
+ && Rhythmic_head::dot_count (nu) != Rhythmic_head::dot_count (nd)
+ && !to_boolean (me->get_property ("merge-differently-dotted")))
+ merge_possible = false;
+
+ /* Can only merge different heads if merge-differently-headed is
+ set. */
+ if (merge_possible
+ && upball_type != dnball_type
+ && !to_boolean (me->get_property ("merge-differently-headed")))
+ merge_possible = false;
+
+ if (merge_possible
+ && nu->get_property ("style") == ly_symbol2scm ("fa")
+ && nd->get_property ("style") == ly_symbol2scm ("fa"))
+ {
+ Interval uphead_size = nu->extent (nu, Y_AXIS);
+ Offset att = Offset (0.0, -1.0);
+ nu->set_property ("stem-attachment", ly_offset2scm (att));
+ nu->set_property ("transparent", SCM_BOOL_T);
+ }