X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Fframework-svg.scm;h=5dd9383ebfd2427682ce9db55070b4167cbe5b0a;hb=f27ae571e387e7081432fccbf988c9b8148cbfec;hp=ba918ce3b01ea50c30e71f5716be4b04e93b2ba2;hpb=f5387a5c986393052bc9443ebd9b6cd9f14c6887;p=lilypond.git diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm index ba918ce3b0..5dd9383ebf 100644 --- a/scm/framework-svg.scm +++ b/scm/framework-svg.scm @@ -58,6 +58,61 @@ (define (svg-end) (ec 'svg)) +(define (mkdirs dir-name mode) + (let loop ((dir-name (string-split dir-name #\/)) (root "")) + (if (pair? dir-name) + (let ((dir (string-append root (car dir-name)))) + (if (not (file-exists? dir)) + (mkdir dir mode)) + (loop (cdr dir-name) (string-append dir "/")))))) + +(define output-dir #f) + +(define (svg-define-font font font-name scaling) + (let* ((base-file-name (basename (if (list? font) (pango-pf-file-name font) + (ly:font-file-name font)) ".otf")) + (woff-file-name (string-regexp-substitute "([.]otf)?$" ".woff" + base-file-name)) + (woff-file (or (ly:find-file woff-file-name) "/no-such-file.woff")) + (url (string-append output-dir "/fonts/" (lilypond-version) "/" + (basename woff-file-name))) + (lower-name (string-downcase font-name))) + (if (file-exists? woff-file) + (begin + (if (not (file-exists? url)) + (begin + (ly:message (_ "Updating font into: ~a") url) + (mkdirs (string-append output-dir "/" (dirname url)) #o700) + (copy-file woff-file url) + (ly:progress "\n"))) + (ly:format + "@font-face { +font-family: '~a'; +font-weight: normal; +font-style: normal; +src: url('~a'); +} +" + font-name url)) + ""))) + +(define (woff-header paper dir) + "TODO: + * add (ly:version) to font name + * copy woff font with version alongside svg output +" + (set! output-dir dir) + (string-append + (eo 'defs) + (eo 'style '(text . "style/css")) + " +" + (ec 'style) + (ec 'defs))) + (define (dump-page paper filename page page-number page-count) (let* ((outputter (ly:make-paper-outputter (open-file filename "wb") 'svg)) (dump (lambda (str) (display str (ly:outputter-port outputter)))) @@ -69,8 +124,14 @@ (page-width (* output-scale device-width)) (page-height (* output-scale device-height))) + (if (ly:get-option 'svg-woff) + (module-define! (ly:outputter-module outputter) 'paper paper)) (dump (svg-begin page-width page-height 0 0 device-width device-height)) + (if (ly:get-option 'svg-woff) + (module-remove! (ly:outputter-module outputter) 'paper)) + (if (ly:get-option 'svg-woff) + (dump (woff-header paper (dirname filename)))) (dump (comment (format "Page: ~S/~S" page-number page-count))) (ly:outputter-output-scheme outputter `(begin (set! lily-unit-length ,unit-length) @@ -94,8 +155,14 @@ (svg-width (* output-scale device-width)) (svg-height (* output-scale device-height))) + (if (ly:get-option 'svg-woff) + (module-define! (ly:outputter-module outputter) 'paper paper)) (dump (svg-begin svg-width svg-height left-x (- top-y) device-width device-height)) + (if (ly:get-option 'svg-woff) + (module-remove! (ly:outputter-module outputter) 'paper)) + (if (ly:get-option 'svg-woff) + (dump (woff-header paper (dirname filename)))) (ly:outputter-output-scheme outputter `(begin (set! lily-unit-length ,unit-length) ""))