]> git.donarmstrong.com Git - lilypond.git/commitdiff
* scm/lily.scm (postscript->png): new function
authorHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 24 Jul 2004 11:38:20 +0000 (11:38 +0000)
committerHan-Wen Nienhuys <hanwen@xs4all.nl>
Sat, 24 Jul 2004 11:38:20 +0000 (11:38 +0000)
(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

14 files changed:
ChangeLog
Documentation/user/invoking.itexi
flower/include/getopt-long.hh
lily/include/lily-guile.hh
lily/include/main.hh
lily/main.cc
lily/mensural-ligature.cc
lily/paper-book.cc
lily/vaticana-ligature.cc
python/lilylib.py
scm/framework-ps.scm
scm/framework-tex.scm
scm/lily.scm
scripts/ps2png.py [new file with mode: 0644]

index 63814c51b3240360390f023268cbc1ced01a3b4d..6d57c41b9e9a982f71149f19e865a95aed2cd768 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2004-07-24  Han-Wen Nienhuys   <hanwen@xs4all.nl>
 
+       * 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.
 
index 999f81574f143eb23641e535440dae41c024e92e..92fe71fddbc7538cce3d4fc1b7fa8a65ad2f5335 100644 (file)
@@ -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. 
index a909326d4cc455c06d1c8cf1661bcb1e4a4dafb2..4387e579327a41c69fbdf99d3ed3071a47668bfc 100644 (file)
 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_;
   
index 3042c980e1aa347d1584416cac3cb931ed5cd5f7..45f0f820b14d6451e380c9ec7869649b4513f600 100644 (file)
@@ -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.
index bafde2f92ea88fa484b1b84b4149ba51172a03a3..6319df9b68131ded8d34daa64642d037a2e601a8 100644 (file)
@@ -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;
 
index ce647209779cb5f1a23590f390381657e4441394..35d07b844a781cdf4ba010daaec2b2e7f953965e 100644 (file)
@@ -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;
index b64fc88af8aecd656003124933466dedcd87c925..3d344a9a0e3a4bc8548564a175c183c94271eb62 100644 (file)
@@ -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);
index 6e739723cf50f3b4e3a32b48efcd247eedf78577..a94be54856a37675f53d1af68fdfdfb25438d49c 100644 (file)
@@ -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)
 {
index dfbd257ac248264b5f852df62dfaa0aa030ffda9..ff6289feb2982887f6b9db4d4e6db0c450c4e032 100644 (file)
@@ -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;
 }
 
index 2da37b1083d9f282f4bfddf3d878b0d9d6b31e50..0f48d4dac05465d0e1bc156d0fa938a0106ab7a5 100644 (file)
@@ -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
+
index 99ed406caef891b2c280b25f084c97d24b5a66a9..f26593219758ba092ca65a37a0f1372a6d846081 100644 (file)
   (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
index f032dec4821dfbed401fb2f8913de8bee10227a2..754c50160d6007c590c3b3c82e0be149d2eeeb3e 100644 (file)
       (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")
         "")
        "}\\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)))
      (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)))
     
 
 
 (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
 
     (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)))
+
index 5f1074ff4fcf650c48d44f4bb0784d115314cf40..e5c27d303aed555e2a1d689f91df7212e3e29c97 100644 (file)
@@ -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 (file)
index 0000000..eb1cced
--- /dev/null
@@ -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 <hanwen@cs.uu.nl',
+            'Jan Nieuwenhuizen <janneke@gnu.org')
+
+option_definitions = [
+       ('', 'h', 'help', _ ("print this help")),
+       ('', 'V', 'verbose', _ ("be verbose")),
+       (_ ('RES'), 'R', 'resolution',
+        _ ("set the resolution of the preview to RES")),
+       ]
+
+(sh, long) = ly.getopt_args (option_definitions)
+try:
+       (options, files) = getopt.getopt (sys.argv[1:], sh, long)
+except getopt.error, s:
+       sys.stderr.write ('\n')
+       ly.error (_ ("getopt says: `%s\'" % s))
+       sys.stderr.write ('\n')
+       ly.help ()
+       ly.exit (2)
+       
+for opt in options:
+       o = opt[0]
+       a = opt[1]
+
+       if o == '--help' or o == '-h':
+               ly.help ()
+               sys.exit (0)
+       elif o == '--resolution' or o == '-R':
+               preview_resolution = string.atoi (a)
+       elif o == '--verbose' or o == '-V':
+               verbose_p = 1
+
+for f in files:
+       out = ly.make_ps_images (f, 
+                          resolution = preview_resolution)
+       sys.stderr.write (_("Written `%s'\n"  % out ))