From: Han-Wen Nienhuys Date: Sat, 24 Jul 2004 11:38:20 +0000 (+0000) Subject: * scm/lily.scm (postscript->png): new function X-Git-Tag: release/2.3.10~60 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=207ff3900c435070d808a685429068f444b02406;p=lilypond.git * scm/lily.scm (postscript->png): new function (postscript->pdf): new function * lily/paper-book.cc (post_processing): call convert-to-{dvi,ps,png,pdf} * scripts/ps2png.py (option_definitions): new file. * lily/paper-book.cc (output): call output-preview-framework (post_processing): new function. Do PDF/PNG conversion. * scm/framework-ps.scm (convert-to-pdf): new function. Call ps2pdf. (output-preview-framework): new function. Generate a preview .ps --- diff --git a/ChangeLog b/ChangeLog index 63814c51b3..6d57c41b9e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2004-07-24 Han-Wen Nienhuys + * scm/lily.scm (postscript->png): new function + (postscript->pdf): new function + + * lily/paper-book.cc (post_processing): call + convert-to-{dvi,ps,png,pdf} + + * scripts/ps2png.py (option_definitions): new file. + * lily/paper-book.cc (output): call output-preview-framework (post_processing): new function. Do PDF/PNG conversion. diff --git a/Documentation/user/invoking.itexi b/Documentation/user/invoking.itexi index 999f81574f..92fe71fddb 100644 --- a/Documentation/user/invoking.itexi +++ b/Documentation/user/invoking.itexi @@ -44,8 +44,6 @@ files. The temporary directory is created in the current directory as @code{@cod Generate output to @var{file}. The extension of @var{file} is ignored. @item --png Also generate pictures of each page, in PNG format. -@item --psgz - Gzip the postscript file. @item --preview Also generate a picture of the first system of the score. @@ -180,9 +178,9 @@ information. @item -f,--format=@var{format} @c @c -A comma separated list of output formats. Choices are @code{tex} (for -@TeX{} output, to be processed with La@TeX{}, and @code{ps} for -PostScript. +A comma separated list of back-end output formats to use. Choices are +@code{tex} (for @TeX{} output, to be processed with La@TeX{}, and +@code{ps} for PostScript. Other output options are intended for developers. @@ -199,12 +197,19 @@ Add @var{directory} to the search path for input files. @cindex search path @item -i,--init=@var{file} Set init file to @var{file} (default: @file{init.ly}). -@item -m,--no-paper -@cindex MIDI -Disable @TeX{} output. If you have a @code{\midi} definition MIDI output -will be generated. @item -o,--output=@var{FILE} -Set the default output file to @var{FILE}. + Set the default output file to @var{FILE}. +@item --ps + Generate PostScript. +@item --dvi + Generate DVI files. In this case, the @TeX{} backend should be + specified, i.e. @code{-f tex}. +@item --png + Generate pictures of each page, in PNG format. This implies @code{--ps}. +@item --pdf + Generate PDF. This implies @code{--ps}. +@item --preview + Also generate a picture of the first system of the score. @item -s,--safe Do not trust the @code{.ly} input. diff --git a/flower/include/getopt-long.hh b/flower/include/getopt-long.hh index a909326d4c..4387e57932 100644 --- a/flower/include/getopt-long.hh +++ b/flower/include/getopt-long.hh @@ -10,7 +10,11 @@ struct Long_option_init { char const * take_arg_str0_; char const * longname_str0_; - char shortname_char_; + + /* + > 255: don't take short version. + */ + int shortname_char_; char const * help_str0_; diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 3042c980e1..45f0f820b1 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -196,7 +196,7 @@ SCM ly_split_list (SCM s, SCM lst); SCM ly_unique (SCM lst); SCM ly_list_qsort_uniq_x (SCM lst); - +SCM ly_output_formats(); /* snarfing. diff --git a/lily/include/main.hh b/lily/include/main.hh index bafde2f92e..6319df9b68 100644 --- a/lily/include/main.hh +++ b/lily/include/main.hh @@ -36,6 +36,8 @@ extern bool verbose_global_b; extern bool store_locations_global_b; extern bool internal_type_checking_global_b; extern bool make_png; +extern bool make_dvi; +extern bool make_ps; extern bool make_pdf; extern bool make_preview; diff --git a/lily/main.cc b/lily/main.cc index ce64720977..35d07b844a 100644 --- a/lily/main.cc +++ b/lily/main.cc @@ -47,7 +47,7 @@ bool no_paper_global_b = false; /* Selected output format. One of tex, ps, scm, as. */ -String output_format_global = "tex"; +String output_format_global = "ps"; /* Current output name. */ String output_name_global; @@ -64,6 +64,8 @@ bool verbose_global_b = false; String init_scheme_code_string = "(begin #t "; bool make_pdf = false; +bool make_dvi = false; +bool make_ps = true; bool make_png = false; bool make_preview = false; @@ -124,7 +126,7 @@ static Long_option_init options_static[] = _i ("set options, use -e '(ly:option-usage)' for help")}, /* Bug in option parser: --output=foe is taken as an abbreviation for --output-format. */ - {_i ("EXT"), "format", 'f', _i ("use output format EXT")}, + {_i ("EXT"), "format", 'f', _i ("select back-end to use")}, {0, "help", 'h', _i ("print this help")}, {_i ("FIELD"), "header", 'H', _i ("write header field to BASENAME.FIELD")}, {_i ("DIR"), "include", 'I', _i ("add DIR to search path")}, @@ -132,6 +134,10 @@ static Long_option_init options_static[] = {0, "no-paper", 'm', _i ("produce MIDI output only")}, {_i ("FILE"), "output", 'o', _i ("write output to FILE")}, {0, "preview", 'p', _i ("generate a preview")}, + {0, "png", 0, _i ("generate PNG")}, + {0, "ps", 0, _i ("generate PostScript")}, + {0, "dvi", 0, _i ("generate DVI")}, + {0, "pdf", 0, _i ("generate PDF")}, {0, "safe-mode", 's', _i ("run in safe mode")}, {0, "version", 'v', _i ("print version number")}, {0, "verbose", 'V', _i ("be verbose")}, @@ -242,6 +248,26 @@ prepend_load_path (String dir) scm_c_eval_string (s.to_str0 ()); } +static void +determine_output_options () +{ + bool found_tex = false; + SCM formats = ly_output_formats (); + for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s)) + { + found_tex = found_tex || (ly_scm2string (ly_car (s)) == "tex"); + } + + if (make_ps && found_tex) + { + make_dvi = true; + } + if (make_pdf || make_png) + { + make_ps = true; + } +} + static void main_with_guile (void *, int, char **) { @@ -261,6 +287,7 @@ main_with_guile (void *, int, char **) call_constructors (); progress_indication ("\n"); + determine_output_options (); all_fonts_global = new All_font_metrics (global_path.to_string ()); init_scheme_code_string += ")"; @@ -324,6 +351,19 @@ parse_argv (int argc, char **argv) { switch (opt->shortname_char_) { + case 0: + if (String (opt->longname_str0_) == "png") + make_png = true; + else if (String (opt->longname_str0_) == "pdf") + make_pdf = true; + else if (String (opt->longname_str0_) == "ps") + make_ps = true; + else if (String (opt->longname_str0_) == "dvi") + make_dvi = true; + else if (String (opt->longname_str0_) == "preview") + make_preview = true; + break; + case 'v': notice (); exit (0); @@ -335,9 +375,6 @@ parse_argv (int argc, char **argv) output_name_global = file_name.to_string (); } break; - case 'p': - make_preview = true; - break; case 'e': init_scheme_code_string += option_parser->optional_argument_str0_; break; diff --git a/lily/mensural-ligature.cc b/lily/mensural-ligature.cc index b64fc88af8..3d344a9a0e 100644 --- a/lily/mensural-ligature.cc +++ b/lily/mensural-ligature.cc @@ -103,7 +103,7 @@ brew_flexa (Grob *me, } Stencil -internal_brew_primitive (Grob *me, bool ledger_take_space) +internal_brew_primitive (Grob *me) { SCM primitive_scm = me->get_property ("primitive"); if (primitive_scm == SCM_EOL) @@ -194,7 +194,7 @@ SCM Mensural_ligature::brew_ligature_primitive (SCM smob) { Grob *me = unsmob_grob (smob); - return internal_brew_primitive (me, false).smobbed_copy (); + return internal_brew_primitive (me).smobbed_copy (); } MAKE_SCHEME_CALLBACK (Mensural_ligature, print, 1); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index 6e739723cf..a94be54856 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -117,28 +117,33 @@ void Paper_book::post_processing (SCM module, SCM file_name) { - if (make_pdf) + struct + { + bool do_it_; + char const *func_name_; + } settings[] = { + {make_dvi, "convert-to-dvi"}, + {make_ps, "convert-to-ps"}, + {make_pdf, "convert-to-pdf"}, + {make_png, "convert-to-png"}, + {0,0} + }; + + for (int i= 0; settings[i].func_name_; i++) { - SCM func = scm_c_module_lookup (module, "convert-to-pdf"); - if (scm_variable_p (func) == SCM_BOOL_T) + if (settings[i].do_it_) { - func = scm_variable_ref (func); - if (ly_c_procedure_p (func)) - scm_call_2 (func, self_scm(), file_name); - } - } - - if (make_png) - { - SCM func = scm_c_module_lookup (module, "convert-to-png"); - if (scm_variable_p (func) == SCM_BOOL_T) - { - func = scm_variable_ref (func); - if (ly_c_procedure_p (func)) - scm_call_2 (func, self_scm(), file_name); + SCM func = scm_c_module_lookup (module, settings[i].func_name_); + if (scm_variable_p (func) == SCM_BOOL_T) + { + func = scm_variable_ref (func); + if (ly_c_procedure_p (func)) + scm_call_2 (func, self_scm(), file_name); + } } } } + void Paper_book::output (String outname) { diff --git a/lily/vaticana-ligature.cc b/lily/vaticana-ligature.cc index dfbd257ac2..ff6289feb2 100644 --- a/lily/vaticana-ligature.cc +++ b/lily/vaticana-ligature.cc @@ -191,7 +191,7 @@ vaticana_brew_join (Grob *me, int delta_pitch, } Stencil -vaticana_brew_primitive (Grob *me, bool ledger_take_space) +vaticana_brew_primitive (Grob *me) { SCM glyph_name_scm = me->get_property ("glyph-name"); if (glyph_name_scm == SCM_EOL) @@ -288,7 +288,7 @@ SCM Vaticana_ligature::brew_ligature_primitive (SCM smob) { Grob *me = unsmob_grob (smob); - SCM primitive = vaticana_brew_primitive (me, false).smobbed_copy (); + SCM primitive = vaticana_brew_primitive (me).smobbed_copy (); return primitive; } diff --git a/python/lilylib.py b/python/lilylib.py index 2da37b1083..0f48d4dac0 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -522,3 +522,5 @@ def make_ps_images (ps_name, resolution = 90): cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file, resolution, ps_name) + return output_file + diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 99ed406cae..f265932197 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -256,31 +256,24 @@ (ly:outputter-dump-string outputter "} stop-system\n%%Trailer\n%%EOF\n"))) (define-public (convert-to-pdf book name) - (display - (string-append - "Converting to " - (regexp-substitute/global #f "\\.ps" name 'pre ".pdf" 'post) - "\n")) - (system (string-append "ps2pdf -sPAPERSIZE=" - (ly:output-def-lookup - (ly:paper-book-book-paper book) - 'papersize) - " " - name))) + (let* + ((defs (ly:paper-book-book-paper book)) + (size (ly:output-def-lookup book 'papersize))) + (postscript->pdf (if (string? size) size "a4") + name))) (define-public (convert-to-png book name) - (display - (string-append - "Converting to " - (regexp-substitute/global #f "\\.ps" name 'pre ".png" 'post) - "\n")) - (system (string-append "ps2pdf -sPAPERSIZE=" - (ly:output-def-lookup - (ly:paper-book-book-paper book) - 'papersize) - " " - name))) + (let* + ((defs (ly:paper-book-book-paper book)) + (resolution (ly:output-def-lookup defs 'pngresolution))) + + (postscript->png (if (number? resolution) resolution 90) + name))) + +(define-public (convert-to-dvi book name) + (ly:warn "Can not generate DVI via the postscript back-end")) +(define-public (convert-to-ps book name) + #t) -; %%BoundingBox: 70 597 207 657 diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index f032dec482..754c50160d 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -103,12 +103,13 @@ (string-append "\\def\\" prefix (symbol->tex-key key) "{" (sanitize-tex-string str) "}%\n"))) -(define (header creator time-stamp bookpaper page-count classic?) +(define (header bookpaper page-count classic?) (let ((scale (ly:output-def-lookup bookpaper 'outputscale))) (string-append - "% Generated by " creator "\n" - "% at " time-stamp "\n" + "% Generated by LilyPond " + (lilypond-version) "\n" + "% at " "time-stamp,FIXME" "\n" (if classic? (tex-string-def "lilypond" 'classic "1") "") @@ -149,7 +150,7 @@ "}\\vss\n}\n\\vfill\n" "}\\vss\n}\n\\vfill\\lilypondpagebreak\n"))) -(define-public (output-framework outputter book scopes fields basename options) +(define-public (output-framework outputter book scopes fields basename ) (let* ((bookpaper (ly:paper-book-book-paper book)) (pages (ly:paper-book-pages book)) (last-page (car (last-pair pages))) @@ -158,7 +159,7 @@ (lambda (x) (ly:outputter-dump-string outputter x)) (list - (header "creator" "timestamp" bookpaper (length pages) #f) + (header bookpaper (length pages) #f) (define-fonts bookpaper) (header-end))) @@ -203,7 +204,7 @@ (define-public (output-preview-framework - outputter book scopes fields basename options) + outputter book scopes fields basename ) (let* ((bookpaper (ly:paper-book-book-paper book)) (lines (ly:paper-book-lines book))) (for-each @@ -219,3 +220,40 @@ (dump-line outputter (car lines) #t) (ly:outputter-dump-string outputter "\\lilypondend\n"))) + + +(define-public (convert-to-pdf book name) + (let* + ((defs (ly:paper-book-book-paper book)) + (size (ly:output-def-lookup book 'papersize))) + + (postscript->pdf (if (string? size) size "a4") + (string-append + (basename name ".tex") + ".ps") + ))) + +(define-public (convert-to-png book name) + (let* + ((defs (ly:paper-book-book-paper book)) + (resolution (ly:output-def-lookup defs 'pngresolution))) + + (postscript->png + (if (number? resolution) resolution 90) + (string-append (basename name ".tex") ".ps") + ))) + +(define-public (convert-to-ps book name) + (let* + ((cmd (string-append "dvips -u+ec-mftrace.map -u+lilypond.map -Ppdf " (basename name ".tex")))) + + (display (format #f "invoking ~S" cmd)) + (system cmd))) + +(define-public (convert-to-dvi book name) + (let* + ((cmd (string-append "latex " name))) + + (display (format #f "invoking ~S\n" cmd)) + (system cmd))) + diff --git a/scm/lily.scm b/scm/lily.scm index 5f1074ff4f..e5c27d303a 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -552,6 +552,26 @@ L1 is copied, L2 not. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(define-public (postscript->pdf papersize name) + (display + (string-append + "Converting to " + (regexp-substitute/global #f "\\.ps" name 'pre ".pdf" 'post) + "\n")) + (system (string-append "ps2pdf -sPAPERSIZE=" papersize + " " + name))) + + +(define-public (postscript->png resolution name) + (system (string-append + "ps2png --resolution=" + (if (number? resolution) + (number->string resolution) + "90") + " " + name))) + (define-public (lilypond-main files) "Entry point for LilyPond." (let* ((failed '()) diff --git a/scripts/ps2png.py b/scripts/ps2png.py new file mode 100644 index 0000000000..eb1ccedc5b --- /dev/null +++ b/scripts/ps2png.py @@ -0,0 +1,71 @@ +#!@PYTHON@ + +import operator +import stat +import string +import traceback +import glob +import getopt, os, sys +datadir = '@local_lilypond_datadir@' +if not os.path.isdir (datadir): + datadir = '@lilypond_datadir@' +if os.environ.has_key ('LILYPONDPREFIX') : + datadir = os.environ['LILYPONDPREFIX'] + while datadir[-1] == os.sep: + datadir= datadir[:-1] + + +sys.path.insert (0, os.path.join (datadir, 'python')) + +# Customize these +#if __name__ == '__main__': + +import lilylib as ly +global _;_=ly._ +global re;re = ly.re + +preview_resolution = 90 + +# lilylib globals +program_name = 'ps2png' +verbose_p = 0 +program_version = '@TOPLEVEL_VERSION@' +pseudo_filter_p = 0 # ugr. + +help_summary = _ ("Convert PostScript to PNG image.") +copyright = ('Han-Wen Nienhuys