-
-static SCM
-c_ragged_page_breaks (SCM lines,
- Paper_book *book,
- Real text_height,
- Real first, Real last)
-{
- int page_number = 0;
-
- Real book_height =0.;
- for (SCM s = lines ; ly_c_pair_p (s); s = ly_cdr (s))
- {
- book_height += unsmob_paper_line (ly_car (s))->dim ()[Y_AXIS];
- }
-
- /*
- UGH. following stuff should go out of C++.
- */
- SCM scopes = SCM_EOL;
- if (ly_c_module_p (book->header_))
- scopes = scm_cons (book->header_, scopes);
-
-
- SCM tag = make_tagline (book->bookpaper_, scopes);
- if (unsmob_stencil (tag))
- {
- book_height += unsmob_stencil (tag)->extent (Y_AXIS).length ();
- }
-
- SCM cr = make_copyright (book->bookpaper_, scopes);
- if (unsmob_stencil (cr))
- {
- book_height += unsmob_stencil (cr)->extent (Y_AXIS).length ();
- }
-
- int page_count = int (book_height / text_height + 0.5); // ceil?
- SCM breaks = SCM_EOL;
- Real page_height = text_height + first;
- Real h = 0;
- int number = 0;
- for (SCM s = lines; ly_c_pair_p (s); s = ly_cdr (s))
- {
- Paper_line *pl = unsmob_paper_line (ly_car (s));
- if (!pl->is_title () && h < page_height)
- number++;
- h += pl->dim ()[Y_AXIS];
- if (!pl->is_title () && h > page_height)
- {
- breaks = ly_snoc (scm_int2num (number), breaks);
- page_number++;
- page_height = text_height + (page_number == page_count) * last;
- h = 0;
- }
- if (ly_cdr (s) == SCM_EOL)
- breaks = ly_snoc (scm_int2num (pl->number_), breaks);
- }
-
- return scm_vector (breaks);
-}
-
-LY_DEFINE (ly_ragged_page_breaks, "ly:ragged-page-breaks",
- 5, 0, 0, (SCM lines, SCM book, SCM text, SCM first, SCM last),
- "Return a vector with line numbers of page breaks.")
-{
- Paper_book* b = unsmob_paper_book (book);
-
- SCM_ASSERT_TYPE (scm_pair_p (lines), lines, SCM_ARG1, __FUNCTION__, "list");
- SCM_ASSERT_TYPE (b, book, SCM_ARG2, __FUNCTION__, "Paper_book");
- SCM_ASSERT_TYPE (ly_c_number_p (text), text, SCM_ARG3, __FUNCTION__, "number");
- SCM_ASSERT_TYPE (ly_c_number_p (first), first, SCM_ARG4, __FUNCTION__, "number");
- SCM_ASSERT_TYPE (ly_c_number_p (last), last, SCM_ARG5, __FUNCTION__, "number");
-
- return c_ragged_page_breaks (lines, b,
- ly_scm2double (text),
- ly_scm2double (first), ly_scm2double (last));
-}
-