/*
This file is part of LilyPond, the GNU music typesetter.
- Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ Copyright (C) 1997--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
LilyPond is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
self_scm_ = SCM_EOL;
immutable_property_alist_ = s.immutable_property_alist_;
- mutable_property_alist_ = ly_deep_copy (s.mutable_property_alist_);
+ mutable_property_alist_ = SCM_EOL;
interfaces_ = s.interfaces_;
object_alist_ = SCM_EOL;
layout_ = 0;
smobify_self ();
+
+ mutable_property_alist_ = ly_deep_copy (s.mutable_property_alist_);
+
}
Grob::~Grob ()
= *unsmob_stencil (scm_call_1 (ly_lily_module_constant ("stencil-whiteout"),
retval.smobbed_copy ()));
}
+
+ SCM id = get_property ("id");
+ if (scm_is_string (id))
+ {
+ SCM expr = scm_list_3 (ly_symbol2scm ("id"),
+ id,
+ retval.expr ());
+
+ retval = Stencil (retval.extent_box (), expr);
+ }
+
}
return retval;
{
if (isinf (y) || isnan (y))
{
- programming_error (_ ("Infinity or NaN encountered"));
+ programming_error ("Infinity or NaN encountered");
return;
}
Interval
Grob::maybe_pure_extent (Grob *refp, Axis a, bool pure, int start, int end)
{
- if (pure && a != Y_AXIS)
- programming_error ("tried to get pure width");
return (pure && a == Y_AXIS) ? pure_height (refp, start, end) : extent (refp, a);
}
Grob *
Grob::common_refpoint (Grob const *s, Axis a) const
{
- /* I don't like the quadratic aspect of this code, but I see no
- other way. The largest chain of parents might be 10 high or so,
- so it shouldn't be a real issue. */
- for (Grob const *c = this; c; c = c->dim_cache_[a].parent_)
- for (Grob const *d = s; d; d = d->dim_cache_[a].parent_)
- if (d == c)
- return (Grob *) d;
- return 0;
+ /* Catching the trivial cases is likely costlier than just running
+ through: one can't avoid going to the respective chain ends
+ anyway. We might save the second run through when the chain ends
+ differ, but keeping track of the ends makes the loop more costly.
+ */
+
+ int balance = 0;
+ Grob const *c;
+ Grob const *d;
+
+ for (c = this; c; ++balance)
+ c = c->dim_cache_[a].parent_;
+
+ for (d = s; d; --balance)
+ d = d->dim_cache_[a].parent_;
+
+ /* Cut down ancestry to same size */
+
+ for (c = this; balance > 0; --balance)
+ c = c->dim_cache_[a].parent_;
+
+ for (d = s; balance < 0; ++balance)
+ d = d->dim_cache_[a].parent_;
+
+ /* Now find point where our lineages converge */
+ while (c != d)
+ {
+ c = c->dim_cache_[a].parent_;
+ d = d->dim_cache_[a].parent_;
+ }
+
+ return (Grob *) c;
}
void
}
}
+/****************************************************************
+ VERTICAL ORDERING
+****************************************************************/
+
+Grob *
+get_maybe_root_vertical_alignment (Grob *g, Grob *maybe)
+{
+ if (!g)
+ return maybe;
+ if (Align_interface::has_interface (g))
+ return get_maybe_root_vertical_alignment (g->get_parent (Y_AXIS), g);
+ return get_maybe_root_vertical_alignment (g->get_parent (Y_AXIS), maybe);
+
+}
+
+Grob *
+Grob::get_root_vertical_alignment (Grob *g)
+{
+ return get_maybe_root_vertical_alignment (g, 0);
+}
+
+Grob *
+Grob::get_vertical_axis_group (Grob *g)
+{
+ if (!g)
+ return 0;
+ if (!g->get_parent (Y_AXIS))
+ return 0;
+ if (Axis_group_interface::has_interface (g)
+ && Align_interface::has_interface (g->get_parent (Y_AXIS)))
+ return g;
+ return get_vertical_axis_group (g->get_parent (Y_AXIS));
+
+}
+
+int
+Grob::get_vertical_axis_group_index (Grob *g)
+{
+ Grob *val = get_root_vertical_alignment (g);
+ if (!val)
+ return -1;
+ Grob *vax = get_vertical_axis_group (g);
+ extract_grob_set (val, "elements", elts);
+ for (vsize i = 0; i < elts.size (); i++)
+ if (elts[i] == vax)
+ return (int) i;
+ g->programming_error ("could not find this grob's vertical axis group in the vertical alignment");
+ return -1;
+}
+
+bool
+Grob::vertical_less (Grob *g1, Grob *g2)
+{
+ return internal_vertical_less (g1, g2, false);
+}
+
+bool
+Grob::pure_vertical_less (Grob *g1, Grob *g2)
+{
+ return internal_vertical_less (g1, g2, true);
+}
+
+bool
+Grob::internal_vertical_less (Grob *g1, Grob *g2, bool pure)
+{
+ Grob *vag = get_root_vertical_alignment (g1);
+ if (!vag)
+ {
+ g1->programming_error ("grob does not belong to a VerticalAlignment?");
+ return false;
+ }
+
+ Grob *ag1 = get_vertical_axis_group (g1);
+ Grob *ag2 = get_vertical_axis_group (g2);
+
+ extract_grob_set (vag, "elements", elts);
+
+ if (ag1 == ag2 && !pure)
+ {
+ Grob *common = g1->common_refpoint (g2, Y_AXIS);
+ return g1->relative_coordinate (common, Y_AXIS) > g2->relative_coordinate (common, Y_AXIS);
+ }
+
+ for (vsize i = 0; i < elts.size (); i++)
+ {
+ if (elts[i] == ag1)
+ return true;
+ if (elts[i] == ag2)
+ return false;
+ }
+
+ g1->programming_error ("could not place this grob in its axis group");
+ return false;
+}
+
/****************************************************************
MESSAGES
****************************************************************/
void
-Grob::warning (string s) const
+Grob::programming_error (string s) const
{
- if (get_program_option ("warning-as-error"))
- error (s);
+ SCM cause = self_scm ();
+ while (Grob *g = unsmob_grob (cause))
+ cause = g->get_property ("cause");
+
+ /* ES TODO: cause can't be Music*/
+ if (Music *m = unsmob_music (cause))
+ m->origin ()->programming_error (s);
+ else if (Stream_event *ev = unsmob_stream_event (cause))
+ ev->origin ()->programming_error (s);
+ else
+ ::programming_error (s);
+}
+void
+Grob::warning (string s) const
+{
SCM cause = self_scm ();
while (Grob *g = unsmob_grob (cause))
cause = g->get_property ("cause");
return scm_is_symbol (nm) ? ly_symbol2string (nm) : this->class_name ();
}
-void
-Grob::programming_error (string s) const
-{
- if (get_program_option ("warning-as-error"))
- error (s);
-
- SCM cause = self_scm ();
- while (Grob *g = unsmob_grob (cause))
- cause = g->get_property ("cause");
-
- s = _f ("programming error: %s", s);
-
- /* ES TODO: cause can't be Music*/
- if (Music *m = unsmob_music (cause))
- m->origin ()->message (s);
- else if (Stream_event *ev = unsmob_stream_event (cause))
- ev->origin ()->message (s);
- else
- ::message (s);
-}
-
ADD_INTERFACE (Grob,
"A grob represents a piece of music notation.\n"
"\n"
"cause "
"color "
"cross-staff "
+ "id "
"extra-X-extent "
"extra-Y-extent "
"extra-offset "
+ "footnote-music "
+ "forced-spacing "
"interfaces "
"layer "
"meta "