From: Han-Wen Nienhuys Date: Sun, 30 May 2004 21:55:13 +0000 (+0000) Subject: * python/lilylib.py (make_ps_images): only compute bbox when needed. X-Git-Tag: release/2.3.3~3 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=a2e0081b9f6263a3ddb8e7bf898f6592dad5f89e;p=lilypond.git * python/lilylib.py (make_ps_images): only compute bbox when needed. * scripts/lilypond-book.py (process_snippets): use lily -f ps files for generating pngs. * scm/framework-ps.scm (output-classic-framework-ps): dump EPS file with PFA fonts included. * lily/score.cc (default_rendering): put header in too. * lily/paper-line.cc (LY_DEFINE): change function to ly:paper-line-extent * scm/page-layout.scm (default-book-title): only add lines for non-nil fields. (default-score-title): idem. * lily/paper-book.cc (book_title): separate function for the book title. * scm/page-layout.scm (default-book-title): only account for markup fields. * scm/framework-ps.scm: new file. Move high level interface from output-ps.scm * scm/framework-tex.scm (dump-line): new file. High level interface for output (pages, systems, header). * lily/paper-book.cc (split_string): new function (output): output multiple formats, i.e. --format=ps,tex --- diff --git a/ChangeLog b/ChangeLog index bdc094a535..e9eae179a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,22 @@ 2004-05-30 Han-Wen Nienhuys + * python/lilylib.py (make_ps_images): only compute bbox when needed. + + * scripts/lilypond-book.py (process_snippets): use lily -f ps + files for generating pngs. + + * scm/framework-ps.scm (output-classic-framework-ps): dump EPS + file with PFA fonts included. + + * lily/score.cc (default_rendering): put header in too. + + * lily/paper-line.cc (LY_DEFINE): change function to + ly:paper-line-extent + + * scm/page-layout.scm (default-book-title): only add lines for + non-nil fields. + (default-score-title): idem. + * lily/my-lily-parser.cc (parse_string): delete lexer after use. * lily/my-lily-lexer.cc (My_lily_lexer): copy keytable. diff --git a/lily/font-metric.cc b/lily/font-metric.cc index 509daa608d..9af80e5738 100644 --- a/lily/font-metric.cc +++ b/lily/font-metric.cc @@ -196,7 +196,7 @@ LY_DEFINE (ly_font_name,"ly:font-name", 1, 0, 0, (SCM font), "Given the font metric @var{font}, " - "return the corresponding file name.") + "return the corresponding name.") { Font_metric *fm = unsmob_metrics (font); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index acc87f61ab..6c5c02dabb 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -154,7 +154,7 @@ Paper_book::output (String outname) if (ly_c_module_p (header_)) scopes = scm_cons (header_, scopes); - String func_nm = output_format_global; + String func_nm = format; func_nm = "output-framework-" + func_nm; SCM func = ly_scheme_function (func_nm.to_str0 ()); @@ -174,8 +174,6 @@ Paper_book::output (String outname) void Paper_book::classic_output (String outname) { - String format = "tex"; - Paper_outputter *out = get_paper_outputter (outname + "." + format, format); /* Generate all stencils to trigger font loads. */ lines (); @@ -189,19 +187,31 @@ Paper_book::classic_output (String outname) if (ly_c_module_p (score_lines_[0].header_)) scopes = scm_cons (score_lines_[0].header_, scopes); //end ugh - - String func_nm = output_format_global; - func_nm = "output-classic-framework-" + func_nm; + + + Array output_formats = split_string (output_format_global, ','); + + for (int i = 0; i < output_formats.size (); i++) + { + String format = output_formats[i]; + String func_nm = format; + func_nm = "output-classic-framework-" + func_nm; - SCM func = ly_scheme_function (func_nm.to_str0 ()); - scm_apply_0 (func, scm_list_n (out->self_scm (), - self_scm (), - scopes, - dump_fields (), - scm_makfrom0str (outname.to_str0 ()), - SCM_UNDEFINED - )) ; + SCM func = ly_scheme_function (func_nm.to_str0 ()); + Paper_outputter *out = get_paper_outputter (outname + "." + format, format); + + scm_apply_0 (func, scm_list_n (out->self_scm (), + self_scm (), + scopes, + dump_fields (), + scm_makfrom0str (outname.to_str0 ()), + SCM_UNDEFINED + )) ; + + scm_gc_unprotect_object (out->self_scm ()); + } + progress_indication ("\n"); } @@ -428,11 +438,11 @@ c_ragged_page_breaks (SCM lines, Real book_height =0.; for (SCM s = lines ; ly_c_pair_p (s); s = ly_cdr (s)) { - book_height += unsmob_paper_line (s)->dim ()[Y_AXIS]; + book_height += unsmob_paper_line (ly_car (s))->dim ()[Y_AXIS]; } /* - UGH. + UGH. following stuff should go out of C++. */ SCM scopes = SCM_EOL; if (ly_c_module_p (book->header_)) diff --git a/lily/paper-line.cc b/lily/paper-line.cc index b4dbf3b7a1..945435365e 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -91,15 +91,18 @@ Paper_line::to_stencil () const return stencil_; } -LY_DEFINE (ly_paper_line_height, "ly:paper-line-height", - 1, 0, 0, (SCM line), - "Return the height of @var{line}.") +LY_DEFINE (ly_paper_line_height, "ly:paper-line-extent", + 2, 0, 0, (SCM line, SCM axis), + "Return the extent of @var{line}.") { Paper_line *pl = unsmob_paper_line (line); SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line"); - return scm_make_real (pl->dim ()[Y_AXIS]); + SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis"); + Axis ax = (Axis)ly_scm2int (axis); + return scm_make_real (pl->dim ()[ax]); } + LY_DEFINE (ly_paper_line_number, "ly:paper-line-number", 1, 0, 0, (SCM line), "Return the number of @var{line}.") diff --git a/lily/score.cc b/lily/score.cc index 7757b6a37d..aaa6663616 100644 --- a/lily/score.cc +++ b/lily/score.cc @@ -195,7 +195,7 @@ default_rendering (SCM music, SCM outdef, ugh, this is strange, Paper_book without a Book object. */ Paper_book *paper_book = new Paper_book (); - + paper_book->header_ = header; paper_book->bookpaper_ = unsmob_output_def (scaled_bookdef); Score_lines sc; diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index 7971229f07..be3831dc79 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -13,8 +13,7 @@ TODO: naming add/combine. */ /* - UMGH. junkme! - + UGH. Junk all mutators. */ LY_DEFINE (ly_stencil_set_extent_x, "ly:stencil-set-extent!", 3, 0, 0, (SCM stil, SCM axis, SCM np), diff --git a/python/lilylib.py b/python/lilylib.py index 4df1532a19..01b3e80540 100644 --- a/python/lilylib.py +++ b/python/lilylib.py @@ -456,15 +456,22 @@ def make_ps_images (ps_name, resolution = 90): base = re.sub (r'\.e?ps', '', ps_name) header = open (ps_name).read (1024) + + match = re.match (BOUNDING_BOX_RE, header) + bbox = [] + if match: + bbox = map (string.atoi, match.groups ()) + multi_page = re.search ('\n%%Pages: ', header) cmd = '' if multi_page == None: - bbox = get_bbox (ps_name) + + if bbox == []: + bbox = get_bbox (ps_name) + trans_ps = ps_name + '.trans.ps' output_file = re.sub (r'\.e?ps', '.png', ps_name) - - # need to have margin, otherwise edges of letters will # be cropped off. @@ -508,3 +515,8 @@ def make_ps_images (ps_name, resolution = 90): os.unlink (png) error (_ ("Removing output file")) exit (1) + + + cmd = r'''gs -s -sDEVICE=pnggray -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -q -sOutputFile=%s -dNOPAUSE -r%d %s -c quit''' % (output_file, + resolution, ps_name) + diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index 69311a4ad9..49f382b227 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -13,6 +13,21 @@ (equal? (substring fontname 0 2) "cm")) +(define (load-fonts bookpaper) + + (let* + ((fonts (ly:bookpaper-fonts bookpaper)) + (font-names (uniq-list (sort (map ly:font-filename fonts) stringstring page-count) "\n" - "%%PageOrder: Ascend\n" - "%%DocumentPaperSizes: " (ly:output-def-lookup paper 'papersize) "\n" - ;;(string-append "GNU LilyPond (" (lilypond-version) "), ") - ;; (strftime "%c" (localtime (current-time)))) - ;; FIXME: duplicated in every backend - (ps-string-def - "lilypond" 'tagline - (string-append "Engraved by LilyPond (version " (lilypond-version) ")")) )) (define (dump-page outputter page page-number page-count) @@ -150,6 +158,10 @@ (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") @@ -165,40 +177,63 @@ )) -(define (dump-line outputter system) - (ly:outputter-dump-string - outputter - " start-system {\n set-ps-scale-to-lily-scale\n") - (ly:outputter-dump-stencil outputter (ly:page-line-stencil system)) - (ly:outputter-dump-string - outputter - "} stop-system\n")) (define-public (output-classic-framework-ps outputter book scopes fields basename) (let* ((bookpaper (ly:paper-book-book-paper book)) (lines (ly:paper-book-lines book)) - (pageno 0) - (page-count (length lines)) + (y 0.0) + (scale (* 2.83464 (ly:output-def-lookup bookpaper 'outputscale))) + (total-y (apply + (map (lambda (z) (ly:paper-line-extent z Y)) lines))) + (x-ext '(-8 . 0)) + (lineno 0) ) + + (define (dump-line outputter system) + (let* + ((stil (ly:paper-line-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-line-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)))) + (for-each (lambda (l) + (set! x-ext (interval-union x-ext (cons 0.0 (ly:paper-line-extent l X)))) + ) + lines) (for-each (lambda (x) (ly:outputter-dump-string outputter x)) (list - (header bookpaper - (length pages) - #f) - + "%!PS-Adobe-2.0 EPSF-2.0\n" + "%%Creator: LilyPond \n" + "%%BoundingBox: " + (ly:number->string (to-pt (car x-ext))) " " + (ly:number->string (to-pt 0)) " " + (ly:number->string (to-pt (cdr x-ext))) " " + (ly:number->string (to-pt total-y)) "\n" + "%%EndComments\n" (output-variables bookpaper) (ly:gulp-file "music-drawing-routines.ps") (ly:gulp-file "lilyponddefs.ps") + (load-fonts bookpaper) (define-fonts bookpaper) )) (for-each (lambda (line) - (set! pageno (1+ pageno)) + (set! lineno (1+ lineno)) (dump-line outputter line)) ; pageno page-count)) lines) (ly:outputter-dump-string outputter "\n") diff --git a/scm/framework-tex.scm b/scm/framework-tex.scm index 16682df3db..69d4a99ada 100644 --- a/scm/framework-tex.scm +++ b/scm/framework-tex.scm @@ -121,16 +121,16 @@ (ly:outputter-dump-string putter (string-append "\\leavevmode\n\\lybox{0}{0}{0}{" - (ly:number->string (ly:paper-line-height line)) + (ly:number->string (ly:paper-line-extent line Y)) "}{")) (ly:outputter-dump-stencil putter (ly:paper-line-stencil line)) (ly:outputter-dump-string putter (if last? + "}%\n" "}\\interscoreline\n" - "}%\n")) - ) + )) ) (define-public (output-framework-tex outputter book scopes fields basename) (let* @@ -172,10 +172,10 @@ bookpaper (length lines) #f) - - (output-scopes scopes fields basename) - (define-fonts bookpaper) - (header-end))) + "\\def\\lilypondclassic{1}%\n" + (output-scopes scopes fields basename) + (define-fonts bookpaper) + (header-end))) (for-each (lambda (line) diff --git a/scm/page-layout.scm b/scm/page-layout.scm index 5312e1a3b5..c8168c138d 100644 --- a/scm/page-layout.scm +++ b/scm/page-layout.scm @@ -78,7 +78,7 @@ (define (robust-line-height line) (if (null? line) 0 - (ly:paper-line-height line))) + (ly:paper-line-extent line Y))) (define (robust-line-number node) (if (null? node) 0 @@ -225,38 +225,75 @@ (define (get sym) (let ((x (ly:modules-lookup scopes sym))) (if (markup? x) x ""))) - + (define (has sym) + (markup? (ly:modules-lookup scopes sym))) + (let ((props (page-properties paper))) (interpret-markup paper props - (markup - #:column - (#:override '(baseline-skip . 4) - #:column - (#:fill-line - (#:normalsize (get 'dedication)) - #:fill-line - (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title)) - #:override '(baseline-skip . 3) - #:column - (#:fill-line - (#:large #:bigger #:bigger #:bold (get 'subtitle)) - #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle))) - #:override '(baseline-skip . 5) - #:column ("") - #:override '(baseline-skip . 2.5) - #:column - (#:fill-line - (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer)) - #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus)) - #:fill-line - (#:bigger (get 'meter) #:bigger (get 'arranger)) - "" - #:fill-line (#:large #:bigger (get 'instrument)) - " " - #:fill-line (#:large #:bigger #:caps (get 'piece) "")))))))) - + (make-override-markup + '(baseline-skip . 4) + (make-column-markup + (append + (if (has 'dedication) + (list (markup #:fill-line + (#:normalsize (get 'dedication)))) + '()) + + (if (has 'title) + (list (markup (#:fill-line + (#:huge #:bigger #:bigger #:bigger #:bigger #:bold (get 'title))))) + '()) + + (if (or (has 'subtitle) (has 'subsubtitle)) + (list + (make-override-markup + '(baseline-skip . 3) + (make-column-markup + (list + (markup #:fill-line + (#:large #:bigger #:bigger #:bold (get 'subtitle)) + #:fill-line (#:bigger #:bigger #:bold (get 'subsubtitle))) + (markup #:override '(baseline-skip . 5) + #:column (""))) + + )) + ) + '()) + + (list + (make-override-markup + '(baseline-skip . 2.5) + (make-column-markup + (append + (if (or (has 'poet) (has 'composer)) + (list (markup #:fill-line + (#:bigger (get 'poet) #:large #:bigger #:caps (get 'composer)))) + '()) + (if (or (has 'texttranslator) (has 'opus)) + (list + (markup + #:fill-line (#:bigger (get 'texttranslator) #:bigger (get 'opus)))) + '()) + (if (or (has 'meter) (has 'arranger)) + (list + (markup #:fill-line + (#:bigger (get 'meter) #:bigger (get 'arranger)))) + '()) + + (if (has 'instrument) + (list "" + (markup #:fill-line (#:large #:bigger (get 'instrument)))) + '()) + (if (has 'piece) + (list "" + (markup #:fill-line (#:large #:bigger #:caps (get 'piece) ""))) + '()) + ))))))) + ))) + + (define-public (default-user-title paper markup) "Generate book title from header markup." (if (markup? markup) @@ -270,16 +307,24 @@ (define (get sym) (let ((x (ly:modules-lookup scopes sym))) - (if (and x (not (unspecified? x))) x ""))) + (if (markup? x) x ""))) + + (define (has sym) + (markup? (ly:modules-lookup scopes sym))) (let ((props (page-properties paper))) (interpret-markup paper props - (markup - #:column - (#:override '(baseline-skip . 4) - #:column - (#:fill-line - ("" (get 'opus)) - #:fill-line (#:large #:bigger #:caps (get 'piece) ""))))))) + (make-override-markup + '(baseline-skip . 4) + (make-column-markup + (append + (if (has 'opus) + (list (markup #:fill-line ("" (get 'opus)))) + '()) + (if (has 'piece) + (list (markup #:fill-line (#:large #:bigger #:caps (get 'piece) ""))) + '())) + + ))))) diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index bcd9a41fa4..a99269de54 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -96,7 +96,7 @@ ly:paper-get-font ly:paper-get-number ly:paper-line-break-score - ly:paper-line-height + ly:paper-line-extent ly:paper-line-number ly:paper-line-stencil ly:paper-line? diff --git a/scripts/lilypond-book.py b/scripts/lilypond-book.py index 1da2f27ff7..c22601f381 100644 --- a/scripts/lilypond-book.py +++ b/scripts/lilypond-book.py @@ -795,9 +795,12 @@ def process_snippets (cmd, snippets): if format == HTML or format == TEXINFO: for i in names: - if os.path.exists (i + '.tex'): + if not os.path.exists (i + '.ps') and os.path.exists (i + '.tex'): to_eps (i) ly.make_ps_images (i + '.eps', resolution=110) + elif os.path.exists (i + '.ps'): + ly.make_ps_images (i + '.ps', resolution=110) + LATEX_DOCUMENT = r''' %(preamble)s