]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-outputter.cc
(file): open file in binary mode. This
[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 (String file_name, String format)
31 {
32   file_ = SCM_EOL;
33   output_module_ = SCM_EOL;
34   smobify_self ();
35
36   file_name_ = file_name;
37   String module_name = "scm output-" + format;
38   output_module_ = scm_c_resolve_module (module_name.to_str0 ());
39 }
40
41 Paper_outputter::~Paper_outputter ()
42 {
43 }
44
45 IMPLEMENT_SMOBS (Paper_outputter);
46 IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter);
47
48 SCM
49 Paper_outputter::mark_smob (SCM x)
50 {
51   Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x);
52   scm_gc_mark (p->output_module_);
53   return p->file_;
54 }
55
56 int
57 Paper_outputter::print_smob (SCM x, SCM p, scm_print_state*)
58 {
59   (void) x;
60   scm_puts ("#<Paper_outputter>", p);
61   return 1;
62 }
63
64 SCM
65 Paper_outputter::file ()
66 {
67   if (file_ == SCM_EOL)
68     if (file_name_ == "-")
69       file_ = scm_current_output_port ();
70     else
71       /*
72         Opening binary sucks a little for DOS, since PS doesn't look like
73         ASCII anymore, but binary CFFs will get embedded correctly.
74        */
75       file_ = scm_open_file (scm_makfrom0str (file_name_.to_str0 ()),
76                              scm_makfrom0str ("wb"));
77   return file_;
78 }
79
80 SCM
81 Paper_outputter::dump_string (SCM scm)
82 {
83   return scm_display (scm, file ());
84 }
85
86 SCM
87 Paper_outputter::scheme_to_string (SCM scm)
88 {
89   return scm_eval (scm, output_module_);
90 }
91
92 void
93 Paper_outputter::output_scheme (SCM scm)
94 {
95   dump_string (scheme_to_string (scm));
96 }
97
98 void
99 paper_outputter_dump (void *po, SCM x)
100 {
101   Paper_outputter *me = (Paper_outputter *) po;
102   me->output_scheme (x);
103 }
104
105 void
106 Paper_outputter::output_stencil (Stencil stil)
107 {
108   interpret_stencil_expression (stil.expr (), paper_outputter_dump,
109                                 (void *) this, Offset (0, 0));
110 }
111
112 void
113 Paper_outputter::close ()
114 {
115   if (scm_port_p (file_) == SCM_BOOL_T)
116     scm_close_port (file_);
117 }