From 6f28237e24268c76147ba3e9d8619316a4b4b4fb Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 13 Mar 2004 21:24:15 +0000 Subject: [PATCH] * scm/lily.scm (get-output-module): New function. (output-alist): Remove ,ps-output-expression. * scm/output-tex.scm (ps-output-expression): New function. * scm/output-ps.scm (ps-output-expression): Remove. (header, start-page): Output page metadata. * lily/paper-outputter.cc (Paper_outputter)[PAGE_LAYOUT]: initialise output_module_. Do not write part of header. (output_scheme)[PAGE_LAYOUT]: Output through output_module_. (output_header): Output full header. * scm/define-markup-commands.scm (bigger, smaller): Avoid crash. FIXME. --- ChangeLog | 18 ++++++++++ lily/include/paper-outputter.hh | 7 ++-- lily/my-lily-lexer.cc | 1 + lily/paper-book.cc | 9 ++--- lily/paper-outputter.cc | 64 ++++++++++++++++++++++----------- lily/parse-scm.cc | 14 +++----- scm/define-markup-commands.scm | 8 +++-- scm/lily.scm | 10 +++--- scm/output-ps.scm | 32 +++++++++++------ scm/output-tex.scm | 16 ++++++--- 10 files changed, 119 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index b2e0dc286f..9cbf4403f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2004-03-13 Jan Nieuwenhuizen + + * scm/lily.scm (get-output-module): New function. + (output-alist): Remove ,ps-output-expression. + + * scm/output-tex.scm (ps-output-expression): New function. + + * scm/output-ps.scm (ps-output-expression): Remove. + (header, start-page): Output page metadata. + + * lily/paper-outputter.cc (Paper_outputter)[PAGE_LAYOUT]: + initialise output_module_. Do not write part of header. + (output_scheme)[PAGE_LAYOUT]: Output through output_module_. + (output_header): Output full header. + + * scm/define-markup-commands.scm (bigger, smaller): Avoid crash. + FIXME. + 2004-03-13 Han-Wen Nienhuys * scm/new-font.scm: new file. Tree based font lookup. diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index fc59ec65bc..4f2ea7b4cc 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -29,7 +29,8 @@ class Paper_outputter bool verbatim_scheme_b_; public: - SCM output_func_ ; + SCM output_func_; + SCM output_module_; Protected_scm file_; String basename_; @@ -38,11 +39,11 @@ public: void dump_scheme (SCM); - void output_metadata (SCM, Paper_def*); + void output_metadata (Paper_def*, SCM); void output_music_output_def (Music_output_def* odef); void output_scheme (SCM scm); void output_expr (SCM expr, Offset o); - void output_header (Paper_def*); + void output_header (Paper_def*, SCM, int); void output_line (SCM, Offset*, bool); }; diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index a0a276ccf7..5653b3b989 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -165,6 +165,7 @@ void My_lily_lexer::start_main_input () { new_input (main_input_name_, &global_input_file->sources_); + /* Do not allow \include in --safe-mode */ allow_includes_b_ = allow_includes_b_ && ! safe_global_b; scm_module_define (gh_car (scopes_), diff --git a/lily/paper-book.cc b/lily/paper-book.cc index b89d0a86b6..31f939c557 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -217,8 +217,7 @@ Paper_book::output (String outname) Paper_def *paper = papers_[0]; Paper_outputter *out = paper->get_paper_outputter (outname); - out->output_metadata (get_scopes (0), paper); - out->output_header (paper); + out->output_header (paper, get_scopes (0), pages->size ()); int page_count = pages->size (); for (int i = 0; i < page_count; i++) @@ -437,11 +436,9 @@ Paper_book::fill_pages (Page *page, int page_count, Real fudge) void Paper_book::classic_output (String outname) { - Paper_outputter *out = papers_.top ()->get_paper_outputter (outname); int count = scores_.size (); - - out->output_metadata (get_scopes (count - 1), papers_.top ()); - out->output_header (papers_.top ()); + Paper_outputter *out = papers_.top ()->get_paper_outputter (outname); + out->output_header (papers_.top (), get_scopes (count - 1), 0); int line_count = SCM_VECTOR_LENGTH ((SCM) scores_.top ()); for (int i = 0; i < line_count; i++) diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 4797a837ec..0e9d30eb91 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -36,23 +36,31 @@ Paper_outputter::Paper_outputter (String name) file_ = scm_open_file (scm_makfrom0str (name.to_str0 ()), scm_makfrom0str ("w")); - static SCM find_dumper; - if (!find_dumper) - find_dumper = scm_c_eval_string ("find-dumper"); - - output_func_ - = scm_call_1 (find_dumper, - scm_makfrom0str (output_format_global.to_str0 ())); - - String creator = gnu_lilypond_version_string (); - creator += " (http://lilypond.org)"; - time_t t (time (0)); - String time_stamp = ctime (&t); - time_stamp = time_stamp.left_string (time_stamp.length () - 1) - + " " + *tzname; - output_scheme (scm_list_3 (ly_symbol2scm ("header"), - scm_makfrom0str (creator.to_str0 ()), - scm_makfrom0str (time_stamp.to_str0 ()))); + if (output_format_global == PAGE_LAYOUT) + { + output_func_ = SCM_UNDEFINED; + output_module_ + = scm_call_1 (scm_primitive_eval (ly_symbol2scm ("get-output-module")), + scm_makfrom0str (output_format_global.to_str0 ())); + if (safe_global_b) + { + SCM safe_module = scm_primitive_eval (ly_symbol2scm ("safe-module")); + SCM m = scm_set_current_module (safe_module); + scm_c_use_module (("output-" + output_format_global).to_str0 ()); + output_module_ = scm_set_current_module (m); + } + } + else + { + static SCM find_dumper; + if (!find_dumper) + find_dumper = scm_c_eval_string ("find-dumper"); + + output_func_ + = scm_call_1 (find_dumper, + scm_makfrom0str (output_format_global.to_str0 ())); + output_module_ = SCM_UNDEFINED; + } } Paper_outputter::~Paper_outputter () @@ -64,11 +72,14 @@ Paper_outputter::~Paper_outputter () void Paper_outputter::output_scheme (SCM scm) { - gh_call2 (output_func_, scm, file_); + if (output_format_global == PAGE_LAYOUT) + scm_display (scm_eval (scm, output_module_), file_); + else + gh_call2 (output_func_, scm, file_); } void -Paper_outputter::output_metadata (SCM scopes, Paper_def *paper) +Paper_outputter::output_metadata (Paper_def *paper, SCM scopes) { SCM fields = SCM_EOL; for (int i = dump_header_fieldnames_global.size (); i--; ) @@ -86,9 +97,22 @@ Paper_outputter::output_metadata (SCM scopes, Paper_def *paper) } void -Paper_outputter::output_header (Paper_def *paper) +Paper_outputter::output_header (Paper_def *paper, SCM scopes, int page_count) { + String creator = gnu_lilypond_version_string (); + creator += " (http://lilypond.org)"; + time_t t (time (0)); + String time_stamp = ctime (&t); + time_stamp = time_stamp.left_string (time_stamp.length () - 1) + + " " + *tzname; + output_scheme (scm_list_4 (ly_symbol2scm ("header"), + scm_makfrom0str (creator.to_str0 ()), + scm_makfrom0str (time_stamp.to_str0 ()), + scm_int2num (page_count))); + + output_metadata (paper, scopes); output_music_output_def (paper); + output_scheme (scm_list_1 (ly_symbol2scm ("header-end"))); output_scheme (scm_list_2 (ly_symbol2scm ("define-fonts"), ly_quote_scm (paper->font_descriptions ()))); diff --git a/lily/parse-scm.cc b/lily/parse-scm.cc index e95eb644f7..a5de3e9866 100644 --- a/lily/parse-scm.cc +++ b/lily/parse-scm.cc @@ -5,14 +5,10 @@ #include "string.hh" #include "source-file.hh" -/* - Pass string to scm parser, evaluate one expression. - Return result value and #chars read. - - Thanks to Gary Houston - - Need guile-1.3.4 (>1.3 anyway) for ftell on str ports -- jcn -*/ +/* Pass string to scm parser, evaluate one expression. + Return result value and #chars read. + + Thanks to Gary Houston */ SCM internal_ly_parse_scm (Parse_start * ps, bool safe) { @@ -35,8 +31,6 @@ internal_ly_parse_scm (Parse_start * ps, bool safe) static SCM safe_module; if (!safe_module) safe_module = scm_primitive_eval (ly_symbol2scm ("safe-module")); - - answer = scm_eval (form, safe_module); } else diff --git a/scm/define-markup-commands.scm b/scm/define-markup-commands.scm index 6d765b7182..6332287c41 100644 --- a/scm/define-markup-commands.scm +++ b/scm/define-markup-commands.scm @@ -518,14 +518,18 @@ any sort of property supported by @internalsref{font-interface} and (def-markup-command (smaller paper props arg) (markup?) "Decrease the font size relative to current setting" (let* ((fs (chain-assoc-get 'font-size props 0)) - (entry (cons 'font-size (- fs 1)))) + ;; FIXME: crasher fix + ;; (entry (cons 'font-size (- fs 1)))) + (entry (cons 'font-size (if (number? fs) (- fs 1) 0)))) (interpret-markup paper (cons (list entry) props) arg))) (def-markup-command (bigger paper props arg) (markup?) "Increase the font size relative to current setting" (let* ((fs (chain-assoc-get 'font-size props 0)) - (entry (cons 'font-size (+ fs 1)))) + ;; FIXME: crasher fix + ;; (entry (cons 'font-size (+ fs 1)))) + (entry (cons 'font-size (if (number? fs) (+ fs 1) 0)))) (interpret-markup paper (cons (list entry) props) arg))) (def-markup-command larger (markup?) diff --git a/scm/lily.scm b/scm/lily.scm index 60fbcf744b..9329701c04 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -371,7 +371,6 @@ L1 is copied, L2 not. (define output-alist `( ("tex" . ("TeX output. The default output form." ,tex-output-expression)) - ("ps" . ("Direct postscript. Requires setting GS_LIB and GS_FONTPATH" ,ps-output-expression)) ("scm" . ("Scheme dump: debug scheme stencil expressions" ,write)) ("sketch" . ("Bare bones Sketch output." ,sketch-output-expression)) ("sodipodi" . ("Bare bones Sodipodi output." ,sodipodi-output-expression)) @@ -386,13 +385,16 @@ L1 is copied, L2 not. output-alist) )) -(define-public (find-dumper format ) - (let* ((d (assoc format output-alist))) - +(define-public (find-dumper format) + (let ((d (assoc format output-alist))) (if (pair? d) (caddr d) (scm-error "Could not find dumper for format ~s" format)))) +(define-public (get-output-module output-format) + (resolve-module `(scm ,(string->symbol + (string-append "output-" output-format))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; other files. diff --git a/scm/output-ps.scm b/scm/output-ps.scm index 3bb2094353..36d9dffbcd 100644 --- a/scm/output-ps.scm +++ b/scm/output-ps.scm @@ -16,6 +16,8 @@ ;;;; * text setting, kerning. ;;;; * document output-interface +;;(if (not safe-mode?) +;; (debug-enable 'backtrace)) (debug-enable 'backtrace) (define-module (scm output-ps)) @@ -27,17 +29,18 @@ (srfi srfi-13) (lily)) - - - -;;; Lily output interface, PostScript implementation --- cleanup and docme +(define (expression->string expr) + (eval expr this-module)) ;;; Output interface entry -(define-public (ps-output-expression expr port) +(define (output-expression expr port) (display (expression->string expr) port)) + ;;; Global vars ;; alist containing fontname -> fontcommand assoc (both strings) +(define page-count 0) +(define page-number 0) (define font-name-alist '()) ;; /lilypondpaperoutputscale 1.75729901757299 def @@ -80,6 +83,11 @@ (define (tex-font? fontname) (equal? (substring fontname 0 2) "cm")) + +;;; +;;; Lily output interface, PostScript implementation --- cleanup and docme +;;; + ;;; Output-interface functions (define (beam width slope thick blot) (string-append @@ -239,9 +247,6 @@ (define (end-output) "\nend-lilypond-output\n") -(define (expression->string expr) - (eval expr this-module)) - (define (ez-ball ch letter-col ball-col) (string-append " (" ch ") " @@ -267,10 +272,14 @@ (string-append (select-font name-mag-pair) exp)) -(define (header creator time-stamp) +(define (header creator time-stamp page-count-) + (set! page-count page-count-) + (set! page-number 0) (string-append "%!PS-Adobe-3.0\n" "%%Creator: " creator " " time-stamp "\n" + "%%Pages: " (number->string page-count) "\n" + "%%PageOrder: Ascend\n" ;;(string-append "GNU LilyPond (" (lilypond-version) "), ") ;; (strftime "%c" (localtime (current-time)))) ;; FIXME: duplicated in every backend @@ -422,7 +431,10 @@ " draw_zigzag_line ")) (define (start-page) - "\nstart-page\n") + (set! page-number (+ page-number 1)) + (string-append + "%%Page: " (number->string page-number) " " (number->string page-count) "\n" + "start-page\n")) (define (stop-page last?) (if last? diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 52c86ed58a..f86cc53699 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -19,6 +19,12 @@ (define this-module (current-module)) +;; dumper-compatibility + +(define (ps-output-expression expr port) + (let ((output-ps (resolve-module '(scm output-ps)))) + (display (eval expr output-ps) port))) + ;;; Output interface entry (define-public (tex-output-expression expr port) (display (eval expr this-module) port )) @@ -200,12 +206,12 @@ (define (end-output) (begin - ; uncomment for some stats about lily memory - ; (display (gc-stats)) + ;; uncomment for some stats about lily memory + ;; (display (gc-stats)) (string-append "\\lilypondend\n" - ; Put GC stats here. - ))) + ;; Put GC stats here. + ))) (define (experimental-on) "") @@ -230,7 +236,7 @@ "\\lilypondspecial\n" "\\lilypondpostscript\n")) -(define (header creator time-stamp) +(define (header creator time-stamp page-count) (string-append "% Generated by " creator "\n" "% at " time-stamp "\n" -- 2.39.2