X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fbackend-library.scm;h=0734a1a83427339603fd641ff19488ccac5073b0;hb=76249556809f7a916e9f2bdbe38d7bfc89a2e99d;hp=90c0cd07edfa725620e215eb4ba89d20fad9323d;hpb=d473dbfc4a6f500b14ccdd78a33675b90151f775;p=lilypond.git diff --git a/scm/backend-library.scm b/scm/backend-library.scm index 90c0cd07ed..0734a1a834 100644 --- a/scm/backend-library.scm +++ b/scm/backend-library.scm @@ -1,6 +1,6 @@ ;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; Copyright (C) 2005--2010 Jan Nieuwenhuizen +;;;; Copyright (C) 2005--2012 Jan Nieuwenhuizen ;;;; Han-Wen Nienhuys ;;;; ;;;; LilyPond is free software: you can redistribute it and/or modify @@ -23,48 +23,17 @@ (scm paper-system) (ice-9 optargs)) -(define-public (ly:system command . rest) - (let* ((status 0) - (dev-null "/dev/null") - (silenced (if (or (ly:get-option 'verbose) - (not (access? dev-null W_OK))) - command - (format #f "~a > ~a 2>&1 " command dev-null)))) - (if (ly:get-option 'verbose) - (begin - (ly:message (_ "Invoking `~a'...") command)) - (ly:progress "\n")) - - (set! status - (if (pair? rest) - (system-with-env silenced (car rest)) - (system silenced))) - +(define-public (ly:system command) + (ly:debug (_ "Invoking `~a'...") (string-join command)) + (let ((status (apply ly:spawn command))) (if (> status 0) (begin - (ly:message (_ "`~a' failed (~a)") command status) - (ly:progress "\n") + (ly:warning (_ "`~a' failed (~a)\n") command status) ;; hmmm. what's the best failure option? (throw 'ly-file-failed))))) -(define-public (system-with-env cmd env) - - "Execute CMD in fork, with ENV (a list of strings) as the environment" - (let* - ;; laziness: should use execle? - - ((pid (primitive-fork))) - (if (= 0 pid) - ;; child - (begin - (environ env) - (system cmd)) - - ;; parent - (cdr (waitpid pid))))) - (define-public (sanitize-command-option str) - "Kill dubious shell quoting" + "Kill dubious shell quoting." (string-append "\"" @@ -91,46 +60,34 @@ (dir-basename name ".ps" ".eps") ".pdf")) (is-eps (string-match "\\.eps$" name)) - (paper-size-string (if is-eps - "-dEPSCrop" - (ly:format "-dDEVICEWIDTHPOINTS=~$\ - -dDEVICEHEIGHTPOINTS=~$" - paper-width paper-height))) - - (cmd (ly:format - "~a\ - ~a\ - ~a\ - ~a\ - -dCompatibilityLevel=1.4\ - -dNOPAUSE\ - -dBATCH\ - -r1200\ - -sDEVICE=pdfwrite\ - -sOutputFile=~S\ - -c .setpdfwrite\ - -f ~S\ -" - (search-gs) - (if (ly:get-option 'verbose) "" "-q") - (if (or (ly:get-option 'gs-load-fonts) - (ly:get-option 'gs-load-lily-fonts)) - "-dNOSAFER" - "-dSAFER") - paper-size-string - pdf-name - name))) - ;; The wrapper on windows cannot handle `=' signs, - ;; gs has a workaround with #. - (if (eq? PLATFORM 'windows) - (begin - (set! cmd (string-regexp-substitute "=" "#" cmd)) - (set! cmd (string-regexp-substitute "-dSAFER " "" cmd)) - (if (access? pdf-name W_OK) - (delete-file pdf-name)))) + (*unspecified* (if #f #f)) + (cmd + (remove (lambda (x) (eq? x *unspecified*)) + (list + (search-gs) + (if (ly:get-option 'verbose) *unspecified* "-q") + (if (or (ly:get-option 'gs-load-fonts) + (ly:get-option 'gs-load-lily-fonts) + (eq? PLATFORM 'windows)) + "-dNOSAFER" + "-dSAFER") + + (if is-eps + "-dEPSCrop" + (ly:format "-dDEVICEWIDTHPOINTS=~$" paper-width)) + (if is-eps + *unspecified* + (ly:format "-dDEVICEHEIGHTPOINTS=~$" paper-height)) + "-dCompatibilityLevel=1.4" + "-dNOPAUSE" + "-dBATCH" + "-r1200" + "-sDEVICE=pdfwrite" + (string-append "-sOutputFile=" pdf-name) + "-c.setpdfwrite" + (string-append "-f" name))))) - (ly:message (_ "Converting to `~a'...") pdf-name) - (ly:progress "\n") + (ly:message (_ "Converting to `~a'...\n") pdf-name) (ly:system cmd))) (define-public (postscript->png resolution paper-width paper-height name) @@ -155,7 +112,7 @@ (base (dir-basename filename ".ps" ".eps")) (intermediate (remove (lambda (x) (member x formats)) completed))) (for-each (lambda (f) - ((eval (string->symbol (format "convert-to-~a" f)) + ((eval (string->symbol (format #f "convert-to-~a" f)) module) paper-book filename)) completed) (if (ly:get-option 'delete-intermediate-files) (for-each (lambda (f) @@ -245,3 +202,69 @@ (lambda (x) (module-remove! output-module x)) missing-stencil-list)) + +(define (filter-out pred? lst) + (filter (lambda (x) (not (pred? x))) lst)) + +(define-public (font-name-split font-name) + "Return @code{(FONT-NAME . DESIGN-SIZE)} from @var{font-name} string +or @code{#f}." + (let ((match (regexp-exec (make-regexp "(.*)-([0-9]*)") font-name))) + (if (regexp-match? match) + (cons (match:substring match 1) (match:substring match 2)) + (cons font-name-designsize #f)))) + +;; Example of a pango-physical-font +;; ("Emmentaler-11" "/home/janneke/vc/lilypond/out/share/lilypond/current/fonts/otf/emmentaler-11.otf" 0) +(define-public (pango-pf-font-name pango-pf) + "Return the font-name of the pango physical font @var{pango-pf}." + (list-ref pango-pf 0)) +(define-public (pango-pf-file-name pango-pf) + "Return the file-name of the pango physical font @var{pango-pf}." + (list-ref pango-pf 1)) +(define-public (pango-pf-fontindex pango-pf) + "Return the fontindex of the pango physical font @var{pango-pf}." + (list-ref pango-pf 2)) + +(define (pango-font-name pango-font) + (let ((pf-fonts (ly:pango-font-physical-fonts pango-font))) + (if (pair? pf-fonts) + (pango-pf-font-name (car pf-fonts)) + ""))) + +(define-public (define-fonts paper define-font define-pango-pf) + "Return a string of all fonts used in @var{paper}, invoking the functions +@var{define-font} and @var{define-pango-pf} for producing the actual font +definition." + + (let* ((font-list (ly:paper-fonts paper)) + (pango-fonts (filter ly:pango-font? font-list)) + (other-fonts (filter-out ly:pango-font? font-list)) + (other-font-names (map ly:font-name other-fonts)) + (pango-only-fonts + (filter-out (lambda (x) + (member (pango-font-name x) other-font-names)) + pango-fonts))) + + (define (font-load-command font) + (let* ((font-name (ly:font-name font)) + (designsize (ly:font-design-size font)) + (magnification (* (ly:font-magnification font))) + (ops (ly:output-def-lookup paper 'output-scale)) + (scaling (* ops magnification designsize))) + (if (equal? font-name "unknown") + (display (list font font-name))) + (define-font font font-name scaling))) + + (define (pango-font-load-command pango-font) + (let* ((pf-fonts (ly:pango-font-physical-fonts pango-font)) + (pango-pf (if (pair? pf-fonts) (car pf-fonts) '("" "" 0))) + (font-name (pango-pf-font-name pango-pf)) + (scaling (ly:output-def-lookup paper 'output-scale))) + (if (equal? font-name "unknown") + (display (list pango-font font-name))) + (define-pango-pf pango-pf font-name scaling))) + + (string-append + (apply string-append (map font-load-command other-fonts)) + (apply string-append (map pango-font-load-command pango-only-fonts)))))