source file of the GNU LilyPond music typesetter
- (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
*/
#include "axis-group-interface.hh"
#include "grob-array.hh"
#include "hara-kiri-group-spanner.hh"
#include "international.hh"
+#include "lookup.hh"
#include "paper-column.hh"
#include "paper-score.hh"
#include "separation-item.hh"
+#include "stencil.hh"
#include "system.hh"
#include "warn.hh"
for (vsize i = 0; i < elts.size (); i++)
{
Grob *se = elts[i];
- Interval dims = se->extent (common, a);
- if (!dims.is_empty ())
- r.unite (dims);
+ if (!to_boolean (se->get_property ("cross-staff")))
+ {
+ Interval dims = se->extent (common, a);
+ if (!dims.is_empty ())
+ r.unite (dims);
+ }
}
return r;
}
+
+/*
+ FIXME: pure extent handling has a lot of ad-hoc caching.
+ This should be done with grob property callbacks.
+
+ --hwn
+*/
+
Interval
Axis_group_interface::cached_pure_height (Grob *me,
vector<Grob*> const &elts,
if (!scm_is_vector (extents))
{
extents = scm_c_make_vector (breaks.size () - 1, SCM_EOL);
- for (vsize i = 0; i < breaks.size () - 1; i++)
+ for (vsize i = 0; i + 1 < breaks.size (); i++)
{
int st = Paper_column::get_rank (cols[breaks[i]]);
int ed = Paper_column::get_rank (cols[breaks[i+1]]);
for (vsize i = 0; i < elts.size (); i++)
{
- Interval_t<int> rank_span = elts[i]->spanned_rank_iv ();
+ Interval_t<int> rank_span = elts[i]->spanned_rank_interval ();
Item *it = dynamic_cast<Item*> (elts[i]);
if (rank_span[LEFT] <= end && rank_span[RIGHT] >= start && (!it || it->pure_is_visible (start, end)))
{
int end = robust_scm2int (end_scm, INT_MAX);
Grob *me = unsmob_grob (smob);
+ /* Maybe we are in the second pass of a two-pass spacing run. In that
+ case, the Y-extent of a system is already given to us */
+ System *system = dynamic_cast<System*> (me);
+ if (system)
+ {
+ SCM line_break_details = system->column (start)->get_property ("line-break-system-details");
+ SCM system_y_extent = scm_assq (ly_symbol2scm ("system-Y-extent"), line_break_details);
+ if (scm_is_pair (system_y_extent))
+ return scm_cdr (system_y_extent);
+ }
+
return pure_group_height (me, start, end);
}
{
Grob *me = unsmob_grob (smob);
extract_grob_set (me, "elements", elts);
- return skyline_spacing (me, elts).smobbed_copy ();
+ Skyline_pair skylines = skyline_spacing (me, elts);
+
+ /* add a minimum-Y-extent-sized box to the skyline */
+ SCM min_y_extent = me->get_property ("minimum-Y-extent");
+ if (is_number_pair (min_y_extent))
+ {
+ Box b (me->extent (me, X_AXIS), ly_scm2interval (min_y_extent));
+ skylines.insert (b, 0, X_AXIS);
+ }
+ return skylines.smobbed_copy ();
}
/* whereas calc_skylines calculates skylines for axis-groups with a lot of
Skyline_pair ret;
for (vsize i = 0; i < elements.size (); i++)
{
- SCM skyline_scm = elements[i]->get_property ("skylines");
+ SCM skyline_scm = elements[i]->get_property ("vertical-skylines");
if (Skyline_pair::unsmob (skyline_scm))
{
Real offset = elements[i]->relative_coordinate (y_common, Y_AXIS);
Axis_group_interface::generic_group_extent (Grob *me, Axis a)
{
/* trigger the callback to do skyline-spacing on the children */
- (void) me->get_property ("skylines");
+ if (a == Y_AXIS)
+ (void) me->get_property ("vertical-skylines");
extract_grob_set (me, "elements", elts);
Grob *common = common_refpoint_of_array (elts, me, a);
return common;
}
-MAKE_SCHEME_CALLBACK(Axis_group_interface,calc_y_common, 1);
+MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_x_common, 1);
+SCM
+Axis_group_interface::calc_x_common (SCM grob)
+{
+ Grob *me = unsmob_grob (grob);
+
+ extract_grob_set (me, "elements", elts);
+ Grob *common = common_refpoint_of_array (elts, me, X_AXIS);
+ return common->self_scm ();
+}
+
+MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_y_common, 1);
SCM
Axis_group_interface::calc_y_common (SCM grob)
{
Grob *me = unsmob_grob (grob);
extract_grob_set (me, "elements", elts);
- return common_refpoint_of_array (elts, me, Y_AXIS)->self_scm ();
+ Grob *common = common_refpoint_of_array (elts, me, Y_AXIS);
+ return common->self_scm ();
}
SCM
else if (priority_1 > priority_2)
return false;
+ /* if neither grob has an outside-staff priority, the ordering will have no
+ effect -- we just need to choose a consistent ordering. We do this to
+ avoid the side-effect of calculating extents. */
+ if (isinf (priority_1))
+ return g1 < g2;
+
/* if there is no preference in staff priority, choose the left-most one */
Grob *common = g1->common_refpoint (g2, X_AXIS);
Real start_1 = g1->extent (common, X_AXIS)[LEFT];
}
static void
-add_boxes (Grob *me, Grob *x_common, Grob *y_common, vector<Box> *const boxes)
+add_boxes (Grob *me, Grob *x_common, Grob *y_common, vector<Box> *const boxes, Skyline_pair *skylines)
{
- /* if we are a parent, consider the children's boxes instead of mine */
- if (Grob_array *elements = unsmob_grob_array (me->get_object ("elements")))
+ /* if a child has skylines, use them instead of the extent box */
+ if (Skyline_pair *pair = Skyline_pair::unsmob (me->get_property ("vertical-skylines")))
+ {
+ Skyline_pair s = *pair;
+ s.shift (me->relative_coordinate (x_common, X_AXIS));
+ s.raise (me->relative_coordinate (y_common, Y_AXIS));
+ skylines->merge (s);
+ }
+ else if (Grob_array *elements = unsmob_grob_array (me->get_object ("elements")))
{
for (vsize i = 0; i < elements->size (); i++)
- add_boxes (elements->grob (i), x_common, y_common, boxes);
+ add_boxes (elements->grob (i), x_common, y_common, boxes, skylines);
+ }
+ else if (!scm_is_number (me->get_property ("outside-staff-priority"))
+ && !to_boolean (me->get_property ("cross-staff")))
+ {
+ boxes->push_back (Box (me->extent (x_common, X_AXIS),
+ me->extent (y_common, Y_AXIS)));
}
- else if (!scm_is_number (me->get_property ("outside-staff-priority")))
- boxes->push_back (Box (me->extent (x_common, X_AXIS),
- me->extent (y_common, Y_AXIS)));
}
/* We want to avoid situations like this:
if (b[X_AXIS][LEFT] - 2*horizon_padding < last_affected_position[dir])
continue;
- if (b[X_AXIS].is_empty () || b[Y_AXIS].is_empty ())
- warning (_f ("outside-staff object %s has an empty extent", elements[i]->name ().c_str ()));
- else
+ if (!b[X_AXIS].is_empty () && !b[Y_AXIS].is_empty ())
{
boxes.clear ();
boxes.push_back (b);
vsize i = 0;
vector<Box> boxes;
+ Skyline_pair skylines;
for (i = 0; i < elements.size ()
&& !scm_is_number (elements[i]->get_property ("outside-staff-priority")); i++)
- add_boxes (elements[i], x_common, y_common, &boxes);
+ add_boxes (elements[i], x_common, y_common, &boxes, &skylines);
- Skyline_pair skylines (boxes, 0, X_AXIS);
+ SCM padding_scm = me->get_property ("skyline-horizontal-padding");
+ Real padding = robust_scm2double (padding_scm, 0.1);
+ skylines.merge (Skyline_pair (boxes, padding, X_AXIS));
for (; i < elements.size (); i++)
{
SCM priority = elements[i]->get_property ("outside-staff-priority");
vector<Grob*> current_elts;
current_elts.push_back (elements[i]);
- while (i < elements.size () - 1
+ while (i + 1 < elements.size ()
&& scm_eq_p (elements[i+1]->get_property ("outside-staff-priority"), priority))
current_elts.push_back (elements[++i]);
add_grobs_of_one_priority (&skylines, current_elts, x_common, y_common);
}
+ skylines.shift (-me->relative_coordinate (x_common, X_AXIS));
return skylines;
}
+MAKE_SCHEME_CALLBACK (Axis_group_interface, calc_max_stretch, 1)
+SCM
+Axis_group_interface::calc_max_stretch (SCM smob)
+{
+ Grob *me = unsmob_grob (smob);
+ Real ret = 0;
+ extract_grob_set (me, "elements", elts);
+
+ for (vsize i = 0; i < elts.size (); i++)
+ if (Axis_group_interface::has_interface (elts[i]))
+ ret += robust_scm2double (elts[i]->get_property ("max-stretch"), 0.0);
+
+ return scm_from_double (ret);
+}
+
+extern bool debug_skylines;
+MAKE_SCHEME_CALLBACK (Axis_group_interface, print, 1)
+SCM
+Axis_group_interface::print (SCM smob)
+{
+ if (!debug_skylines)
+ return SCM_BOOL_F;
+
+ Grob *me = unsmob_grob (smob);
+ Stencil ret;
+ if (Skyline_pair *s = Skyline_pair::unsmob (me->get_property ("vertical-skylines")))
+ {
+ ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[UP].to_points (X_AXIS)).in_color (255, 0, 255));
+ ret.add_stencil (Lookup::points_to_line_stencil (0.1, (*s)[DOWN].to_points (X_AXIS)).in_color (0, 255, 255));
+ }
+ return ret.smobbed_copy ();
+}
+
ADD_INTERFACE (Axis_group_interface,
"An object that groups other layout objects.",
"Y-common "
"axes "
"elements "
+ "keep-fixed-while-stretching "
+ "max-stretch "
"pure-Y-common "
"pure-relevant-elements "
- "skylines "
+ "vertical-skylines "
"cached-pure-extents "
);