From: Jan Nieuwenhuizen Date: Mon, 31 May 2010 15:13:55 +0000 (+0200) Subject: Experimental support for woff fonts in svg. X-Git-Tag: release/2.13.26-1~13 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=378016b5fa0b07d5585bad89e0151fec16b7886a;p=lilypond.git Experimental support for woff fonts in svg. 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/ --- diff --git a/configure.in b/configure.in index 7396379f9b..39f30fc866 100644 --- a/configure.in +++ b/configure.in @@ -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) diff --git a/mf/GNUmakefile b/mf/GNUmakefile index 31b1f99e8c..ac27d1afc5 100644 --- a/mf/GNUmakefile +++ b/mf/GNUmakefile @@ -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) diff --git a/mf/emmentaler-brace.pe.in b/mf/emmentaler-brace.pe.in index dabbecb7e1..d5440be402 100644 --- a/mf/emmentaler-brace.pe.in +++ b/mf/emmentaler-brace.pe.in @@ -82,3 +82,4 @@ LoadTableFromFile("LILY", "emmentaler-brace.otf-gtable") Generate("emmentaler-brace.otf"); Generate("emmentaler-brace.svg"); +Generate("emmentaler-brace.woff"); diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm index ba918ce3b0..9bc11ae2a3 100644 --- a/scm/framework-svg.scm +++ b/scm/framework-svg.scm @@ -58,6 +58,27 @@ (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")) + " + " + (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) @@ -96,6 +119,8 @@ (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) "")) diff --git a/scm/lily.scm b/scm/lily.scm index 7c10affaa3..68ab46a6e7 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -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 diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 57c5e733a0..8bdcf2a61b 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -285,11 +285,29 @@ (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 @@ -352,7 +370,7 @@ (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))) @@ -368,6 +386,12 @@ (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) "") diff --git a/scripts/build/gen-emmentaler-scripts.py b/scripts/build/gen-emmentaler-scripts.py index d7ea193b59..46fb8163dd 100644 --- a/scripts/build/gen-emmentaler-scripts.py +++ b/scripts/build/gen-emmentaler-scripts.py @@ -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)