(c) 1999 Glen Prideaux <glenprideaux@iname.com>
- (adapted from extender-spanner)
+ (adapted from lyric-extender)
*/
-/*
- TODO: too complicated implementation. Why the dx_drul?.
- */
-
#include <math.h>
+
#include "box.hh"
-#include "debug.hh"
#include "lookup.hh"
#include "molecule.hh"
-#include "paper-column.hh"
#include "paper-def.hh"
#include "hyphen-spanner.hh"
-#include "dimension-cache.hh"
-
-Hyphen_spanner::Hyphen_spanner ()
- : Spanner ()
-{
- dx_f_drul_[LEFT] = dx_f_drul_[RIGHT] = 0.0;
-
- dim_cache_[Y_AXIS]->set_extent_callback (Dimension_cache::point_dimension_callback);
-}
-
-Molecule
-Hyphen_spanner::do_brew_molecule () const
-{
- Molecule mol;
-
- Real w = spanner_length ();
-
- w += (dx_f_drul_[RIGHT] - dx_f_drul_[LEFT]);
-
- Real th = paper_l ()->get_var ("hyphen_thickness");
- Real h = paper_l ()->get_var ("hyphen_height");
-
- // UGH. First try: just make the hyphen take 1/3 of the available space
- // for length, use a geometric mean of the available space and some minimum
- Real l = paper_l ()->get_var ("hyphen_minimum_length");
- if(l < w)
- l = sqrt(l*w);
- Molecule a = lookup_l ()->filledbox ( Box (Interval ((w-l)/2,(w+l)/2), Interval (h,h+th)));
- a.translate (Offset (dx_f_drul_[LEFT], 0));
-
- mol.add_molecule (a);
-
- return mol;
-}
+#include "paper-column.hh"
+#include "spanner.hh"
+#include "item.hh"
+MAKE_SCHEME_CALLBACK(Hyphen_spanner,brew_molecule,1)
-void
-Hyphen_spanner::after_line_breaking ()
+SCM
+Hyphen_spanner::brew_molecule (SCM smob)
{
- // UGH
- Real gap = paper_l ()->get_var ("interline");
+ Spanner * sp = dynamic_cast<Spanner*> (unsmob_grob (smob));
+ Grob * common = sp;
Direction d = LEFT;
do
{
- Item* t = get_bound (d)
- ? get_bound (d) : get_bound ((Direction)-d);
- if (d == LEFT)
- dx_f_drul_[d] += t->extent (X_AXIS).length ();
- else
- dx_f_drul_[d] -= d * gap / 2;
+ common = common->common_refpoint( sp->get_bound (d), X_AXIS);
}
- while (flip(&d) != LEFT);
+ while (flip (&d) != LEFT);
+ Interval bounds;
+
+ do
+ {
+ bounds[d] = sp->get_bound (d)->extent (common, X_AXIS)[-d];
+ }
+ while (flip (&d) != LEFT);
+
+ Real lt = sp->paper_l ()->get_var ("stafflinethickness");
+ Real th = gh_scm2double (sp->get_grob_property ("thickness")) * lt ;
+ Real h = gh_scm2double (sp->get_grob_property ("height"));
+ Real l = gh_scm2double (sp->get_grob_property ("minimum-length"));
+ // The hyphen can exist in the word space of the left lyric ...
+ SCM space = sp->get_bound (LEFT)->get_grob_property ("word-space");
+ if (gh_number_p (space))
+ {
+ bounds[LEFT] -= gh_scm2double (space);
+ }
+ Real w = bounds.length ();
+ /* for length, use a geometric mean of the available space and some minimum
+ */
+ if(l < w)
+ l = sqrt(l*w);
+ else
+ {
+ /* OK, we have a problem. Usually this means that we're on the
+ first column, and we have a long lyric which extends to near
+ the offset for stuff */
+ /* This test for being on the first column has been shamelessly
+ ripped from spanner.cc */
+ Paper_column *sc = dynamic_cast<Paper_column*> (sp->get_bound(LEFT)->column_l());
+ if (sc != NULL &&
+ sc->break_status_dir () == RIGHT)
+ {
+ /* We are on the first column, so it's probably harmless to
+ get the minimum length back by extending leftwards into
+ the space under the clef/key sig/time sig */
+ bounds[LEFT] = bounds[RIGHT] - l;
+ }
+ else
+ {
+ /* We can't get the length desired. Maybe we should warn. */
+ l = w;
+ }
+ }
+ Box b (Interval (-l/2,l/2), Interval (h,h+th));
+ Molecule mol (Lookup::filledbox (b));
+ mol.translate_axis (bounds.center ()
+ -sp->relative_coordinate (common, X_AXIS),
+ X_AXIS);
+ return mol.smobbed_copy ();
}
-
void
-Hyphen_spanner::set_textitem (Direction d, Item* textitem_l)
+Hyphen_spanner::set_textitem (Direction d, Grob* b)
{
- set_bound (d, textitem_l);
- add_dependency (textitem_l);
+ elt_l_->set_bound (d, b);
+ elt_l_->add_dependency (b);
}
+Hyphen_spanner::Hyphen_spanner (Spanner*s)
+{
+ elt_l_ = s;
+}