]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
* lily/include/lily-guile.hh: rename ly_c_X_p -> ly_is_X
[lilypond.git] / lily / paper-outputter.cc
1 /*
2   paper-outputter.cc -- implement Paper_outputter
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include "paper-outputter.hh"
11
12 #include <math.h>
13 #include <ctime>
14
15 #include "dimensions.hh"
16 #include "file-name.hh"
17 #include "font-metric.hh"
18 #include "input-smob.hh"
19 #include "lily-version.hh"
20 #include "main.hh"
21 #include "output-def.hh"
22 #include "paper-book.hh"
23 #include "paper-system.hh"
24 #include "scm-hash.hh"
25 #include "string-convert.hh"
26 #include "warn.hh"
27
28 #include "ly-smobs.icc"
29
30 Paper_outputter::Paper_outputter (SCM port, String format)
31 {
32   file_ = port;
33   output_module_ = SCM_EOL;
34   smobify_self ();
35
36   String module_name = "scm output-" + format;
37   output_module_ = scm_c_resolve_module (module_name.to_str0 ());
38 }
39
40 Paper_outputter::~Paper_outputter ()
41 {
42 }
43
44 IMPLEMENT_SMOBS (Paper_outputter);
45 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
46
47 SCM
48 Paper_outputter::mark_smob (SCM x)
49 {
50   Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
51   scm_gc_mark (p->output_module_);
52   return p->file_;
53 }
54
55 int
56 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
57 {
58   (void) x;
59   scm_puts ("#<Paper_outputter>", p);
60   return 1;
61 }
62
63 SCM
64 Paper_outputter::file () const
65 {
66   return file_;
67 }
68
69 SCM
70 Paper_outputter::dump_string (SCM scm)
71 {
72   return scm_display (scm, file ());
73 }
74
75 SCM
76 Paper_outputter::scheme_to_string (SCM scm)
77 {
78   return scm_eval (scm, output_module_);
79 }
80
81 void
82 Paper_outputter::output_scheme (SCM scm)
83 {
84   dump_string (scheme_to_string (scm));
85 }
86
87 void
88 paper_outputter_dump (void *po, SCM x)
89 {
90   Paper_outputter *me = (Paper_outputter *) po;
91   me->output_scheme (x);
92 }
93
94 void
95 Paper_outputter::output_stencil (Stencil stil)
96 {
97   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
98                                 (void *) this, Offset (0, 0));
99 }
100
101 void
102 Paper_outputter::close ()
103 {
104   if (scm_port_p (file_) == SCM_BOOL_T)
105     scm_close_port (file_);
106 }