X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fframework-ps.scm;h=28579ebc96f93c0175d793fa39d8dd2547741cfb;hb=c5a3f0c024f4cb629811cff9eb04abff36e94138;hp=e39b245233bdb9b82d9a393fc72b7cba5f876067;hpb=a9856fd0e12eaf82e7cbee99ac5c4739daff22c6;p=lilypond.git diff --git a/scm/framework-ps.scm b/scm/framework-ps.scm index e39b245233..28579ebc96 100644 --- a/scm/framework-ps.scm +++ b/scm/framework-ps.scm @@ -2,22 +2,25 @@ ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; -;;;; (c) 2004--2006 Han-Wen Nienhuys +;;;; (c) 2004--2006 Han-Wen Nienhuys (define-module (scm framework-ps)) ;;; this is still too big a mess. -(use-modules (ice-9 regex) - (ice-9 string-fun) - (ice-9 format) +(use-modules (ice-9 string-fun) (guile) (scm page) (scm paper-system) (srfi srfi-1) (srfi srfi-13) + (scm clip-region) (lily)) +(define (format dest . rest) + (if (string? dest) + (apply simple-format (cons #f (cons dest rest))) + (apply simple-format (cons dest rest)))) (define framework-ps-module (current-module)) @@ -30,7 +33,12 @@ (string-append "magfont" - (string-regexp-substitute "[ /%]" "_" name) + (ly:string-substitute + " " "_" + (ly:string-substitute + "/" "_" + (ly:string-substitute + "%" "_" name))) "m" (string-encode-integer (inexact->exact (round (* 1000 magnify))))))) (define (tex-font? fontname) @@ -44,10 +52,6 @@ (string-append "/" command " { /" fontname " " (ly:number->string scaling) " output-scale div selectfont } bind def\n")) - (define (standard-tex-font? x) - (or (equal? (substring x 0 2) "ms") - (equal? (substring x 0 2) "cm"))) - (define (font-load-command font) (let* ((specced-font-name (ly:font-name font)) (fontname (if specced-font-name @@ -62,10 +66,6 @@ (ops (ly:output-def-lookup paper 'output-scale)) (scaling (* ops magnification designsize))) - ;; Bluesky pfbs have UPCASE names (sigh.) - ;; FIXME - don't support Bluesky? - (if (standard-tex-font? fontname) - (set! fontname (string-upcase fontname))) (if (equal? fontname "unknown") (display (list font fontname))) (define-font plain fontname scaling))) @@ -164,13 +164,13 @@ (ly:output-def-lookup paper 'output-scale)) (ly:bp 1))) (landscape? (eq? (ly:output-def-lookup paper 'landscape) #t))) - (format "%%DocumentMedia: ~a ~$ ~$ ~a ~a ~a\n" - (ly:output-def-lookup paper 'papersizename) - (if landscape? h w) - (if landscape? w h) - 80 ;; weight - "()" ;; color - "()" ;; type + (ly:format "%%DocumentMedia: ~a ~2f ~2f ~a ~a ~a\n" + (ly:output-def-lookup paper 'papersizename) + (if landscape? h w) + (if landscape? w h) + 80 ;; weight + "()" ;; color + "()" ;; type ))) @@ -255,7 +255,7 @@ (format (if (string? name) "(~a) (r) file .loadfont\n" - "% can't find font file: ~a\n") + "% cannot find font file: ~a\n") name)) (let* ((font (car font-name-filename)) @@ -269,13 +269,16 @@ (if (mac-font? bare-file-name) (handle-mac-font name bare-file-name) (cond - ((string-match "^([eE]mmentaler|[Aa]ybabtu)" file-name) + ((or (string-startswith file-name "Emmentaler") + (string-startswith file-name "emmentaler") + (string-startswith file-name "aybabtu") + (string-startswith file-name "Aybabtu")) (ps-load-file (ly:find-file (format "~a.otf" file-name)))) ((string? bare-file-name) (ps-load-file file-name)) (else - (ly:warning (_ "can't embed ~S=~S") name file-name) + (ly:warning (_ "cannot embed ~S=~S") name file-name) ""))) ))) @@ -328,7 +331,7 @@ (if (not embed) (begin (set! embed "% failed \n") - (ly:warning (_ "can't extract file matching ~a from ~a") name filename))) + (ly:warning (_ "cannot extract file matching ~a from ~a") name filename))) embed)) (define (font-file-as-ps-string name file-name) @@ -336,16 +339,16 @@ ((downcase-file-name (string-downcase file-name))) (cond - ((and file-name (string-match "\\.pfa" downcase-file-name)) + ((and file-name (string-endswith downcase-file-name ".pfa")) (embed-document file-name)) - ((and file-name (string-match "\\.pfb" downcase-file-name)) + ((and file-name (string-endswith downcase-file-name ".pfb")) (ly:pfb->pfa file-name)) - ((and file-name (string-match "\\.ttf" downcase-file-name)) + ((and file-name (string-endswith downcase-file-name ".ttf")) (ly:ttf->pfa file-name)) - ((and file-name (string-match "\\.otf" downcase-file-name)) + ((and file-name (string-endswith downcase-file-name ".otf")) (ps-embed-cff (ly:otf->cff file-name) name 0)) (else - (ly:warning (_ "don't know how to embed ~S=~S") name file-name) + (ly:warning (_ "do not know how to embed ~S=~S") name file-name) "")))) (define (mac-font? bare-file-name) @@ -353,7 +356,7 @@ (eq? PLATFORM 'darwin) bare-file-name (or - (string-match "\\.dfont" bare-file-name) + (string-endswith bare-file-name ".dfont") (= (stat:size (stat bare-file-name)) 0)))) (define (load-font font-name-filename) @@ -376,7 +379,7 @@ (bare-file-name (font-file-as-ps-string name bare-file-name)) (else - (ly:warning (_ "don't know how to embed font ~s ~s ~s") + (ly:warning (_ "do not know how to embed font ~s ~s ~s") name file-name font)))))) @@ -408,8 +411,7 @@ (sort (apply append all-font-names) (lambda (x y) (stringpdf 0 0 (format "~a.eps" filename))) + )) + + extents-system-pairs) + )) + + +(define-public (clip-system-EPSes basename paper-book) + (define do-pdf (member "pdf" (ly:output-formats))) + + (define (clip-score-systems basename systems) + (let* + ((layout (ly:grob-layout (paper-system-system-grob (car systems)))) + (regions (ly:output-def-lookup layout 'clip-regions))) + + (for-each + (lambda (region) + (clip-systems-to-region + (format "~a-from-~a-to-~a-clip" + basename + (rhythmic-location->file-string (car region)) + (rhythmic-location->file-string (cdr region))) + layout systems region + do-pdf)) + + regions))) + + + ;; partition in system lists sharing their layout blocks + (let* + ((systems (ly:paper-book-systems paper-book)) + (count 0) + (score-system-list '())) + + (fold + (lambda (system last-system) + + + (if (not (and last-system + (equal? (paper-system-layout last-system) + (paper-system-layout system)))) + (set! score-system-list (cons '() score-system-list))) + + (if (paper-system-layout system) + (set-car! score-system-list (cons system (car score-system-list)))) + + ;; pass value. + system) + + #f + systems) + + (for-each + (lambda (system-list) + (clip-score-systems + (if (> count 0) + (format "~a-~a" basename count) + basename) + system-list)) + + score-system-list))) + + (define-public (output-preview-framework basename book scopes fields) (let* ((paper (ly:paper-book-paper book)) (systems (ly:paper-book-systems book)) @@ -539,7 +667,7 @@ ;; skip booktitles. (if (and - (not (ly:get-option 'preview-include-book-title)) + (not (ly:get-option 'include-book-title-preview)) (pair? systems) (ly:prob-property (car systems) 'is-book-title #f)) @@ -586,19 +714,25 @@ (postprocess-output book framework-ps-module (format "~a.preview.eps" basename) (ly:output-formats))))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-public (convert-to-pdf book name) (let* ((defs (ly:paper-book-paper book)) - (paper-width (ly:output-def-lookup defs 'paper-width)) - (paper-height (ly:output-def-lookup defs 'paper-height)) - (output-scale (ly:output-def-lookup defs 'output-scale))) + (landscape (ly:output-def-lookup defs 'landscape)) + (output-scale (ly:output-def-lookup defs 'output-scale)) + (convert (lambda (x) (* x output-scale (/ (ly:bp 1))))) + + (paper-width (convert (ly:output-def-lookup defs 'paper-width))) + (paper-height (convert (ly:output-def-lookup defs 'paper-height))) + + (w (if landscape paper-height paper-width)) + (h (if landscape paper-width paper-height)) + ) (if (equal? (basename name ".ps") "-") - (ly:warning (_ "can't convert to ~S" "PDF")) - (postscript->pdf (* paper-width output-scale (/ (ly:bp 1))) - (* paper-height output-scale (/ (ly:bp 1))) - name)))) + (ly:warning (_ "cannot convert to ~S" "PDF")) + (postscript->pdf w h name)))) (define-public (convert-to-png book name) (let* ((defs (ly:paper-book-paper book)) @@ -616,20 +750,26 @@ name))) (define-public (convert-to-dvi book name) - (ly:warning (_ "can't generate ~S using the postscript back-end") "DVI")) + (ly:warning (_ "cannot generate ~S using the postscript back-end") "DVI")) (define-public (convert-to-tex book name) - (ly:warning (_ "can't generate ~S using the postscript back-end") "TeX")) + (ly:warning (_ "cannot generate ~S using the postscript back-end") "TeX")) (define-public (convert-to-ps book name) #t) (define-public (output-classic-framework basename book scopes fields) - (ly:error (_ "\nThe PostScript backend does not support the 'classic' -framework. Use the EPS backend instead, + (ly:error (_ "\nThe PostScript backend does not support the system-by-system +output. For that, use the EPS backend instead, lilypond -b eps -or remove the lilypond-book specific settings from the input. +If have cut & pasted a lilypond fragment from a webpage, be sure +to only remove anything before + + %% **************************************************************** + %% Start cut-&-pastable-section + %% **************************************************************** + ")))