(post_processing): new function. Do PDF/PNG conversion.
* lily/paper-outputter.cc (close): new function.
* scm/framework-ps.scm (convert-to-pdf): new function. Call
ps2pdf.
(output-preview-framework): new function. Generate a preview .ps
+2004-07-24 Han-Wen Nienhuys <hanwen@xs4all.nl>
+
+ * lily/paper-book.cc (output): call output-preview-framework
+ (post_processing): new function. Do PDF/PNG conversion.
+
+ * lily/paper-outputter.cc (close): new function.
+
+ * scm/framework-ps.scm (convert-to-pdf): new function. Call
+ ps2pdf.
+ (output-preview-framework): new function. Generate a preview .ps
+
+
2004-07-23 Han-Wen Nienhuys <hanwen@xs4all.nl>
+ * VERSION: release 2.3.8
+
* lily/note-head.cc: remove ledger line handling.
* lily/ambitus.cc (print): strip away accidental / note head code,
extern bool verbose_global_b;
extern bool store_locations_global_b;
extern bool internal_type_checking_global_b;
-extern bool debug_beam_quanting_flag;
-
+extern bool make_png;
+extern bool make_pdf;
+extern bool make_preview;
/* misc */
extern Array<String> failed_files;
Stencil score_title (int);
void classic_output (String);
void output (String);
+ void post_processing (SCM, SCM);
};
DECLARE_UNSMOB (Paper_book, paper_book)
Paper_outputter (String nm, String format);
SCM scheme_to_string (SCM);
void output_stencil (Stencil);
+ void close();
};
Paper_outputter *get_paper_outputter (String, String);
*/
String init_scheme_code_string = "(begin #t ";
-
+bool make_pdf = false;
+bool make_png = false;
+bool make_preview = false;
/*
* Miscellaneous global stuff.
{_i ("FILE"), "init", 'i', _i ("use FILE as init file")},
{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, "safe-mode", 's', _i ("run in safe mode")},
{0, "version", 'v', _i ("print version number")},
{0, "verbose", 'V', _i ("be verbose")},
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;
return lst;
}
+void
+Paper_book::post_processing (SCM module,
+ SCM file_name)
+{
+ if (make_pdf)
+ {
+ SCM func = scm_c_module_lookup (module, "convert-to-pdf");
+ 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);
+ }
+ }
+
+ 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);
+ }
+ }
+}
void
Paper_book::output (String outname)
{
for (SCM s = formats; ly_c_pair_p (s); s = ly_cdr (s))
{
String format = ly_scm2string (ly_car (s));
- Paper_outputter *out = get_paper_outputter (outname + "." + format,
- format);
+ String file_name = outname + "." + format;
+ Paper_outputter *out = get_paper_outputter (file_name, format);
SCM scopes = SCM_EOL;
if (ly_c_module_p (header_))
dump_fields (),
scm_makfrom0str (outname.to_str0 ()),
SCM_UNDEFINED));
-
+ out->close ();
scm_gc_unprotect_object (out->self_scm ());
+
+ post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
+
+ if (make_preview)
+ {
+ String file_name = outname + ".preview." + format;
+ Paper_outputter *out = get_paper_outputter (file_name, format);
+
+ SCM func = scm_c_module_lookup (mod, "output-preview-framework");
+ func = scm_variable_ref (func);
+ scm_apply_0 (func, scm_list_n (out->self_scm (),
+ self_scm (),
+ scopes,
+ dump_fields (),
+ scm_makfrom0str (outname.to_str0 ()),
+ SCM_UNDEFINED));
+
+ out->close ();
+ scm_gc_unprotect_object (out->self_scm ());
+
+ post_processing (mod, scm_makfrom0str (file_name.to_str0 ()));
+ }
+
progress_indication ("\n");
}
}
Paper_outputter *out = get_paper_outputter (outname + "." + format,
format);
- scm_apply_0 (func, scm_list_5 (out->self_scm (), self_scm (), scopes,
+ scm_apply_0 (func, scm_list_n (out->self_scm (), self_scm (), scopes,
dump_fields (),
- scm_makfrom0str (outname.to_str0 ())));
+ scm_makfrom0str (outname.to_str0 ()),
+ SCM_UNDEFINED));
scm_gc_unprotect_object (out->self_scm ());
progress_indication ("\n");
return po->dump_string (str);
}
+
+void
+Paper_outputter::close ()
+{
+ scm_close_port (file_);
+}
(srfi srfi-13)
(lily))
+(define mm-to-bigpoint
+ (/ 72 25.4))
+
(define-public (ps-font-command font . override-coding)
(let* ((name (ly:font-filename font))
(magnify (ly:font-magnification font))
(value->string (ly:output-def-lookup paper ly-key)) " def \n"))
(string-append
- "/lily-output-units 2.83464 def %% milimeter \n"
- "% /lily-output-units 0.996264 def %% true points.\n"
+ "/lily-output-units " (number->string mm-to-bigpoint) " def %% milimeter \n"
(output-entry "staff-line-thickness" 'linethickness)
(output-entry "line-width" 'linewidth)
(output-entry "paper-size" 'papersize)
(number->string (ly:output-def-lookup paper 'outputscale))
" lily-output-units mul def \n"))
-(define (header paper page-count classic?)
- (string-append
- "%!PS-Adobe-3.0\n"
- "%%Creator: creator time-stamp \n"))
-
(define (dump-page outputter page page-number page-count)
(ly:outputter-dump-string outputter
(string-append
(ly:outputter-dump-stencil outputter page)
(ly:outputter-dump-string outputter "} stop-system \nshowpage\n"))
+(define (eps-header bookpaper bbox)
+ (string-append "%!PS-Adobe-2.0 EPSF-2.0\n"
+ "%%Creator: creator time-stamp\n"
+ "%%BoundingBox: " (string-join (map number->string bbox) " ") "\n"
+ "%%EndComments\n"))
+
+(define (page-header bookpaper page-count)
+ (string-append "%!PS-Adobe-3.0\n"
+ "%%Creator: creator time-stamp\n"
+ "%%Pages: " (number->string page-count) "\n"
+ "%%PageOrder: Ascend\n"
+ "%%DocumentPaperSizes: " (ly:output-def-lookup bookpaper 'papersize) "\n"))
+
+(define (preamble bookpaper)
+ (list
+ (output-variables bookpaper)
+ (ly:gulp-file "music-drawing-routines.ps")
+ (ly:gulp-file "lilyponddefs.ps")
+ (load-fonts bookpaper)
+ (define-fonts bookpaper)))
+
(define-public (output-framework outputter book scopes fields basename)
(let* ((bookpaper (ly:paper-book-book-paper book))
(pages (ly:paper-book-pages book))
(for-each
(lambda (x)
(ly:outputter-dump-string outputter x))
- (list
- (header bookpaper
- (length pages)
- #f)
-
- "%%Pages: " (number->string page-count) "\n"
- "%%PageOrder: Ascend\n"
- "%%DocumentPaperSizes: " (ly:output-def-lookup bookpaper 'papersize) "\n"
-
- (output-variables bookpaper)
- (ly:gulp-file "music-drawing-routines.ps")
- (ly:gulp-file "lilyponddefs.ps")
- (load-fonts bookpaper)
- (define-fonts bookpaper)))
-
+ (cons
+ (page-header bookpaper page-count)
+ (preamble bookpaper)))
+
(for-each
(lambda (page)
(set! page-number (1+ page-number))
pages)
(ly:outputter-dump-string outputter "%%Trailer\n%%EOF\n")))
-(define-public (output-classic-framework outputter book scopes fields
- basename)
+(define-public (output-preview-framework outputter book scopes fields basename)
(let* ((bookpaper (ly:paper-book-book-paper book))
- (lines (ly:paper-book-lines book))
- (y 0.0)
- ;; What the F*** is 2.83463?
- (scale (* 2.83464 (ly:output-def-lookup bookpaper 'outputscale)))
- (total-y
- (apply + (map (lambda (z) (ly:paper-system-extent z Y)) lines)))
- (x-ext '(-8 . 0))
- (lineno 0))
-
- (define (dump-line outputter system)
- (let ((stil (ly:paper-system-stencil system)))
-
- (ly:outputter-dump-string
- outputter
- (string-append
- " 0.0 "
- (ly:number->string y)
- " start-system {\n set-ps-scale-to-lily-scale\n"))
- (set! y (+ y (ly:paper-system-extent system Y)))
- (ly:outputter-dump-stencil outputter stil)
- (ly:outputter-dump-string
- outputter
- "} stop-system\n")))
-
- (define (to-pt x)
- (inexact->exact (round (* scale x))))
-
- (define (bbox llx lly urx ury)
- (string-append
- "%%BoundingBox: "
- (ly:number->string (to-pt llx)) " "
- (ly:number->string (to-pt lly)) " "
- (ly:number->string (to-pt urx)) " "
- (ly:number->string (to-pt ury)) "\n"))
-
- (for-each
- (lambda (ell)
- (set! x-ext (interval-union x-ext
- (cons 0.0 (ly:paper-system-extent ell X)))))
- lines)
-
+ (systems (ly:paper-book-lines book))
+ (scale (ly:output-def-lookup bookpaper '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)))))
+ (xext (ly:stencil-extent dump-me X))
+ (yext (ly:stencil-extent dump-me Y))
+ )
+
(for-each
(lambda (x)
(ly:outputter-dump-string outputter x))
- (list
- "%!PS-Adobe-2.0 EPSF-2.0\n"
- "%%Creator: LilyPond \n"
+ (cons
+ (eps-header bookpaper
+ (map
+ (lambda (x)
+ (inexact->exact
+ (round (* x scale mm-to-bigpoint))))
+ (list (car xext) (car yext)
+ (cdr xext) (cdr yext))))
+ (preamble bookpaper)))
-;; (bbox (car x-ext) 0 (cdr x-ext) total-y) ; doesn't work well
- "%%EndComments\n"
- (output-variables bookpaper)
- (ly:gulp-file "music-drawing-routines.ps")
- (ly:gulp-file "lilyponddefs.ps")
- (load-fonts bookpaper)
- (define-fonts bookpaper)))
+ (ly:outputter-dump-string outputter
+ (string-append "0 0 start-system { "
+ "set-ps-scale-to-lily-scale "
+ "\n"))
+ (ly:outputter-dump-stencil outputter dump-me)
+ (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)))
-;; ; page-number page-count))
- (for-each
- (lambda (line) (set! lineno (1+ lineno)) (dump-line outputter line))
- lines)
- (ly:outputter-dump-string outputter "\n")))
+
+(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)))
+
+
+; %%BoundingBox: 70 597 207 657
"}\\vss\n}\n\\vfill\n"
"}\\vss\n}\n\\vfill\\lilypondpagebreak\n")))
-(define-public (output-framework outputter book scopes fields basename)
+(define-public (output-framework outputter book scopes fields basename options)
(let* ((bookpaper (ly:paper-book-book-paper book))
(pages (ly:paper-book-pages book))
(last-page (car (last-pair pages)))
(define-public (output-preview-framework
- outputter book scopes fields basename)
+ outputter book scopes fields basename options)
(let* ((bookpaper (ly:paper-book-book-paper book))
(lines (ly:paper-book-lines book)))
(for-each