1 ;;;; This file is part of LilyPond, the GNU music typesetter.
3 ;;;; Copyright (C) 2004--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;; LilyPond is free software: you can redistribute it and/or modify
6 ;;;; it under the terms of the GNU General Public License as published by
7 ;;;; the Free Software Foundation, either version 3 of the License, or
8 ;;;; (at your option) any later version.
10 ;;;; LilyPond is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;;;; GNU General Public License for more details.
15 ;;;; You should have received a copy of the GNU General Public License
16 ;;;; along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (scm framework-ps))
20 ;;; this is still too big a mess.
22 (use-modules (ice-9 string-fun)
31 (define format ergonomic-simple-format)
33 (define framework-ps-module (current-module))
35 ;;(define pdebug stderr)
36 (define (pdebug . rest) #f)
38 (define-public (ps-font-command font)
39 (let* ((name (ly:font-file-name font))
40 (magnify (ly:font-magnification font)))
49 "m" (string-encode-integer (inexact->exact (round (* 1000 magnify)))))))
51 (define (ps-define-pango-pf pango-pf font-name scaling)
54 (define (ps-define-font font font-name scaling)
57 "/" (ps-font-command font) "-N"
59 " " (ly:number->string scaling) " output-scale div selectfont }"
61 "/" (ps-font-command font) "-S"
63 " " (ly:number->string scaling) " output-scale div selectfont }"
65 "/" (ps-font-command font) "-O"
67 " " (ly:number->string scaling) " output-scale div selectfont }"
69 "/help" font-name " {\n gsave\n 1 setgray\n /"
71 " 0.001 selectfont 0 0 moveto <01> show\n /"
73 " 0.001 selectfont 0 0 moveto <01> show\n /"
75 " 0.001 selectfont 0 0 moveto <01> show\n grestore\n} def\n")
77 "/" (ps-font-command font)
79 " " (ly:number->string scaling) " output-scale div selectfont }"
82 ;; FIXME: duplicated in other output backends
83 ;; FIXME: silly interface name
84 (define (output-variables layout)
85 ;; FIXME: duplicates output-layout's scope-entry->string, mostly
86 (define (value->string val)
88 ((string? val) (string-append "(" val ")"))
89 ((symbol? val) (symbol->string val))
90 ((number? val) (number->string val))
93 (define (output-entry ps-key ly-key)
96 (value->string (ly:output-def-lookup layout ly-key)) " def\n"))
100 (number->string (/ (ly:bp 1))) " def %% millimeter\n"
101 (output-entry "staff-line-thickness" 'line-thickness)
102 (output-entry "line-width" 'line-width)
103 (output-entry "paper-size" 'papersizename)
104 (output-entry "staff-height" 'staff-height) ;junkme.
106 (number->string (ly:output-def-lookup layout 'output-scale)) " def\n"
107 (output-entry "page-height" 'paper-height)
108 (output-entry "page-width" 'paper-width)
109 (if (ly:get-option 'strokeadjust) "true setstrokeadjust\n" "")
112 (define (dump-page outputter page page-number page-count landscape?)
113 (ly:outputter-dump-string
116 (format #f "%%Page: ~a ~a\n" page-number page-number)
119 "page-width output-scale lily-output-units mul mul 0 translate 90 rotate\n"
123 "gsave 0 paper-height translate set-ps-scale-to-lily-scale\n"
124 "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n"
125 "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n"
126 "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n"
127 "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n"
128 "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n"
129 "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n"
130 "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n"
131 "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n"
132 "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n"))
133 (ly:outputter-dump-stencil outputter page)
134 (ly:outputter-dump-string outputter "stroke grestore\nshowpage\n"))
136 (define (supplies-or-needs paper load-fonts?)
137 (define (extract-names font)
138 (if (ly:pango-font? font)
139 (map car (ly:pango-font-physical-fonts font))
140 (list (ly:font-name font))))
142 (let* ((fonts (ly:paper-fonts paper))
143 (names (append-map extract-names fonts)))
148 "%%DocumentSuppliedResources: font ~a\n"
149 "%%DocumentNeededResources: font ~a\n")
151 (uniq-list (sort names string<?))))))
153 (define (eps-header paper bbox load-fonts?)
154 (string-append "%!PS-Adobe-2.0 EPSF-2.0\n"
155 "%%Creator: LilyPond " (lilypond-version) "\n"
157 (string-join (map ly:number->string bbox) " ") "\n"
159 (if (eq? (ly:output-def-lookup paper 'landscape) #t)
162 (supplies-or-needs paper load-fonts?)
165 (define (ps-document-media paper)
167 (ly:output-def-lookup paper 'output-scale)
168 (ly:output-def-lookup paper 'paper-width)) (ly:bp 1)))
170 (ly:output-def-lookup paper 'paper-height)
171 (ly:output-def-lookup paper 'output-scale))
173 (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t)))
174 (ly:format "%%DocumentMedia: ~a ~2f ~2f ~a ~a ~a\n"
175 (ly:output-def-lookup paper 'papersizename)
183 (define (file-header paper page-count load-fonts?)
184 (string-append "%!PS-Adobe-3.0\n"
185 "%%Creator: LilyPond " (lilypond-version) "\n"
186 "%%Pages: " (number->string page-count) "\n"
187 "%%PageOrder: Ascend\n"
189 (if (eq? (ly:output-def-lookup paper 'landscape) #t)
192 (ps-document-media paper)
193 (supplies-or-needs paper load-fonts?)
196 (define (procset file-name)
198 "%%BeginResource: procset (~a) 1 0
202 file-name (cached-file-contents file-name)))
204 (define (embed-document file-name)
205 (format #f "%%BeginDocument: ~a
209 file-name (cached-file-contents file-name)))
211 (define (setup-variables paper)
214 (define-fonts paper ps-define-font ps-define-pango-pf)
215 (output-variables paper)))
217 (define (cff-font? font)
218 (let* ((cff-string (ly:otf-font-table-data font "CFF ")))
219 (> (string-length cff-string) 0)))
221 (define-public (ps-embed-cff body font-set-name version)
224 (format #f "/~a ~s StartData " font-set-name (string-length body))
228 "%%BeginResource: font ~a
229 %!PS-Adobe-3.0 Resource-FontSet
230 %%DocumentNeededResources: ProcSet (FontSetInit)
231 %%Title: (FontSet/~a)
234 %%IncludeResource: ProcSet (FontSetInit)
235 %%BeginResource: FontSet (~a)
236 /FontSetInit /ProcSet findresource begin
237 %%BeginData: ~s Binary Bytes
239 font-set-name font-set-name version font-set-name
240 (string-length binary-data)))
244 (string-append header
248 (define check-conflict-and-embed-cff
249 (let ((font-list '()))
250 (lambda (name file-name font-index)
251 (let* ((name-symbol (string->symbol name))
252 (args-filename-offset
253 (cons file-name (ly:get-cff-offset file-name font-index)))
254 (found-filename-offset (assq name-symbol font-list)))
255 (if found-filename-offset
257 (if (equal? args-filename-offset (cdr found-filename-offset))
259 (_ "CFF font `~a' already embedded, skipping.")
262 (_ "Different CFF fonts which have the same name `~a' has been detected. The font cannot be embedded.")
267 (_ "Embedding CFF font `~a'")
270 (acons name-symbol args-filename-offset font-list))
271 (ps-embed-cff (ly:otf->cff file-name font-index) name 0)))))))
273 (define (write-preamble paper load-fonts? port)
274 (define (internal-font? font-name-filename)
275 (let* ((font (car font-name-filename))
276 (file-name (caddr font-name-filename))
277 (font-file-name (ly:find-file (format #f "~a.otf" file-name))))
281 (string-contains font-file-name
282 (ly:get-option 'datadir)))))
284 (define (load-font-via-GS font-name-filename)
285 (define (is-collection-font? file-name)
286 (let ((port (open-file file-name "rb")))
287 (if (eq? (read-char port) #\t)
288 (if (eq? (read-char port) #\t)
289 (if (eq? (read-char port) #\c)
290 (if (eq? (read-char port) #\f)
297 (define (ps-load-file file-name)
298 (if (string? file-name)
299 (if (string-contains file-name (ly:get-option 'datadir))
301 (set! file-name (ly:string-substitute (ly:get-option 'datadir)
304 "lilypond-datadir (~a) concatstrings (r) file .loadfont\n"
306 (format #f "(~a) (r) file .loadfont\n" file-name))
307 (format #f "% cannot find font file: ~a\n" file-name)))
309 (let* ((font (car font-name-filename))
310 (name (cadr font-name-filename))
311 (file-name (caddr font-name-filename))
312 (font-index (cadddr font-name-filename))
313 (bare-file-name (ly:find-file file-name)))
315 ((and (number? font-index)
317 (ly:warning (_ "Font ~a cannot be loaded via Ghostscript because its font-index (~a) is not zero.")
319 (load-font font-name-filename))
320 ((and (string? bare-file-name)
321 (eq? (ly:get-font-format bare-file-name font-index) 'CFF)
322 (is-collection-font? bare-file-name))
323 (ly:warning (_ "Font ~a cannot be loaded via Ghostscript because it is an OpenType/CFF (OTC) font.")
325 (load-font font-name-filename))
326 ((and (string? bare-file-name)
327 (eq? (ly:get-font-format bare-file-name font-index) 'TrueType)
328 (not (ly:has-glyph-names? bare-file-name font-index)))
329 (ly:warning (_ "Font ~a cannot be used via Ghostscript because it is a TrueType font that does not have glyph names.")
331 (load-font font-name-filename))
334 (if (mac-font? bare-file-name)
335 (handle-mac-font name bare-file-name)
337 ((and font (cff-font? font))
338 (ps-load-file (ly:find-file
339 (format #f "~a.otf" file-name))))
340 ((string? bare-file-name)
341 (ps-load-file file-name))
343 (ly:warning (_ "cannot embed ~S=~S") name file-name)
346 (define (dir-join a b)
349 (string-append a "/" b)))
351 (define (dir-listing dir-name)
352 (define (dir-helper dir lst)
353 (let ((e (readdir dir)))
356 (dir-helper dir (cons e lst)))))
357 (reverse (dir-helper (opendir dir-name) '())))
359 (define (handle-mac-font name file-name)
360 (let* ((dir-name (tmpnam))
365 (mkdir dir-name #o700)
367 (set! status (ly:system (list "fondu" "-force" file-name)))
369 (set! files (dir-listing dir-name))
372 (let* ((full-name (dir-join dir-name f)))
374 (equal? 'regular (stat:type (stat full-name)))
375 (equal? name (ly:ttf-ps-name full-name)))
376 (set! embed (font-file-as-ps-string name full-name 0)))
377 (if (or (equal? "." f)
380 (delete-file full-name))))
385 (set! embed "% failed\n")
386 (ly:warning (_ "cannot extract file matching ~a from ~a")
390 (define (font-file-as-ps-string name file-name font-index)
391 (let ((font-format (ly:get-font-format file-name font-index)))
393 ((eq? font-format (string->symbol "Type 1"))
394 ;; Type 1 (PFA and PFB) fonts
395 (ly:type1->pfa file-name))
396 ((eq? font-format 'TrueType)
397 ;; TrueType fonts (TTF) and TrueType Collection (TTC)
398 (ly:ttf->pfa file-name font-index))
399 ((eq? font-format 'CFF)
400 ;; OpenType/CFF fonts (OTF) and OpenType/CFF Collection (OTC)
401 (check-conflict-and-embed-cff name file-name font-index))
403 (ly:warning (_ "do not know how to embed ~S=~S") name file-name)
406 (define (mac-font? bare-file-name)
407 (and (eq? PLATFORM 'darwin)
409 (or (string-endswith bare-file-name ".dfont")
410 (= (stat:size (stat bare-file-name)) 0))))
412 (define (load-font font-psname-filename-fontindex)
413 (let* ((font (list-ref font-psname-filename-fontindex 0))
414 (name (list-ref font-psname-filename-fontindex 1))
415 (file-name (list-ref font-psname-filename-fontindex 2))
416 (font-index (list-ref font-psname-filename-fontindex 3))
417 (bare-file-name (ly:find-file file-name)))
419 (cond ((mac-font? bare-file-name)
420 (handle-mac-font name bare-file-name))
421 ((and font (cff-font? font))
422 (ps-embed-cff (ly:otf-font-table-data font "CFF ")
425 (bare-file-name (font-file-as-ps-string
426 name bare-file-name font-index))
428 (ly:warning (_ "do not know how to embed font ~s ~s ~s")
429 name file-name font))))))
431 (define (load-fonts paper)
432 (let* ((fonts (ly:paper-fonts paper))
434 ;; todo - doc format of list.
438 (cond ((string? (ly:font-file-name font))
441 (ly:font-file-name font)
443 ((ly:pango-font? font)
444 (map (lambda (psname-filename-fontindex)
446 (list-ref psname-filename-fontindex 0)
447 (list-ref psname-filename-fontindex 1)
448 (list-ref psname-filename-fontindex 2)))
449 (ly:pango-font-physical-fonts font)))
451 (ly:font-sub-fonts font))))
453 (font-names (uniq-list
454 (sort (concatenate all-font-names)
455 (lambda (x y) (string<? (cadr x) (cadr y))))))
457 ;; slightly spaghetti-ish: deciding what to load where
461 (cond ((ly:get-option 'gs-load-fonts)
462 (load-font-via-GS name))
463 ((ly:get-option 'gs-load-lily-fonts)
464 (if (or (string-contains (caddr name)
465 (ly:get-option 'datadir))
466 (internal-font? name))
467 (load-font-via-GS name)
471 (pfas (map font-loader font-names)))
475 (display "%%BeginProlog\n" port)
478 "/lilypond-datadir where {pop} {userdict /lilypond-datadir (~a) put } ifelse"
479 (ly:get-option 'datadir))
481 (for-each (lambda (f)
482 (format port "\n%%BeginFont: ~a\n" (car f))
483 (display (cdr f) port)
484 (display "%%EndFont\n" port))
487 (display (procset "encodingdefs.ps") port))
488 (display (setup-variables paper) port)
490 ;; adobe note 5002: should initialize variables before loading routines.
491 (display (procset "music-drawing-routines.ps") port)
492 (display (procset "lilyponddefs.ps") port)
493 (display "%%EndProlog\n" port)
494 (display "%%BeginSetup\ninit-lilypond-parameters\n%%EndSetup\n\n" port))
496 (define (ps-quote str)
498 (lambda (replacement-list result)
502 (car replacement-list))
503 (cadr replacement-list)))
505 '((#\\ "\\\\") (#\( "\\(") (#\) "\\)"))))
507 ;;; Create DOCINFO pdfmark containing metadata
508 ;;; header fields with pdf prefix override those without the prefix
509 (define (handle-metadata header port)
510 (define (metadata-encode val)
511 ;; First, call ly:encode-string-for-pdf to encode the string (latin1 or
512 ;; utf-16be), then escape all parentheses and backslashes
513 ;; FIXME guile-2.0: use (string->utf16 str 'big) instead
515 (ps-quote (ly:encode-string-for-pdf val)))
516 (define (metadata-lookup-output overridevar fallbackvar field)
517 (let* ((overrideval (ly:modules-lookup (list header) overridevar))
518 (fallbackval (ly:modules-lookup (list header) fallbackvar))
519 (val (if overrideval overrideval fallbackval)))
521 (format port "/~a (~a)\n" field (metadata-encode (markup->string val (list header)))))))
525 (display "mark " port)
526 (metadata-lookup-output 'pdfauthor 'author "Author")
527 (format port "/Creator (LilyPond ~a)\n" (lilypond-version))
528 (metadata-lookup-output 'pdftitle 'title "Title")
529 (metadata-lookup-output 'pdfsubject 'subject "Subject")
530 (metadata-lookup-output 'pdfkeywords 'keywords "Keywords")
531 (metadata-lookup-output 'pdfmodDate 'modDate "ModDate")
532 (metadata-lookup-output 'pdfsubtitle 'subtitle "Subtitle")
533 (metadata-lookup-output 'pdfcomposer 'composer "Composer")
534 (metadata-lookup-output 'pdfarranger 'arranger "Arranger")
535 (metadata-lookup-output 'pdfpoet 'poet "Poet")
536 (metadata-lookup-output 'pdfcopyright 'copyright "Copyright")
537 (display "/DOCINFO pdfmark\n\n" port)))
539 (if (ly:get-option 'embed-source-code)
540 (let ((source-list (delete-duplicates
541 (remove (lambda (str)
544 (ly:get-option 'datadir))
546 "<included string>")))
547 (ly:source-files)))))
548 (display "\n/pdfmark where
549 {pop} {userdict /pdfmark /cleartomark load put} ifelse" port)
550 (for-each (lambda (fname idx)
552 mark /_objdef {ly~a_stream} /type /stream /OBJ pdfmark
553 mark {ly~a_stream} << /Type /EmbeddedFile>> /PUT pdfmark
554 mark {ly~a_stream} (~a) /PUT pdfmark
555 mark /Name (LilyPond source file ~a)
556 /FS << /Type /Filespec /F (~a) /EF << /F {ly~a_stream} >> >> /EMBED pdfmark
557 mark {ly~a_stream} /CLOSE pdfmark
560 (ps-quote (ly:gulp-file fname))
562 source-list (iota (length source-list))))))
564 (define-public (output-framework basename book scopes fields)
565 (let* ((port-tmp (make-tmpfile))
566 (tmp-name (port-filename port-tmp))
567 (outputter (ly:make-paper-outputter
570 (paper (ly:paper-book-paper book))
571 (header (ly:paper-book-header book))
572 (systems (ly:paper-book-systems book))
573 (page-stencils (map page-stencil (ly:paper-book-pages book)))
574 (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t))
575 (page-number (1- (ly:output-def-lookup paper 'first-page-number)))
576 (page-count (length page-stencils))
577 (port (ly:outputter-port outputter)))
578 (if (ly:get-option 'clip-systems)
579 (clip-system-EPSes basename book))
580 (if (ly:get-option 'dump-signatures)
581 (write-system-signatures basename (ly:paper-book-systems book) 1))
582 (output-scopes scopes fields basename)
583 (display (file-header paper page-count #t) port)
584 ;; don't do BeginDefaults PageMedia: A4
585 ;; not necessary and wrong
586 (write-preamble paper #t port)
587 (handle-metadata header port)
590 (set! page-number (1+ page-number))
591 (dump-page outputter page page-number page-count landscape?))
593 (display "%%Trailer\n%%EOF\n" port)
594 (ly:outputter-close outputter)
595 (postprocess-output book framework-ps-module (ly:output-formats)
596 basename tmp-name #f)))
598 (define-public (dump-stencil-as-EPS paper dump-me filename
600 (let* ((xext (ly:stencil-extent dump-me X))
601 (yext (ly:stencil-extent dump-me Y))
602 (padding (ly:get-option 'eps-box-padding))
603 (left-overshoot (if (number? padding)
604 (* -1 padding (ly:output-def-lookup paper 'mm))
609 (if (or (nan? x) (inf? x)
611 (equal? (format #f "~S" x) "+#.#")
612 (equal? (format #f "~S" x) "-#.#"))
615 ;; the left-overshoot is to make sure that
616 ;; bar numbers stick out of margin uniformly.
619 (if (number? left-overshoot)
620 (min left-overshoot (car xext))
622 (car yext) (cdr xext) (cdr yext)))))
623 (dump-stencil-as-EPS-with-bbox paper dump-me filename load-fonts bbox)))
625 (define-public (dump-stencil-as-EPS-with-bbox paper dump-me filename
628 "Create an EPS file from stencil @var{dump-me} to @var{filename}.
629 @var{bbox} has format @code{(left-x, lower-y, right-x, upper-y)}. If
630 @var{load-fonts} set, include fonts inline."
631 (define (to-rounded-bp-box box)
632 "Convert box to 1/72 inch with rounding to enlarge the box."
633 (let* ((scale (ly:output-def-lookup paper 'output-scale))
634 (strip-non-number (lambda (x)
639 (directed-round (lambda (x rounder)
641 (rounder (/ (* (strip-non-number x) scale)
643 (list (directed-round (car box) floor)
644 (directed-round (cadr box) floor)
645 (directed-round (max (1+ (car box)) (caddr box)) ceiling)
646 (directed-round (max (1+ (cadr box)) (cadddr box)) ceiling))))
648 (let* ((outputter (ly:make-paper-outputter
649 ;; FIXME: better wrap open/open-file,
650 ;; content-mangling is always bad.
651 ;; MINGW hack: need to have "b"inary for embedding CFFs
652 (open-file (format #f "~a.eps" filename) "wb")
654 (port (ly:outputter-port outputter))
655 (rounded-bbox (to-rounded-bp-box bbox))
656 (port (ly:outputter-port outputter))
657 (header (eps-header paper rounded-bbox load-fonts)))
658 (display header port)
659 (write-preamble paper load-fonts port)
660 (display "/mark_page_link { pop pop pop pop pop } bind def\n" port)
661 (display "gsave set-ps-scale-to-lily-scale\n" port)
662 (display "/helpEmmentaler-Brace where {pop helpEmmentaler-Brace} if\n" port)
663 (display "/helpEmmentaler-11 where {pop helpEmmentaler-11} if\n" port)
664 (display "/helpEmmentaler-13 where {pop helpEmmentaler-13} if\n" port)
665 (display "/helpEmmentaler-14 where {pop helpEmmentaler-14} if\n" port)
666 (display "/helpEmmentaler-16 where {pop helpEmmentaler-16} if\n" port)
667 (display "/helpEmmentaler-18 where {pop helpEmmentaler-18} if\n" port)
668 (display "/helpEmmentaler-20 where {pop helpEmmentaler-20} if\n" port)
669 (display "/helpEmmentaler-23 where {pop helpEmmentaler-23} if\n" port)
670 (display "/helpEmmentaler-26 where {pop helpEmmentaler-26} if\n" port)
671 (ly:outputter-dump-stencil outputter dump-me)
672 (display "stroke grestore\n%%Trailer\n%%EOF\n" port)
673 (ly:outputter-close outputter)))
675 (define (clip-systems-to-region basename paper systems region do-pdf do-png)
676 (let* ((extents-system-pairs
677 (filtered-map (lambda (paper-system)
678 (let* ((x-ext (system-clipped-x-extent
679 (paper-system-system-grob paper-system)
682 (cons x-ext paper-system)
687 (lambda (ext-system-pair)
688 (let* ((xext (car ext-system-pair))
689 (paper-system (cdr ext-system-pair))
690 (yext (paper-system-extent paper-system Y))
691 (bbox (list (car xext) (car yext)
692 (cdr xext) (cdr yext)))
693 (filename (if (< 0 count)
694 (format #f "~a-~a" basename count)
696 (set! count (1+ count))
697 (dump-stencil-as-EPS-with-bbox paper
698 (paper-system-stencil paper-system)
700 (ly:get-option 'include-eps-fonts)
703 (postscript->pdf 0 0 filename (format #f "~a.eps" filename) #t))
705 (postscript->png (ly:get-option 'resolution) 0 0
706 filename (format #f "~a.eps" filename) #t))))
707 extents-system-pairs)))
709 (define-public (clip-system-EPSes basename paper-book)
711 (member "pdf" (ly:output-formats)))
713 (member "png" (ly:output-formats)))
715 (define (clip-score-systems basename systems)
716 (let* ((layout (ly:grob-layout (paper-system-system-grob (car systems))))
717 (regions (ly:output-def-lookup layout 'clip-regions)))
720 (clip-systems-to-region
721 (format #f "~a-from-~a-to-~a-clip"
723 (rhythmic-location->file-string (car region))
724 (rhythmic-location->file-string (cdr region)))
725 layout systems region
729 ;; partition in system lists sharing their layout blocks
730 (let* ((systems (ly:paper-book-systems paper-book))
732 (score-system-list '()))
734 (lambda (system last-system)
735 (if (not (and last-system
736 (equal? (paper-system-layout last-system)
737 (paper-system-layout system))))
738 (set! score-system-list (cons '() score-system-list)))
739 (if (paper-system-layout system)
740 (set-car! score-system-list (cons system (car score-system-list))))
745 (for-each (lambda (system-list)
746 ;; filter out headers and top-level markup
747 (if (pair? system-list)
750 (format #f "~a-~a" basename count)
755 (define-public (output-preview-framework basename book scopes fields)
756 (let* ((paper (ly:paper-book-paper book))
757 (systems (relevant-book-systems book))
758 (to-dump-systems (relevant-dump-systems systems)))
759 (dump-stencil-as-EPS paper
760 (stack-stencils Y DOWN 0.0
761 (map paper-system-stencil
762 (reverse to-dump-systems)))
763 (format #f "~a.preview" basename)
765 (postprocess-output book framework-ps-module
766 (cons "png" (ly:output-formats))
767 (format #f "~a.preview" basename)
768 (format #f "~a.preview.eps" basename)
772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
774 (define (output-width-height defs)
775 (let* ((landscape (ly:output-def-lookup defs 'landscape))
776 (output-scale (ly:output-def-lookup defs 'output-scale))
778 (* x output-scale (/ (ly:bp 1)))))
779 (paper-width (convert (ly:output-def-lookup defs 'paper-width)))
780 (paper-height (convert (ly:output-def-lookup defs 'paper-height)))
781 (w (if landscape paper-height paper-width))
782 (h (if landscape paper-width paper-height)))
785 (define (output-resolution defs)
786 (let ((defs-resolution (ly:output-def-lookup defs 'pngresolution)))
787 (if (number? defs-resolution)
789 (ly:get-option 'resolution))))
791 (define-public (convert-to-pdf book base-name tmp-name is-eps)
792 (let* ((defs (ly:paper-book-paper book))
793 (width-height (output-width-height defs))
794 (width (car width-height))
795 (height (cdr width-height)))
796 (postscript->pdf width height base-name tmp-name is-eps)))
798 (define-public (convert-to-png book base-name tmp-name is-eps)
799 (let* ((defs (ly:paper-book-paper book))
800 (resolution (output-resolution defs))
801 (width-height (output-width-height defs))
802 (width (car width-height))
803 (height (cdr width-height)))
804 (postscript->png resolution width height base-name tmp-name is-eps)))
806 (define-public (convert-to-ps book base-name tmp-name is-eps)
807 (postscript->ps base-name tmp-name is-eps))
809 (define-public (output-classic-framework basename book scopes fields)
810 (ly:error (_ "\nThe PostScript backend does not support the
811 system-by-system output. For that, use the EPS backend instead,
813 lilypond -dbackend=eps FILE
815 If you have cut & pasted a lilypond fragment from a webpage, be sure
816 to only remove anything before
818 %% ****************************************************************
819 %% Start cut-&-pastable-section
820 %% ****************************************************************