Paper_book::Paper_book ()
{
- pages_ = SCM_EOL;
- lines_ = SCM_EOL;
+ pages_ = SCM_BOOL_F;
+ lines_ = SCM_BOOL_F;
copyright_ = SCM_EOL;
tagline_ = SCM_EOL;
header_ = SCM_EOL;
return lst;
}
-
-
/*
TODO: there is too much code dup, and the interface is not
{
if (!score_lines_.size ())
return;
-
+
+
/* Generate all stencils to trigger font loads. */
pages ();
SCM formats = ly_output_formats();
for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s))
{
-
String format = ly_scm2string (ly_car (s));
Paper_outputter *out = get_paper_outputter (outname + "." + format, format);
-
SCM scopes = SCM_EOL;
if (ly_c_module_p (header_))
return title;
}
-
SCM
Paper_book::lines ()
{
- if (ly_c_pair_p (lines_))
+ if (SCM_BOOL_F != lines_)
return lines_;
- Stencil title = book_title ();
+ lines_ = SCM_EOL;
+ Stencil title = book_title ();
+
if (!title.is_empty ())
{
- Paper_line *pl = new Paper_line (title, -10001, true);
+ Paper_line *pl = new Paper_line (title, true);
lines_ = scm_cons (pl->self_scm (), lines_);
scm_gc_unprotect_object (pl->self_scm ());
Stencil title = score_title (i);
if (!title.is_empty ())
{
- Paper_line *pl = new Paper_line (title, -10001, true);
+ Paper_line *pl = new Paper_line (title, true);
lines_ = scm_cons (pl->self_scm (), lines_);
scm_gc_unprotect_object (pl->self_scm ());
}
if (scm_vector_p (score_lines_[i].lines_) == SCM_BOOL_T)
{
SCM line_list = scm_vector_to_list (score_lines_[i].lines_); // guh.
- lines_ = scm_append (scm_list_2 (scm_reverse (line_list), lines_));
+
+ line_list = scm_reverse (line_list);
+ lines_ = scm_append (scm_list_2 (line_list, lines_));
}
}
lines_ = scm_reverse (lines_);
-
+
int i = 0;
+ Paper_line * last = 0;
for (SCM s = lines_; s != SCM_EOL; s = ly_cdr (s))
- unsmob_paper_line (ly_car (s))->number_ = ++i;
+ {
+ Paper_line * p = unsmob_paper_line (ly_car (s));
+ p->number_ = ++i;
+
+ if (last && last->is_title ())
+ {
+ p->penalty_ = 10000; // ugh, hardcoded.
+ }
+ last = p;
+ }
+
+
return lines_;
}
SCM
Paper_book::pages ()
{
- if (ly_c_pair_p (pages_))
+ if (SCM_BOOL_F != pages_)
return pages_;
+ pages_ = SCM_EOL;
+
Output_def *paper = bookpaper_;
- Page *page = new Page (paper, 1);
+
+ // dummy to extract dims
+ Page *page = new Page (SCM_EOL, paper, 1); // ugh
Real text_height = page->text_height ();
Real copy_height = 0;
if (Stencil *s = unsmob_stencil (tagline_))
tag_height = s->extent (Y_AXIS).length ();
- SCM all = lines ();
- SCM proc = paper->c_variable ("page-breaking");
- SCM breaks = scm_apply_0 (proc, scm_list_n (all,
- self_scm (),
- scm_make_real (text_height),
- scm_make_real (-copy_height),
- scm_make_real (-tag_height),
- SCM_UNDEFINED));
-
+ scm_gc_unprotect_object (page->self_scm ());
/*
UGH - move this out of C++.
tagline_ = make_tagline (bookpaper_, scopes);
copyright_ = make_tagline (bookpaper_, scopes);
- int page_count = SCM_VECTOR_LENGTH ((SCM) breaks);
- int line = 1;
- for (int i = 0; i < page_count; i++)
+ SCM all = lines ();
+ SCM proc = paper->c_variable ("page-breaking");
+ SCM pages = scm_apply_0 (proc, scm_list_n (all,
+ self_scm (),
+ scm_make_real (text_height),
+ scm_make_real (-copy_height),
+ scm_make_real (-tag_height),
+ SCM_UNDEFINED));
+
+
+ SCM *page_tail = &pages_;
+ int num = 0;
+ for (SCM s = pages; ly_c_pair_p (s); s = ly_cdr (s))
{
- if (i)
- page = new Page (paper, i + 1);
+ Page * page = new Page (ly_car (s), paper, ++num);
+
+ *page_tail = scm_cons (page->self_scm () , SCM_EOL);
+ page_tail = SCM_CDRLOC(*page_tail);
- int next = i + 1 < page_count
- ? ly_scm2int (scm_vector_ref (breaks, scm_int2num (i))) : 0;
- while ((!next && all != SCM_EOL) || line <= next)
- {
- SCM s = ly_car (all);
- page->lines_ = ly_snoc (s, page->lines_);
- page->height_ += unsmob_paper_line (s)->dim ()[Y_AXIS];
- page->line_count_++;
- all = ly_cdr (all);
- line++;
- }
- if (i == page_count-1)
+ scm_gc_unprotect_object (page->self_scm ());
+
+ if (!ly_c_pair_p (ly_cdr (s)))
page->is_last_ = true;
-
- pages_ = scm_cons (page->self_scm (), pages_);
}
- pages_ = scm_reverse (pages_);
return pages_;
}