From: Han-Wen Nienhuys Date: Wed, 27 Apr 2005 13:00:50 +0000 (+0000) Subject: * python/lilylib.py (make_ps_images): bugfixes; GS can produce X-Git-Tag: release/2.5.22~38 X-Git-Url: https://git.donarmstrong.com/lilypond.git?a=commitdiff_plain;h=d624901bfb526e5c20f4db931a9e4f183b19b701;p=lilypond.git * python/lilylib.py (make_ps_images): bugfixes; GS can produce empty 2nd page for mono page. * scm/lily.scm: remove p&c definitions. --- diff --git a/ChangeLog b/ChangeLog index e520786901..8ab5324b20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2005-04-27 Han-Wen Nienhuys + * python/lilylib.py (make_ps_images): bugfixes; GS can produce + empty 2nd page for mono page. + + * scm/lily.scm: remove p&c definitions. + * po/zh_TW.po (Module): new translation. * lily/lily-guile.cc (ly_chain_assoc): remove. diff --git a/lily/main.cc b/lily/main.cc index dfc986ceb4..690f1d70f2 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -70,7 +70,8 @@ bool be_verbose_global = false; /* Scheme code to execute before parsing, after .scm init. This is where -e arguments are appended to. */ -String init_scheme_code_string = "(begin #t "; +String init_scheme_code_string; +String init_scheme_variables; /* Generate preview of first system. */ bool make_preview = false; @@ -393,9 +394,29 @@ main_with_guile (void *, int, char **) all_fonts_global = new All_font_metrics (global_path.to_string ()); - init_scheme_code_string += ")"; - scm_c_eval_string ((char *) init_scheme_code_string.to_str0 ()); + + if (!init_scheme_variables.is_empty () + || !init_scheme_code_string.is_empty ()) + { + init_scheme_variables = "(ly:set-option 'command-line-settings (list " + + init_scheme_variables + "))"; + + init_scheme_code_string + += "(begin #t " + + init_scheme_variables + + init_scheme_code_string + + ")"; + + char const *str0 = init_scheme_code_string.to_str0 (); + + if (be_verbose_global) + { + progress_indication (_f("Evaluating %s", str0)); + } + scm_c_eval_string ((char *) str0); + } + /* We accept multiple independent music files on the command line to reduce compile time when processing lots of small files. Starting the GUILE engine is very time consuming. */ @@ -478,7 +499,22 @@ parse_argv (int argc, char **argv) break; case 'd': - + { + String arg (option_parser->optional_argument_str0_); + int eq = arg.index ('='); + + String key = arg; + String val = "#t"; + + if (eq >= 0) + { + key = arg.left_string (eq); + val = arg.right_string (arg.length () - eq - 1); + } + + init_scheme_variables + += "(cons \'" + key + " " + val + ")\n"; + } break; case 'v': diff --git a/lily/scm-option.cc b/lily/scm-option.cc index e7042cc44d..7e007cadb9 100644 --- a/lily/scm-option.cc +++ b/lily/scm-option.cc @@ -6,10 +6,10 @@ (c) 2001--2005 Han-Wen Nienhuys */ -#include "scm-option.hh" - #include +#include "scm-option.hh" +#include "protected-scm.hh" #include "parse-scm.hh" #include "warn.hh" #include "main.hh" @@ -29,8 +29,6 @@ /* Write midi as formatted ascii stream? */ bool midi_debug_global_b; -int preview_resolution_global = 90; - /* General purpose testing flag */ int testing_level_global; @@ -45,6 +43,8 @@ bool lily_1_8_compatibility_used = false; */ bool do_internal_type_checking_global; +Protected_scm command_line_settings = SCM_EOL; + /* What is this function for ? */ @@ -96,6 +96,8 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), "Relative for simultaneous music functions similar to chord syntax\n" "@item new-relative\n" "Relative for simultaneous music functions similar to sequential music\n" + "@item command-line-settings\n" + "An alist of generic key/value pairs\n" "@end table\n" "\n" "This function is useful to call from the command line: @code{lilypond -e\n" @@ -123,10 +125,14 @@ LY_DEFINE (ly_set_option, "ly:set-option", 1, 1, 0, (SCM var, SCM val), /* Needs to be reset for each file that uses this option. */ lily_1_8_compatibility_used = false; } - else if (var == ly_symbol2scm ("resolution")) - preview_resolution_global = robust_scm2int (val, 90); else if (var == ly_symbol2scm ("new-relative")) lily_1_8_relative = false; + else if (var == ly_symbol2scm ("command-line-settings")) + { + SCM_ASSERT_TYPE(scm_list_p (val) == SCM_BOOL_T, + val, SCM_ARG2, __FUNCTION__, "alist"); + command_line_settings = scm_append (scm_list_2 (val, command_line_settings)); + } else { if (scm_is_symbol (var)) @@ -148,8 +154,8 @@ LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var), "Report whether old-relative compatibility mode is used\n" "@item verbose\n" "Report whether we are running in verbose mode\n" - "@item resolution\n" - "Resolution for the PNG output." + "@item command-line-settings\n" + "@end table\n" "\n") { @@ -163,8 +169,10 @@ LY_DEFINE (ly_get_option, "ly:get-option", 1, 0, 0, (SCM var), o = ly_bool2scm (lily_1_8_relative); else if (var == ly_symbol2scm ("verbose")) o = ly_bool2scm (be_verbose_global); - else if (var == ly_symbol2scm ("resolution")) - o = scm_from_int (preview_resolution_global); + else if (var == ly_symbol2scm ("command-line-settings")) + { + o = command_line_settings; + } else { if (scm_is_symbol (var)) diff --git a/python/lilylib.py b/python/lilylib.py index 2c5cc16209..a9d6ebacde 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -474,6 +474,9 @@ def make_ps_images (ps_name, resolution = 90, papersize = "a4", # png16m is because Lily produces color nowadays. if not multi_page: + + # GS can produce empty 2nd page if pngn is used. + output_file = png1 cmd = r'''gs\ -dEPSCrop\ -dGraphicsAlphaBits=4\ @@ -514,7 +517,7 @@ def make_ps_images (ps_name, resolution = 90, papersize = "a4", error (_ ("%s exited with status: %d") % ('GS', status)) exit (1) - if rename_page1_p or not multi_page: + if rename_page1_p and multi_page: os.rename (pngn % 1, png1) - files = glob.glob (png1) + glob.glob (re.sub ('%d', '*', output_file)) + files = glob.glob (png1) + glob.glob (re.sub ('%d', '*', pngn)) return files diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 6275b12ec6..0e2bdf78de 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -342,22 +342,74 @@ (display "} stop-system\n%%Trailer\n%%EOF\n" port) (ly:outputter-close outputter))) + (define-public (output-preview-framework basename book scopes fields) + (let* ((paper (ly:paper-book-paper book)) (systems (ly:paper-book-systems book)) (scale (ly:output-def-lookup paper 'outputscale)) - (titles (take-while ly:paper-system-title? systems)) - (non-title (find (lambda (x) - (not (ly:paper-system-title? x))) systems)) - (dump-me - (stack-stencils Y DOWN 0.0 - (map ly:paper-system-stencil - (append titles (list non-title)))))) - (output-scopes scopes fields basename) - (dump-stencil-as-EPS paper dump-me - (format "~a.preview" basename) - #t))) + (to-dump-systems '()) + ) + + + ;; skip booktitles. + (if (and + (not + (cdr (assoc + 'preview-include-book-title + (ly:get-option 'command-line-settings) + ))) + (< 1 (length systems)) + (ly:paper-system-title? (list-ref systems 0)) + (ly:paper-system-title? (list-ref systems 1))) + (set! systems (cdr systems))) + + (for-each + (lambda (sys) + (if (or + (ly:paper-system-title? sys) + (and (pair? to-dump-systems) + (ly:paper-system-title? (car to-dump-systems)))) + (set! to-dump-systems (cons sys to-dump-systems)))) + systems) + + (dump-stencil-as-EPS + paper + (stack-stencils Y DOWN 0.0 + (map ly:paper-system-stencil (reverse to-dump-systems))) + (format "~a.preview" basename) + #t) + + (postprocess-output book framework-ps-module + (format "~a.preview.eps" basename) + (completize-formats (cons "png" (ly:output-formats)))) + + )) +(if #f + (define-public (output-preview-framework basename book scopes fields) + + (let* ((paper (ly:paper-book-paper book)) + (systems (ly:paper-book-systems book)) + (scale (ly:output-def-lookup paper 'outputscale)) + (titles (take-while ly:paper-system-title? systems)) + (non-title (find (lambda (x) + (not (ly:paper-system-title? x))) systems)) + (dump-me + (stack-stencils Y DOWN 0.0 + (map ly:paper-system-stencil + (append titles (list non-title)))))) + (output-scopes scopes fields basename) + (dump-stencil-as-EPS paper dump-me + (format "~a.preview" basename) + #t) + + (postprocess-output book framework-ps-module + (format "~a.preview.eps" basename) + (completize-formats (ly:output-formats))) + + )) + ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-public (convert-to-pdf book name) @@ -371,12 +423,17 @@ (define-public (convert-to-png book name) (let* ((defs (ly:paper-book-paper book)) - (resolution (ly:output-def-lookup defs 'pngresolution)) + (defs-resolution (ly:output-def-lookup defs 'pngresolution)) + (resolution (if (number? defs-resolution) + defs-resolution + (cdr (assoc 'resolution + (ly:get-option 'command-line-settings))))) (papersizename (ly:output-def-lookup defs 'papersizename))) - (postscript->png (if (number? resolution) resolution - (ly:get-option 'resolution)) - (if (string? papersizename) papersizename "a4") + (postscript->png resolution + (if (string? papersizename) + papersizename "a4") + name))) (define-public (convert-to-dvi book name) diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index d71a26246b..561c5c5e7c 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -298,8 +298,16 @@ (resolution (ly:output-def-lookup defs 'pngresolution)) (papersizename (ly:output-def-lookup defs 'papersizename))) (postscript->png - (if (number? resolution) resolution (ly:get-option 'resolution)) - (if (string? papersizename) papersizename "a4") + (if (number? resolution) + resolution + (assoc + 'resolution + (ly:get-option 'command-line-settings))) + + (if (string? papersizename) + papersizename + "a4") + (string-append (basename name ".tex") ".ps")))) (define-public (convert-to-ps book name) diff --git a/scm/lily.scm b/scm/lily.scm index 3d912310ff..02a6671ac9 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -36,16 +36,13 @@ (debug-enable 'backtrace) (read-enable 'positions))) -(define-public (line-column-location file line col) - "Print an input location, including column number ." - (string-append (number->string line) ":" - (number->string col) " " file)) -(define-public (line-location file line col) - "Print an input location, without column number ." - (string-append (number->string line) " " file)) -(define-public point-and-click #f) +;; initialize defaults. +(ly:set-option 'command-line-settings + '((resolution . 90) + (preview-include-book-title . #t) + )) (define-public tex-backend? (member (ly:output-backend) '("texstr" "tex"))) diff --git a/scm/output-tex.scm b/scm/output-tex.scm index 6537a688e4..960d62d439 100644 --- a/scm/output-tex.scm +++ b/scm/output-tex.scm @@ -192,7 +192,21 @@ ;; no-origin not yet supported by Xdvi (define (no-origin) "") + + + +(define-public (line-location file line col) + "Print an input location, without column number ." + (string-append (number->string line) " " file)) + +(define-public point-and-click #f) + (define (grob-cause offset grob) + (define (line-column-location file line col) + "Print an input location, including column number ." + (string-append (number->string line) ":" + (number->string col) " " file)) + (if (procedure? point-and-click) (let* ((cause (ly:grob-property grob 'cause)) (music-origin (if (ly:music? cause) @@ -202,6 +216,6 @@ (if (pair? location) ;;; \\string ? (string-append "\\special{src:" - (apply point-and-click location) "}") + (line-column-location location) "}") "")) ""))