From 1cb19209abd4a14e45dae2fd3f20d43aa663f2ab Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Sun, 25 May 2003 23:11:52 +0000 Subject: [PATCH] * lily/text-spanner.cc (brew_molecule): clean up function. This fixes bugs with broken 8va spanners. * lily/simple-spacer.cc (solve): also compute force for raggedright. This prevents spurious line-breaks with raggedright --- ChangeLog | 11 ++- input/regression/ottava-broken.ly | 23 ++++++ lily/gourlay-breaking.cc | 7 -- lily/simple-spacer.cc | 6 +- lily/spanner.cc | 2 +- lily/text-spanner.cc | 120 +++++++++++++----------------- scm/define-grobs.scm | 2 +- 7 files changed, 90 insertions(+), 81 deletions(-) create mode 100644 input/regression/ottava-broken.ly diff --git a/ChangeLog b/ChangeLog index 61d67494e9..321a3d2cf9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,12 @@ -2003-05-25 Han-Wen Nienhuys +2003-05-26 Han-Wen Nienhuys + + * lily/text-spanner.cc (brew_molecule): clean up function. This + fixes bugs with broken 8va spanners. - * lily/gourlay-breaking.cc (combine_demerits): add epsilon term to - force unique solution in zero-force case. + * lily/simple-spacer.cc (solve): also compute force for raggedright. + This prevents spurious line-breaks with raggedright + +2003-05-25 Han-Wen Nienhuys * lily/key-performer.cc (create_audio_elements): always use major key diff --git a/input/regression/ottava-broken.ly b/input/regression/ottava-broken.ly new file mode 100644 index 0000000000..7a6599092d --- /dev/null +++ b/input/regression/ottava-broken.ly @@ -0,0 +1,23 @@ + +\header +{ + +texidoc = "Ottava brackets behave properly at line breaks: no vertical +line, and the horizontal line doesn't stick out." + + +} +\version "1.7.19" + + +\paper { raggedright = ##t} +\score { + \notes\relative c''' \notes { + a2 b + #(set-octavation 1) + a2 b \break c a + #(set-octavation 0) + a b c a +} +} + diff --git a/lily/gourlay-breaking.cc b/lily/gourlay-breaking.cc index 157fda6160..17cd71a5a2 100644 --- a/lily/gourlay-breaking.cc +++ b/lily/gourlay-breaking.cc @@ -236,13 +236,6 @@ Gourlay_breaking::combine_demerits (Column_x_positions const &prev, */ Real demerit = abs (this_one.force_) + abs (prev.force_ - this_one.force_) + break_penalties; - - /* - This is rather ugly (not scale free), but we have to put a - penalty breaking two zero-force lines. Otherwise, we don't get a - unique solution (i.e.: line-breaks in short raggedright - fragments.) - */ if (!this_one.satisfies_constraints_b_) { diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index 893b8cb0fd..a44e9f8d75 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -342,6 +342,10 @@ Simple_spacer::solve (Column_x_positions *positions, bool ragged) */ } + /* + For raggedright, we must have a measure of music density: this is + to prevent lots of short lines (which all have force = 0). + */ if (ragged && line_len_ > 0) { Real len = positions->config_.top (); @@ -351,10 +355,8 @@ Simple_spacer::solve (Column_x_positions *positions, bool ragged) positions->cols_ = spaced_cols_; positions->loose_cols_ = loose_cols_; - positions->satisfies_constraints_b_ = (line_len_ < 0) || active_b (); - /* Check if breaking constraints are met. */ diff --git a/lily/spanner.cc b/lily/spanner.cc index fdd02cc3e0..5882795d0a 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -274,7 +274,7 @@ Spanner::get_broken_left_end_align () const // Relevant only if left span point is first column in line if (sc != NULL && - sc->break_status_dir () == RIGHT) + sc->break_status_dir () == RIGHT) { /* diff --git a/lily/text-spanner.cc b/lily/text-spanner.cc index 0864d55a3d..792b52f86e 100644 --- a/lily/text-spanner.cc +++ b/lily/text-spanner.cc @@ -50,51 +50,42 @@ Text_spanner::brew_molecule (SCM smob) SCM itp= me->get_grob_property ("if-text-padding"); if (gh_number_p (itp)) padding = gh_scm2double (itp); - - Real broken_left = spanner->get_broken_left_end_align (); - Real width = spanner->spanner_length (); - width -= broken_left; + Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS); + + Interval span_points; Drul_array broken; - Drul_array extra_off; Direction d = LEFT; do { - extra_off [d]=0; Item *b = spanner->get_bound (d); broken[d] = b->break_status_dir () != CENTER; - if (!broken [d]) + if (broken[d]) { - - Interval e = b->extent (b, X_AXIS); - Real r = 0.0; - if (!e.empty_b ()) - r = e[-d] + padding; - - /* Text spanners such as ottava, should span from outer limits of - noteheads, iso (de)cresc. spanners that span the inner space */ - if (me->get_grob_property ("enclose-bounds") != SCM_EOL) - { - width -= d * r; - } - else - { - width += d * r; - extra_off[d] = r; - } + if (d == LEFT) + span_points[d] = spanner->get_broken_left_end_align (); + else + span_points[d] = b->relative_coordinate (common, X_AXIS); } + else + { + bool encl = to_boolean (me->get_grob_property ("enclose-bounds")); + span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d]; + } } while (flip (&d) != LEFT); + +#if 0 + /* + FIXME. - this switch sucks. --hwn + */ // FIXME: ecs tells us -- only for (de)cresc. spanners width += gh_scm2double (me->get_grob_property ("width-correct")); - /* /Ugh */ - - // who is ecs? --hwn +#endif SCM properties = Font_interface::font_alist_chain (me); - SCM edge_text = me->get_grob_property ("edge-text"); Drul_array edge; if (gh_pair_p (edge_text)) @@ -103,18 +94,17 @@ Text_spanner::brew_molecule (SCM smob) do { /* Don't repeat edge text for broken end */ - if (!broken[d]) - { - SCM text = index_get_cell (edge_text, d); - edge[d] = Text_item::text2molecule (me, text, properties); - if (!edge[d].empty_b ()) - edge[d].align_to (Y_AXIS, CENTER); - } + if (broken[d]) + continue; + + SCM text = index_get_cell (edge_text, d); + edge[d] = Text_item::text2molecule (me, text, properties); + if (!edge[d].empty_b ()) + edge[d].align_to (Y_AXIS, CENTER); } while (flip (&d) != LEFT); } - width -= edge[LEFT].extent (X_AXIS).length () - + edge[RIGHT].extent (X_AXIS).length (); + Drul_array shorten; shorten[LEFT] = 0; @@ -123,28 +113,16 @@ Text_spanner::brew_molecule (SCM smob) SCM s = me->get_grob_property ("shorten-pair"); if (gh_pair_p (s)) { - shorten[LEFT] = gh_scm2double (ly_car (s)); - shorten[RIGHT] = gh_scm2double (ly_cdr (s)); - } - - width -= shorten[LEFT] + shorten[RIGHT]; - - if (width < 0) - { - me->warning (_ ("Text_spanner too small")); - width = 0; + span_points[LEFT] += gh_scm2double (ly_car (s)); + span_points[RIGHT] -= gh_scm2double (ly_cdr (s)); } - - /* ugh */ Real thick = me->get_paper ()->get_var ("linethickness"); SCM st = me->get_grob_property ("thickness"); if (gh_number_p (st)) { thick *= gh_scm2double (st); - } - Molecule line = Line_spanner::line_molecule (me, thick, width, 0); Drul_array edge_line; s = me->get_grob_property ("edge-height"); @@ -155,9 +133,12 @@ Text_spanner::brew_molecule (SCM smob) int dir = to_dir (me->get_grob_property ("direction")); do { - Real dx = ( gh_pair_p (ew) ? - gh_scm2double (index_get_cell (ew, d)) * d : - 0 ); + if (broken[d]) + continue; + + Real dx = (gh_pair_p (ew) ? + gh_scm2double (index_get_cell (ew, d)) * d : + 0); Real dy = gh_scm2double (index_get_cell (s, d)) * - dir; if (dy) { @@ -168,20 +149,25 @@ Text_spanner::brew_molecule (SCM smob) } Molecule m; - if (!edge[LEFT].empty_b ()) - m = edge[LEFT]; - - if (!edge_line[LEFT].empty_b ()) - m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0,0); - if (!line.empty_b ()) - m.add_at_edge (X_AXIS, RIGHT, line, - edge_line[LEFT].empty_b () ? 0 : -thick/2, 0); - if (!edge_line[RIGHT].empty_b ()) - m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], -thick/2, 0); - if (!edge[RIGHT].empty_b ()) - m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0, 0); - m.translate_axis (broken_left + extra_off[LEFT] + shorten[LEFT], X_AXIS); + do + { + Interval ext = edge[d].extent (X_AXIS); + + edge[d].translate_axis (span_points[d], X_AXIS); + m.add_molecule (edge[d]); + edge_line[d].translate_axis (span_points[d], X_AXIS); + m.add_molecule (edge_line[d]); + if (!ext.empty_b ()) + span_points[d] += -d * ext[-d]; + } + while (flip (&d) != LEFT); + + Molecule l =Line_spanner::line_molecule (me, thick, + span_points.length (), 0); + l.translate_axis (span_points[LEFT], X_AXIS); + m.add_molecule (l); + m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS); return m.smobbed_copy (); } diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index c08e3f955c..c7ebdc2c4d 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -1074,7 +1074,7 @@ (font-family . roman) (enclose-bounds . #t) (width-correct . 0.0) - (type . dotted-line) + (type . dashed-line) (edge-height . (0 . 1.5)) (direction . 1) (meta . ((interfaces . (text-spanner-interface side-position-interface font-interface spanner-interface)))) -- 2.39.5