]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-line.cc
* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / paper-line.cc
1 /*
2   paper-line.cc -- implement Paper_line
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "paper-line.hh"
10 #include "ly-smobs.icc"
11 #include "string.hh" // to_string
12
13 #define TITLE_PENALTY -1
14
15 Paper_line::Paper_line (Offset o, SCM stencils, bool is_title)
16 {
17   dim_ = o;
18   stencils_ = stencils;
19   is_title_ = is_title;
20   smobify_self ();
21 }
22
23 Paper_line::~Paper_line ()
24 {
25 }
26
27 IMPLEMENT_SMOBS (Paper_line);
28 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
29 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
30
31 SCM
32 Paper_line::mark_smob (SCM s)
33 {
34   Paper_line *line = (Paper_line*) ly_cdr (s);
35   return line->stencils_;
36 }
37
38 int
39 Paper_line::print_smob (SCM s, SCM port, scm_print_state*)
40 {
41   scm_puts ("#<Paper_line ", port);
42   Paper_line *line = (Paper_line*) ly_cdr (s);
43   scm_puts (to_string (line->number_).to_str0 (), port);
44   if (line->is_title ())
45     scm_puts (" t", port);
46   scm_puts (" >", port);
47   return 1;
48 }
49
50 Offset
51 Paper_line::dim () const
52 {
53   return dim_;
54 }
55
56 bool
57 Paper_line::is_title () const
58 {
59   return is_title_;
60 }
61
62 SCM
63 Paper_line::stencils () const
64 {
65   return stencils_;
66 }
67
68 LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
69            1, 0, 0, (SCM line),
70            "Return the height of @var{line}.")
71 {
72   Paper_line *pl = unsmob_paper_line (line);
73   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
74   return scm_make_real (pl->dim ()[Y_AXIS]);
75 }
76
77 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
78            1, 0, 0, (SCM line),
79            "Return the number of @var{line}.")
80 {
81   Paper_line *pl = unsmob_paper_line (line);
82   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
83   return scm_int2num (pl->number_);
84 }
85
86 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
87            1, 0, 0, (SCM line),
88            "Return the score for breaking after @var{line}.")
89 {
90   Paper_line *pl = unsmob_paper_line (line);
91   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
92   return scm_int2num (int (pl->is_title ()) * TITLE_PENALTY);
93 }