X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fpaper-outputter.cc;h=44b9b671156db9794d8a4f4041b32ef2dbe67352;hb=bb91de5b7f8c4f753452730101c2422946067cc3;hp=bb7d6e3bfb8305e4cda9edbad140c27541e86cd4;hpb=a84a28ec141e048ce6b53eaa688dbbe9aadea3bb;p=lilypond.git diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index bb7d6e3bfb..d3b99055e9 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -3,247 +3,107 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--2008 Han-Wen Nienhuys Jan Nieuwenhuizen */ -#include -#include #include "paper-outputter.hh" -#include "paper-stream.hh" -#include "molecule.hh" -#include "atom.hh" -#include "array.hh" -#include "string-convert.hh" -#include "debug.hh" -#include "lookup.hh" + +#include +#include + +using namespace std; + +#include "dimensions.hh" +#include "file-name.hh" +#include "font-metric.hh" +#include "input.hh" +#include "lily-version.hh" #include "main.hh" +#include "output-def.hh" +#include "paper-book.hh" +#include "paper-system.hh" +#include "scm-hash.hh" +#include "string-convert.hh" +#include "warn.hh" -Paper_outputter::Paper_outputter (Paper_stream *s) -{ - outstream_l_ = s; - output_header (); -} +#include "ly-smobs.icc" -Paper_outputter::~Paper_outputter () +Paper_outputter::Paper_outputter (SCM port, string format) { - SCM scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("end-output"), SCM_EOL))); + file_ = port; + output_module_ = SCM_EOL; + smobify_self (); - output_scheme (scm); + string module_name = "scm output-" + format; + output_module_ = scm_c_resolve_module (module_name.c_str ()); } -void -Paper_outputter::output_header () +Paper_outputter::~Paper_outputter () { - String creator; - if (no_timestamps_global_b) - creator = "GNU LilyPond\n"; - else - creator = get_version_str (); - String generate; - if (no_timestamps_global_b) - generate = "."; - else - { - generate = _ (", at "); - time_t t (time (0)); - generate += ctime (&t); - //urg - } - - SCM args_scm = - gh_cons (gh_str02scm (creator.ch_l ()), - gh_cons (gh_str02scm (generate.ch_l ()), SCM_EOL)); - -#ifndef NPRINT - DOUT << "output_header\n"; - if (check_debug && !monitor->silent_b ("Guile")) - { - gh_display (args_scm); gh_newline (); - } -#endif - - SCM scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("header"), args_scm))); - - output_scheme (scm); } -void -Paper_outputter::output_molecule (Molecule const*m, Offset o, char const *nm) +IMPLEMENT_SMOBS (Paper_outputter); +IMPLEMENT_DEFAULT_EQUAL_P (Paper_outputter); + +SCM +Paper_outputter::mark_smob (SCM x) { - if (check_debug) - *outstream_l_ << String ("\n%start: ") << nm << "\n"; - - for (PCursor i (m->atoms_); i.ok (); i++) - { - Offset a_off = i->offset (); - a_off += o; - - if (!i->lambda_) - { - // urg - i->lambda_ = ly_append (ly_lambda_o (), - ly_list1 (ly_func_o ("empty"))); - } - - switch_to_font (i->font_); - -#ifndef NPRINT - if (check_debug && !monitor->silent_b ("Guile")) - { - DOUT << i->str_ << "\n"; - gh_display (i->lambda_); gh_newline (); - } -#endif - - SCM args_scm = - gh_cons (gh_double2scm (a_off.x ()), - gh_cons (gh_double2scm (a_off.y ()), - gh_cons (i->lambda_, SCM_EOL))); - -#ifndef NPRINT - if (check_debug && !monitor->silent_b ("Guile")) - { - gh_display (args_scm); gh_newline (); - } -#endif - - SCM box_scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("placebox"), args_scm))); - - output_scheme (box_scm); - } + Paper_outputter *p = (Paper_outputter *) SCM_CELL_WORD_1 (x); + scm_gc_mark (p->output_module_); + return p->file_; } -void -Paper_outputter::output_comment (String str) +int +Paper_outputter::print_smob (SCM /* x */, + SCM p, + scm_print_state *) { - // urg - *outstream_l_ << "% " << str << "\n"; + scm_puts ("#", p); + return 1; } - -void -Paper_outputter::output_scheme (SCM scm) +SCM +Paper_outputter::file () const { - String o = String ("\'") + output_global_ch; - - if (String (output_global_ch) == "scm") - { - static SCM port = 0; - // urg - if (!port) - { - int fd = 1; - ofstream * of = dynamic_cast (outstream_l_->os); - if (of) - fd = of->rdbuf()->fd(); - FILE *file = fdopen (fd, "a"); - port = scm_standard_stream_to_port (file, "a", ""); - scm_display (gh_str02scm ("(load 'lily.scm)\n"), port); - } - - scm_display (gh_str02scm ("(display ((eval "), port); - scm_write (scm, port); - scm_display (gh_str02scm (") 'tex))\n"), port); - scm_newline (port); - scm_fflush (port); - - return; - } - else - { - SCM str_scm = gh_call1 (ly_eval (scm), gh_eval_str (o.ch_l ())); - char* c = gh_scm2newstr (str_scm, NULL); - *outstream_l_ << c; - free (c); - } + return file_; } -void -Paper_outputter::output_string (String str) + +SCM +Paper_outputter::dump_string (SCM scm) { - // urg - *outstream_l_ << str; + return scm_display (scm, file ()); } -void -Paper_outputter::switch_to_font (String fontname) +SCM +Paper_outputter::scheme_to_string (SCM scm) { - if (fontname.length_i () && (fontname != current_font_)) - { - current_font_ = fontname; - int i=0; - bool new_b = false; - for (; i< font_arr_.size (); i++) - if (font_arr_[i] == fontname) - { - new_b = true; - break; - } - - if (new_b) - { - font_arr_.push (fontname); - output_font_def (i, fontname); - } - output_font_switch (i); - } - return; + return scm_eval (scm, output_module_); } void -Paper_outputter::start_line () +Paper_outputter::output_scheme (SCM scm) { - SCM scm = - gh_append2 (ly_lambda_o (), - gh_list (ly_func_o ("start-line"), SCM_UNDEFINED));; - - output_scheme (scm); + dump_string (scheme_to_string (scm)); } -/* - 26 fonts ought to be enough for anyone. -*/ void -Paper_outputter::output_font_def (int i, String str) +paper_outputter_dump (void *po, SCM x) { - //urg, broken with guile-1.3 - //return; - SCM scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("font-def"), - gh_cons (gh_int2scm (i), gh_cons (gh_str02scm (str.ch_l ()), SCM_EOL))))); - - output_scheme (scm); + Paper_outputter *me = (Paper_outputter *) po; + me->output_scheme (x); } void -Paper_outputter::output_font_switch (int i) +Paper_outputter::output_stencil (Stencil stil) { - //urg, broken with guile-1.2, 1.3 - //return; - SCM scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("font-switch"), - gh_cons (gh_int2scm (i), SCM_EOL)))); - - output_scheme (scm); + interpret_stencil_expression (stil.expr (), paper_outputter_dump, + (void *) this, Offset (0, 0)); } void -Paper_outputter::stop_line () +Paper_outputter::close () { - SCM scm = - ly_append (ly_lambda_o (), - ly_list1 (ly_append (ly_func_o ("stop-line"), SCM_EOL))); - - output_scheme (scm); - - current_font_ = ""; - font_arr_.clear (); + if (scm_port_p (file_) == SCM_BOOL_T) + scm_close_port (file_); }