#include <math.h>
+
+#include "break-align-interface.hh"
#include <libc-extension.hh> // isinf
#include "self-alignment-interface.hh"
#include "side-position-interface.hh"
#include "axis-group-interface.hh"
#include "warn.hh"
-#include "lily-guile.hh"
-#include "break-align-interface.hh"
#include "dimensions.hh"
-#include "paper-def.hh"
+#include "output-def.hh"
#include "paper-column.hh"
-#include "group-interface.hh"
#include "align-interface.hh"
MAKE_SCHEME_CALLBACK (Break_align_interface,alignment_callback,2);
Break_align_interface::alignment_callback (SCM element_smob, SCM axis)
{
Grob *me = unsmob_grob (element_smob);
- Axis a = (Axis) gh_scm2int (axis);
+ Axis a = (Axis) scm_to_int (axis);
assert (a == X_AXIS);
Grob *par = me->get_parent (a);
Break_align_interface::do_alignment (par);
}
- return gh_double2scm (0);
+ return scm_make_real (0);
}
MAKE_SCHEME_CALLBACK (Break_align_interface,self_align_callback,2);
Break_align_interface::self_align_callback (SCM element_smob, SCM axis)
{
Grob *me = unsmob_grob (element_smob);
- Axis a = (Axis) gh_scm2int (axis);
+ Axis a = (Axis) scm_to_int (axis);
assert (a == X_AXIS);
Item* item = dynamic_cast<Item*> (me);
}
-void
-Break_align_interface::order_elements (Grob *grob)
+/*
+ This is tricky: we cannot modify 'elements, since callers are
+ iterating the same list. Reordering the list in-place, or resetting
+ 'elements will skip elements in the loops of callers.
+
+ So we return the correct order as an array.
+ */
+Link_array<Grob>
+Break_align_interface::ordered_elements (Grob *grob)
{
Item *me = dynamic_cast<Item*> (grob);
SCM elts = me->get_property ("elements");
SCM order_vec = me->get_property ("break-align-orders");
- if (!gh_vector_p (order_vec)
- || gh_vector_length (order_vec) < 3)
- return ;
-
+ if (!ly_c_vector_p (order_vec)
+ || ly_vector_length (order_vec) < 3)
+ return Pointer_group_interface__extract_grobs (me, (Grob*)0,
+ "elements");
SCM order = scm_vector_ref (order_vec,
- gh_int2scm (me->break_status_dir() + 1));
+ scm_int2num (me->break_status_dir() + 1));
+
/*
- Copy in order specified in BREAK-ALIGN-ORDER. We use
- Pointer_group_interface__extract_grobs (which reverses the list)
- down the line, so it's ok to prepend onto newlist.
- */
- SCM new_list = SCM_EOL;
- for (; gh_pair_p (order); order = ly_cdr (order))
+ Copy in order specified in BREAK-ALIGN-ORDER.
+ */
+ Link_array<Grob> new_elts;
+ for (; scm_is_pair (order); order = scm_cdr (order))
{
- SCM sym = gh_car (order);
-
- SCM *tail = &elts;
- for (; gh_pair_p (*tail); tail = SCM_CDRLOC(*tail))
+ SCM sym = scm_car (order);
+
+ for (SCM s =elts; scm_is_pair (s); s = scm_cdr (s))
{
- Grob * g = unsmob_grob (gh_car (*tail));
- if (sym == g->get_property ("break-align-symbol"))
+ Grob *g = unsmob_grob (scm_car (s));
+ if (g && sym == g->get_property ("break-align-symbol"))
{
- SCM new_pair = *tail;
- *tail = gh_cdr (*tail);
- if (gh_pair_p (*tail))
- tail = SCM_CDRLOC(*tail);
-
- gh_set_cdr_x (new_pair, new_list);
- new_list = new_pair;
- break;
+ new_elts.push (g);
+ elts = scm_delq (g->self_scm (), elts);
}
}
}
-
- new_list = scm_reverse_x (elts, new_list);
- me->set_property ("elements", new_list);
+ return new_elts;
}
void
{
Item * me = dynamic_cast<Item*> (grob);
- order_elements (me);
- Link_array<Grob> elems
- = Pointer_group_interface__extract_grobs (me, (Grob*)0,
- "elements");
+ Link_array<Grob> elems = ordered_elements (me);
Array<Interval> extents;
int last_nonempty = -1;
- for (int i=0; i < elems.size (); i++)
+ for (int i= 0; i < elems.size (); i++)
{
Interval y = elems[i]->extent (elems[i], X_AXIS);
extents.push (y);
/*
Find the first grob with a space-alist entry.
*/
- for (SCM s= l->get_property ("elements");
- gh_pair_p (s) ; s = gh_cdr (s))
+ for (SCM s = l->get_property ("elements");
+ scm_is_pair (s) ; s = scm_cdr (s))
{
- Grob *elt = unsmob_grob (gh_car (s));
+ Grob *elt = unsmob_grob (scm_car (s));
if (edge_idx < 0
&& elt->get_property ("break-align-symbol")
edge_idx = idx;
SCM l =elt->get_property ("space-alist");
- if (gh_pair_p (l))
+ if (scm_is_pair (l))
{
alist= l;
break;
reason.
*/
for (SCM s = r ? r->get_property ("elements") : SCM_EOL;
- !gh_symbol_p (rsym) && gh_pair_p (s); s = gh_cdr (s))
+ !scm_is_symbol (rsym) && scm_is_pair (s); s = scm_cdr (s))
{
- Grob * elt =unsmob_grob (gh_car (s));
+ Grob * elt =unsmob_grob (scm_car (s));
rsym = elt->get_property ("break-align-symbol");
}
edge_idx = next_idx;
SCM entry = SCM_EOL;
- if (gh_symbol_p (rsym))
+ if (scm_is_symbol (rsym))
entry = scm_assq (rsym, alist);
- bool entry_found = gh_pair_p (entry);
+ bool entry_found = scm_is_pair (entry);
if (!entry_found)
{
String sym_string;
- if (gh_symbol_p (rsym))
+ if (scm_is_symbol (rsym))
sym_string = ly_symbol2string (rsym);
String orig_string ;
if (entry_found)
{
- entry = gh_cdr (entry);
+ entry = scm_cdr (entry);
- distance = gh_scm2double (gh_cdr (entry));
- type = gh_car (entry) ;
+ distance = scm_to_double (scm_cdr (entry));
+ type = scm_car (entry) ;
}
if (r)
Real here = 0.0;
Interval total_extent;
- Real alignment_off =0.0;
- for (int i =0 ; i < offsets.size (); i++)
+ Real alignment_off = 0.0;
+ for (int i = 0 ; i < offsets.size (); i++)
{
here += offsets[i];
if (i == edge_idx)
alignment_off = -total_extent[LEFT];
here = alignment_off;
- for (int i =0 ; i < offsets.size (); i++)
+ for (int i = 0 ; i < offsets.size (); i++)
{
here += offsets[i];
elems[i]->translate_axis (here, X_AXIS);