From: Jan Nieuwenhuizen Date: Tue, 1 Jun 2010 14:27:51 +0000 (+0200) Subject: Svg with woff fonts: use versioned font src urls. Allows font changes/updates. X-Git-Tag: release/2.13.26-1~10 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;ds=sidebyside;h=9e1355e4dd31e809b4c5e604e761ad3f91b12d51;p=lilypond.git Svg with woff fonts: use versioned font src urls. Allows font changes/updates. Use versioned font src urls like fonts//.woff and put copy of font files there for easier distribution. --- diff --git a/GNUmakefile.in b/GNUmakefile.in index 7d5bba4d3a..04ce4e6e72 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -214,6 +214,8 @@ $(tree-share-prefix)/mf-link-tree link-mf-tree: $(tree-share-prefix)/lilypond-fo ln -s ../../../../../mf/$(outconfbase)/fonts.conf . -cd $(tree-share-prefix)/fonts/svg && \ ln -s ../../../../../../mf/$(outconfbase)/*.svg . + -cd $(tree-share-prefix)/fonts/svg && \ + ln -s ../../../../../../mf/$(outconfbase)/*.woff . -cd $(tree-share-prefix)/fonts/tfm && \ ln -s ../../../../../../mf/$(outconfbase)/*.tfm . -cd $(tree-share-prefix)/fonts/type1 && \ diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm index fb2125c428..c6c342bf1c 100644 --- a/scm/framework-svg.scm +++ b/scm/framework-svg.scm @@ -58,31 +58,50 @@ (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* ((file-name (if (list? font) (pango-pf-file-name font) - (ly:font-file-name font))) + (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))) - ;; only embed emmentaler for now - (if (equal? (substring lower-name 0 (min (string-length lower-name) 10)) "emmentaler") - (string-append - "@font-face { -font-family: '" - 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('" - (string-downcase font-name) - ".woff'); +src: url('~a'); } -") +" + font-name url)) ""))) -(define (woff-header paper) +(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")) @@ -110,7 +129,7 @@ src: url('" (dump (svg-begin page-width page-height 0 0 device-width device-height)) (if (ly:get-option 'svg-woff) - (dump (woff-header paper))) + (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) @@ -139,7 +158,7 @@ src: url('" (dump (svg-begin svg-width svg-height left-x (- top-y) device-width device-height)) (if (ly:get-option svg-woff) - (dump (woff-header paper))) + (dump (woff-header paper (dirname filename)))) (ly:outputter-output-scheme outputter `(begin (set! lily-unit-length ,unit-length) ""))