but convert to single Stencil immediately.
* lily/paper-book.cc (title): don't return Stencil* but Stencil.
+2004-05-08 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * lily/paper-line.cc (Paper_line): don't store list of stencils,
+ but convert to single Stencil immediately.
+
+ * lily/paper-book.cc (title): don't return Stencil* but Stencil.
+
2004-05-07 Jan Nieuwenhuizen <janneke@gnu.org>
* scm/output-sodipodi.scm: Resurrect sodipodi output.
#include "input.hh"
#include "lily-proto.hh"
-
#include "parray.hh"
#include "smobs.hh"
My_lily_parser (My_lily_parser const&);
DECLARE_SCHEME_CALLBACK (paper_description, ());
-
+
Input here_input () const;
Input pop_spot ();
void beam_check (SCM);
SCM ly_parser_bookify (SCM, SCM);
SCM ly_parser_scorify (SCM, SCM);
+Music_output_def *get_paper (My_lily_parser *parser);
+
#endif /* MY_LILY_PARSER_HH */
SCM lines ();
SCM pages ();
SCM scopes (int);
- Stencil *title (int);
+ Stencil title (int);
void classic_output (String);
void init ();
void output (String);
#include "lily-proto.hh"
#include "smobs.hh"
#include "offset.hh"
+#include "stencil.hh"
class Paper_line
{
DECLARE_SMOBS (Paper_line, );
- SCM stencils_;
- Offset dim_;
+ Stencil stencil_;
bool is_title_;
int penalty_;
SCHEME is a Scheme expression that --when eval'd-- produces the
desired output.
-
- Because of the way that Stencil is implemented, it is the most
- efficient to add "fresh" stencils to what you're going to build.
+ Notes:
- Dimension behavior:
+ * Because of the way that Stencil is implemented, it is the most
+ efficient to add "fresh" stencils to what you're going to build.
- Empty stencils have empty dimensions. If add_at_edge is used to
+ * Do not create Stencil objects on the heap. That includes passing
+ around Stencil* which are produced by unsmob_stencil().
+
+ * Empty stencils have empty dimensions. If add_at_edge is used to
init the stencil, we assume that
- DIMENSIONS = (Interval (0,0),Interval (0,0)
+
+ DIMENSIONS = (Interval (0,0),Interval (0,0)
*/
class Stencil
{
#undef FUNC_NAME
}
+/*
+ Lookup SYM in a list of modules, which do not have to be related.
+ Return the first instance.
+ */
SCM
ly_modules_lookup (SCM modules, SCM sym)
{
// JUNKME
SCM
-stencil2line (Stencil *stil, bool is_title = false)
+stencil2line (Stencil stil, bool is_title = false)
{
static SCM z;
if (!z)
z = scm_permanent_object (ly_offset2scm (Offset (0, 0)));
- Offset dim = Offset (stil->extent (X_AXIS).length (),
- stil->extent (Y_AXIS).length ());
- Paper_line *pl = new Paper_line (dim, scm_cons (stil->smobbed_copy (),
+ Offset dim = Offset (stil.extent (X_AXIS).length (),
+ stil.extent (Y_AXIS).length ());
+ Paper_line *pl = new Paper_line (dim, scm_cons (stil.smobbed_copy (),
SCM_EOL),
-10001 * is_title, is_title);
return scopes;
}
-Stencil*
+Stencil
Paper_book::title (int i)
{
+ /*
+ TODO: get from book-paper definition.
+ */
SCM user_title = ly_scheme_function ("user-title");
SCM book_title = ly_scheme_function ("book-title");
SCM score_title = ly_scheme_function ("score-title");
SCM field = (i == 0 ? ly_symbol2scm ("bookTitle")
: ly_symbol2scm ("scoreTitle"));
- Stencil *title = 0;
+ Stencil title;
SCM scopes = this->scopes (i);
SCM s = ly_modules_lookup (scopes, field);
if (s != SCM_UNDEFINED && scm_variable_bound_p (s) == SCM_BOOL_T)
- title = unsmob_stencil (scm_call_2 (user_title,
+ title = *unsmob_stencil (scm_call_2 (user_title,
papers_[0]->self_scm (),
scm_variable_ref (s)));
else
- title = unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title,
+ title = *unsmob_stencil (scm_call_2 (i == 0 ? book_title : score_title,
papers_[0]->self_scm (),
scopes));
- if (title)
- title->align_to (Y_AXIS, UP);
+ if (!title.is_empty ())
+ title.align_to (Y_AXIS, UP);
return title;
}
height_ = 0;
for (int i = 0; i < score_count; i++)
{
- Stencil *title = this->title (i);
- if (title)
- height_ += title->extent (Y_AXIS).length ();
+ Stencil title = this->title (i);
+ if (!title.is_empty ())
+ height_ += title.extent (Y_AXIS).length ();
int line_count = SCM_VECTOR_LENGTH ((SCM) scores_[i]);
for (int j = 0; j < line_count; j++)
SCM lines = SCM_EOL;
for (int i = 0; i < score_count; i++)
{
- if (Stencil *title = this->title (i))
+ Stencil title = this->title (i);
+ if (!title.is_empty ())
lines = ly_snoc (stencil2line (title, true), lines);
lines = scm_append (scm_list_2 (lines, scm_vector_to_list (scores_[i])));
}
Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
{
- dim_ = o;
- stencils_ = stencils;
is_title_ = is_title;
penalty_ = penalty;
smobify_self ();
+
+
+ /*
+ TODO: we should extend the definition of stencil to allow
+
+ stencil-expr: LISTOF stencil-expr*
+
+ so that we don't use as much memory for combining the stencils, and
+ can do this conversion in constant time.
+ */
+ for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
+ stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
+
+ Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
+ stencil_ = Stencil (x, stencil_.expr ());
}
Paper_line::~Paper_line ()
Paper_line::mark_smob (SCM smob)
{
Paper_line *line = (Paper_line*) ly_cdr (smob);
- return line->stencils_;
+ return line-> stencil_.expr ();
}
int
return 1;
}
-Offset
-Paper_line::dim () const
-{
- return dim_;
-}
-
bool
Paper_line::is_title () const
{
return penalty_;
}
-SCM
-Paper_line::stencils () const
+Offset
+Paper_line::dim () const
{
- return stencils_;
+ return Offset (stencil_.extent (X_AXIS).length (),
+ stencil_.extent (Y_AXIS).length ());
}
SCM
Paper_line::to_stencil () const
{
- Stencil stencil;
- for (SCM s = stencils_; ly_c_pair_p (s); s = ly_cdr (s))
- stencil.add_stencil (*unsmob_stencil (ly_car (s)));
- Offset o = dim ();
- Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
- stencil = Stencil (x, stencil.expr ());
- return stencil.smobbed_copy ();
+ return stencil_.smobbed_copy ();
}
LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
Score *score = $1;
Book *book = new Book;
book->scores_.push (score);
- extern Music_output_def* get_paper (My_lily_parser *parser);
+
Music_output_def *paper = get_paper (THIS);
SCM s = book->to_stencil (paper, THIS->header_);
scm_gc_unprotect_object (score->self_scm ());
(SCM score_smob),
"Return SCORE encapsulated in a BOOK.")
{
-#if 0
- SCM_ASSERT_TYPE (ly_c_parser_p (parser_smob), parser_smobd, SCM_ARG1, __FUNCTION__, "parser_smob");
- SCM_ASSERT_TYPE (ly_c_score_p (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob");
-#endif
+ SCM_ASSERT_TYPE (unsmob_score (score_smob), score_smob, SCM_ARG1, __FUNCTION__, "score_smob");
Score *score = unsmob_score (score_smob);
Book *book = new Book;
Paper_line *pl = new Paper_line (Offset (x.length (), y.length ()),
stencils, penalty);
- scm_gc_unprotect_object (pl->self_scm ());
- return pl->self_scm ();
+ return scm_gc_unprotect_object (pl->self_scm ());
}
Link_array<Item>