]> git.donarmstrong.com Git - lilypond.git/commitdiff
Experimental support for woff fonts in svg.
authorJan Nieuwenhuizen <janneke@gnu.org>
Mon, 31 May 2010 15:13:55 +0000 (17:13 +0200)
committerJan Nieuwenhuizen <janneke@gnu.org>
Thu, 24 Jun 2010 14:04:54 +0000 (16:04 +0200)
WOFF files are a new w3c font standard esp. for embedding in
web pages and svg and allow being downloaded on the fly, see

   http://en.wikipedia.org/wiki/Web_Open_Font_Format
   http://www.w3.org/Submission/WOFF/

Use

    out/bin/lilypond -d backend=svg example-1.ly
    out/bin/lilypond -d backend=svg -d svg-woff --output=woff example-1.ly
    cp example-1.svg woff.svg mf/out/emmentaler-20.woff /var/www/woff

and use firefox 3.6 or later to browse http://localhost/woff
(chromium-browser 5.0.375 does not have it yet, but it should be there
 shortly, see http://code.google.com/p/chromium/issues/detail?id=25543 )

Or see the current results at

   http://lilypond.org/people/janneke/woff/

configure.in
mf/GNUmakefile
mf/emmentaler-brace.pe.in
scm/framework-svg.scm
scm/lily.scm
scm/output-svg.scm
scripts/build/gen-emmentaler-scripts.py

index 7396379f9b94ae2936cf5c02643309ab37620b07..39f30fc866a21abe73d4ecc0e9f3c552082a63f7 100644 (file)
@@ -137,7 +137,10 @@ STEPMAKE_PYTHON_DEVEL(REQUIRED)
 
 STEPMAKE_PATH_PROG(GHOSTSCRIPT, gs, OPTIONAL, 8.60)
 
-STEPMAKE_PATH_PROG(FONTFORGE, fontforge, REQUIRED, 20050624)
+STEPMAKE_PATH_PROG(FONTFORGE, fontforge, REQUIRED, 20090923)
+# For svg woff fonts to work, version 20100501 is required but
+# the build does not break; leave optional until distros ship it.
+STEPMAKE_PATH_PROG(FONTFORGE, fontforge, OPTIONAL, 20100501)
 
 STEPMAKE_PATH_PROG(T1ASM, t1asm, REQUIRED)
 
index 31b1f99e8c9fb7276579b0f8a1803322ca7ae249..ac27d1afc5e806283b5125b0b7cc2f04ded78938 100644 (file)
@@ -29,6 +29,7 @@ OTF_TABLES = $(STAFF_SIZES:%=$(outdir)/feta%.otf-table) \
             $(BRACES:%=$(outdir)/feta-braces-%.otf-table)
 FETA_FONTS = $(FETA_MF_FILES:.mf=)
 SVG_FILES = $(OTF_FILES:%.otf=%.svg)
+WOFF_FILES = $(OTF_FILES:%.otf=%.woff)
 
 FC_FIND = $(shell $(FCLIST) --verbose 'Century Schoolbook L:style=$(1)' \
                  | grep 'file:' \
@@ -59,8 +60,9 @@ $(outdir)/emmentaler-brace.otf-gtable: $(BRACES:%=$(outdir)/feta-braces-%.otf-gt
 # 2. are not included with teTeX
 #
 
-$(outdir)/emmentaler-%.otf \
-$(outdir)/emmentaler-%.svg: $(outdir)/emmentaler-%.pe \
+$(outdir)/emmentaler-%.otf\
+ $(outdir)/emmentaler-%.svg\
+ $(outdir)/emmentaler-%.woff: $(outdir)/emmentaler-%.pe \
                            $(outdir)/feta%.pfb \
                            $(outdir)/feta-noteheads%.pfb \
                            $(outdir)/feta-alphabet%.pfb \
@@ -69,8 +71,9 @@ $(outdir)/emmentaler-%.svg: $(outdir)/emmentaler-%.pe \
                            $(outdir)/feta%.otf-gtable
        cd $(outdir) && $(FONTFORGE) -script $(notdir $(basename ,$@).pe)
 
-$(outdir)/emmentaler-brace.otf \
-$(outdir)/emmentaler-brace.svg: $(outdir)/emmentaler-brace.pe \
+$(outdir)/emmentaler-brace.otf\
+ $(outdir)/emmentaler-brace.svg\
+ $(outdir)/emmentaler-brace.woff: $(outdir)/emmentaler-brace.pe \
                       $(foreach s,$(BRACES),$(outdir)/feta-braces-$(s).pfb) \
                       $(outdir)/emmentaler-brace.otf-table $(outdir)/emmentaler-brace.otf-gtable
        cd $(outdir) && $(FONTFORGE) -script emmentaler-brace.pe
@@ -123,8 +126,9 @@ $(outdir)/emmentaler-brace.otf: $(outdir)/emmentaler-brace.subfonts \
                                $(outdir)/emmentaler-brace.otf-gtable \
                                $(outdir)/emmentaler-brace.pe
 
-$(outdir)/emmentaler-brace.otf \
-$(outdir)/emmentaler-brace.svg: $(BRACES:%=$(outdir)/feta-braces-%.pfb)
+$(outdir)/emmentaler-brace.otf\
+ $(outdir)/emmentaler-brace.svg\
+ $(outdir)/emmentaler-brace.woff: $(BRACES:%=$(outdir)/feta-braces-%.pfb)
 
 $(outdir)/emmentaler-brace.fontname:
        echo -n 'emmentaler-brace' > $@
@@ -148,7 +152,8 @@ ALL_GEN_FILES = $(LOG_FILES) \
                $(OTF_TABLES) \
                $(NCSB_OTFS) \
                $(OTF_FILES) \
-               $(SVG_FILES)
+               $(SVG_FILES) \
+               $(WOFF_FILES)
 
 # PRE_INSTALL=$(MAKE) "$(ALL_GEN_FILES)"
 
@@ -162,7 +167,7 @@ INSTALLATION_OUT_FILES1 = $(OTF_FILES) \
                          $(NCSB_OTFS)
 
 INSTALLATION_OUT_DIR2 = $(local_lilypond_datadir)/fonts/svg
-INSTALLATION_OUT_FILES2 = $(SVG_FILES)
+INSTALLATION_OUT_FILES2 = $(SVG_FILES) $(WOFF_FILES)
 
 export MFINPUTS := .:$(MFINPUTS)
 
index dabbecb7e1ce12f520dfaa6d45f7e4bd364cb7b8..d5440be402fc78c365a11072c18ad8ffb9afa086 100644 (file)
@@ -82,3 +82,4 @@ LoadTableFromFile("LILY", "emmentaler-brace.otf-gtable")
 
 Generate("emmentaler-brace.otf");
 Generate("emmentaler-brace.svg");
+Generate("emmentaler-brace.woff");
index ba918ce3b01ea50c30e71f5716be4b04e93b2ba2..9bc11ae2a3f8f5a2a533756b0a876567365173ab 100644 (file)
 (define (svg-end)
   (ec 'svg))
 
+(define (woff-header)
+  "TODO:
+      * dynamically add fonts based on usage
+      * add (ly:version) to font name
+      * copy woff font with version alongside svg output
+"
+  (string-append
+   (eo 'defs)
+   (eo 'style '(text . "style/css"))
+   "      <![CDATA[
+        @font-face {
+          font-family: 'emmentaler-20';
+          font-weight: normal;
+          font-style: normal;
+          src: url('emmentaler-20.woff');
+        }
+      ]]>
+   "
+   (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))))
@@ -71,6 +92,8 @@
 
     (dump (svg-begin page-width page-height
                     0 0 device-width device-height))
+    (if (ly:get-option 'svg-woff)
+       (dump (woff-header)))
     (dump (comment (format "Page: ~S/~S" page-number page-count)))
     (ly:outputter-output-scheme outputter
                                `(begin (set! lily-unit-length ,unit-length)
 
     (dump (svg-begin svg-width svg-height
                     left-x (- top-y) device-width device-height))
+    (if (ly:get-option svg-woff)
+       (dump (woff-header)))
     (ly:outputter-output-scheme outputter
                                `(begin (set! lily-unit-length ,unit-length)
                                        ""))
index 7c10affaa355ba5efc88f8f241fb0880f29a111a..68ab46a6e7e7aaa491b75a39b68ae7ae00c2372e 100644 (file)
@@ -165,8 +165,11 @@ second.  Dump results to `FILE.stacks' and
 `FILE.graph'.")
     (trace-scheme-coverage #f
 "Record coverage of Scheme files in `FILE.cov'.")
-    (show-available-fonts #f
+    ; `'"
+(show-available-fonts #f
 "List available font names.")
+    (svg-woff #f
+"Use woff font files in SVG backend.")
     (verbose ,(ly:command-line-verbose?)
 "Value of the --verbose flag (read-only).")
     (warning-as-error #f
index 57c5e733a0b63cd9e8e6b0dd0459cd925280b26b..8bdcf2a61be0856a8103e8e7e16ea1d438c7daaf 100644 (file)
        (cache-font font-file scaled-size glyph)
        (ly:warning (_ "cannot find SVG font ~S") font-file))))
 
+(define embedded #f)
+
+(define (woff-font-smob-to-text font expr)
+  (let* ((name-style (font-name-style font))
+        (scaled-size (modified-font-metric-font-scaling font))
+        (font-file (ly:find-file (string-append name-style ".woff")))
+        (charcode (ly:font-glyph-name-to-charcode font expr))
+        (text (format #f "&#~S;" charcode)))
+  (define alist '())
+  (define (set-attribute attr val)
+    (set! alist (assoc-set! alist attr val)))
+  (set-attribute 'font-family name-style)
+  (set-attribute 'font-size scaled-size)
+  (apply entity 'text text (reverse! alist))))
+  
+(define font-smob-to-text
+  (if (not (ly:get-option 'svg-woff))
+      font-smob-to-path woff-font-smob-to-text))
 
 (define (fontify font expr)
   (if (string? font)
       (pango-description-to-text font expr)
-      (font-smob-to-path font expr)))
+      (font-smob-to-text font expr)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; stencil outputters
 (define (embedded-svg string)
   string)
 
-(define (glyph-string font size cid glyphs)
+(define (embedded-glyph-string font size cid glyphs)
   (define path "")
   (if (= 1 (length glyphs))
       (set! path (music-string-to-path font size (car glyphs)))
   (set! next-horiz-adv 0.0)
   path)
 
+(define (woff-glyph-string font size cid glyphs)
+  (named-glyph font glyphs))
+
+(define glyph-string
+  (if (not (ly:get-option 'svg-woff)) embedded-glyph-string woff-glyph-string))
+
 (define (grob-cause offset grob)
   "")
 
index d7ea193b59f56120bd9b77d729a61d4380a8ec9a..46fb8163dd7e74d0d5e9c785c1999e89da47b726 100644 (file)
@@ -75,6 +75,7 @@ LoadTableFromFile("LILY", "feta%(design_size)d.otf-gtable");
 
 Generate("%(filename)s-%(design_size)d.otf");
 Generate("%(filename)s-%(design_size)d.svg");
+Generate("%(filename)s-%(design_size)d.woff");
 ''' % vars()
 
     basename = '%s-%d' % (filename, design_size)