]> git.donarmstrong.com Git - lilypond.git/commitdiff
Svg with woff fonts: use versioned font src urls. Allows font changes/updates.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 1 Jun 2010 14:27:51 +0000 (16:27 +0200)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 24 Jun 2010 14:04:55 +0000 (16:04 +0200)
Use versioned font src urls like fonts/<lilypond-version>/<fontname>.woff
and put copy of font files there for easier distribution.

GNUmakefile.in
scm/framework-svg.scm

index 7d5bba4d3aa6364243e74dcf3837277c7f0a226a..04ce4e6e726215fce75d53f56416475fb34ced8e 100644 (file)
@@ -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 && \
index fb2125c428aa4511435c56d7042789c128f9e401..c6c342bf1c95a29393cf839c4c0cf6bab1dcfadc 100644 (file)
 (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)
                                        ""))