From 39a5c51c49d1d299c0bfa525a15f1c87ef4e8481 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sat, 18 Dec 2004 15:44:25 +0000 Subject: [PATCH] * scm/output-svg.scm: * scm/framework-svg.scm: Add pageSet. Update. * mf/GNUmakefile: * buildscripts/gen-bigcheese-scripts.py: Also generate SVG font. --- ChangeLog | 8 +++ GNUmakefile.in | 2 + buildscripts/gen-bigcheese-scripts.py | 4 +- mf/GNUmakefile | 6 ++- mf/aybabtu.pe.in | 1 + scm/framework-svg.scm | 73 +++++++++++---------------- scm/output-svg.scm | 47 ++++++++++------- 7 files changed, 77 insertions(+), 64 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8f75bcaa5..2d52dbfcaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-12-18 Jan Nieuwenhuizen + + * scm/output-svg.scm: + * scm/framework-svg.scm: Add pageSet. Update. + + * mf/GNUmakefile: + * buildscripts/gen-bigcheese-scripts.py: Also generate SVG font. + 2004-12-18 Han-Wen Nienhuys * tex/lilyponddefs.tex: comment out new ifpdf code. diff --git a/GNUmakefile.in b/GNUmakefile.in index 1f1dbcc82d..e3198a352f 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -112,6 +112,7 @@ $(builddir)/share/lilypond-force: ln -s $(abs-srcdir)/ly ly && \ ln -s ../../mf/$(outconfbase) dvips && \ ln -s ../../mf/$(outconfbase) otf && \ + ln -s ../../mf/$(outconfbase) svg && \ ln -s ../../mf/$(outconfbase) tfm && \ ln -s $(abs-srcdir)/mf && \ ln -s $(abs-srcdir)/ps && \ @@ -125,6 +126,7 @@ $(builddir)/share/lilypond-force: ln -s $(abs-srcdir)/mf source && \ ln -s ../../../mf/$(outconfbase) otf && \ ln -s ../../../mf/$(outconfbase) tfm && \ + ln -s ../../../mf/$(outconfbase) svg && \ ln -s ../../../mf/$(outconfbase) type1 cd $(builddir)/share/$(package)/elisp && \ ln -sf ../../../elisp/$(outconfbase)/lilypond-words.el . && \ diff --git a/buildscripts/gen-bigcheese-scripts.py b/buildscripts/gen-bigcheese-scripts.py index f5e47d42e4..d4091e82f1 100644 --- a/buildscripts/gen-bigcheese-scripts.py +++ b/buildscripts/gen-bigcheese-scripts.py @@ -65,7 +65,9 @@ LoadTableFromFile("LILC", "feta%(design_size)d.otf-table") LoadTableFromFile("LILY", "feta%(design_size)d.otf-gtable") Generate("%(name)s%(design_size)d.otf"); -Generate("%(name)s%(design_size)d.cff");''' % vars() +Generate("%(name)s%(design_size)d.cff"); +Generate("%(name)s%(design_size)d.svg"); +''' % vars() path = os.path.join (outdir, name + '%d' % design_size + '.pe') open (path, 'w').write (script) diff --git a/mf/GNUmakefile b/mf/GNUmakefile index 014d7b1d71..b01bb1cff0 100644 --- a/mf/GNUmakefile +++ b/mf/GNUmakefile @@ -24,6 +24,7 @@ PE_SCRIPTS = $(addsuffix .pe, $(addprefix $(outdir)/bigcheese, $(STAFF_SIZES))) OTF_TABLES = $(addsuffix .otf-table, $(addprefix $(outdir)/feta, $(STAFF_SIZES))) \ $(BRACES:%=$(outdir)/feta-braces-%.otf-table) FETA_FONTS = $(FETA_MF_FILES:.mf=) +SVG_FILES = $(OTF_FILES:%.otf=%.svg) $(outdir)/aybabtu.otf-table: $(BRACES:%=$(outdir)/feta-braces-%.otf-table) cat $^ > $@ @@ -54,7 +55,7 @@ foe: echo $(TEXMF) kpsewhich exbase.mf -$(outdir)/%.otf: $(outdir)/%.pe +$(outdir)/%.otf $(outdir)/%.svg: $(outdir)/%.pe (cd $(outdir) && fontforge -script $(notdir $<)) $(outdir)/%.otf-table: $(outdir)/%.lisp @@ -106,6 +107,9 @@ INSTALLATION_OUT_FILES6=$(outdir)/lilypond.map INSTALLATION_OUT_DIR7=$(local_lilypond_datadir)/ps/ INSTALLATION_OUT_FILES7=$(ENC_FILES) +INSTALLATION_OUT_DIR8=$(local_lilypond_datadir)/svg +INSTALLATION_OUT_FILES8=$(OTF_FILES) + export MFINPUTS:=.:$(MFINPUTS) diff --git a/mf/aybabtu.pe.in b/mf/aybabtu.pe.in index fbe376285c..983b31b3e9 100644 --- a/mf/aybabtu.pe.in +++ b/mf/aybabtu.pe.in @@ -42,3 +42,4 @@ LoadTableFromFile("LILY", "aybabtu.otf-gtable") Generate("aybabtu.otf"); Generate("aybabtu.cff"); +Generate("aybabtu.svg"); diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm index 7415536ec6..83af347a70 100644 --- a/scm/framework-svg.scm +++ b/scm/framework-svg.scm @@ -6,7 +6,7 @@ (define-module (scm framework-svg)) -(use-modules (guile) (lily)) +(use-modules (guile) (lily) (scm output-svg)) (use-modules (srfi srfi-2) (ice-9 regex)) ;; FIXME: 0.62 to get paper size right @@ -21,55 +21,42 @@ (hsize (ly:output-def-lookup paper 'hsize)) (vsize (ly:output-def-lookup paper 'vsize)) (page-width (inexact->exact (ceiling (* output-scale hsize)))) - (page-height (inexact->exact (ceiling (* output-scale vsize))))) - - (ly:outputter-dump-string outputter xml-header) - (ly:outputter-dump-string - outputter - (comment "Created with GNU LilyPond (http://lilypond.org)")) - (ly:outputter-dump-string - outputter (format #f "\n" - page-width page-height)) - (ly:outputter-dump-string - outputter "\n") - -; (for-each -; (lambda (x) -; (ly:outputter-dump-string outputter x)) -; (cons -; (page-header paper page-count) -; (preamble paper))) - + (page-height (inexact->exact (ceiling (* output-scale vsize)))) + (page-set? (> page-count 1))) + + (ly:outputter-dump-string + outputter + (string-append + (eo 'svg + '(xmlns . "http://www.w3.org/2000/svg") + '(version . "1.2") + `(width . ,(format #f "~smm" page-width)) + `(height . ,(format #f "~smm" page-height))) + ;; FIXME: only use pages if there are more than one, pageSet is + ;; not supported by all SVG applications yet. + (if page-set? (eo 'pageSet) "") + (eo 'g))) + (for-each (lambda (page) (set! page-number (1+ page-number)) - (dump-page outputter page page-number page-count landscape?)) + (dump-page outputter page page-number page-count landscape? page-set?)) pages) - (ly:outputter-dump-string outputter "\n\n\n"))) - -(define (comment s) - (string-append "\n")) - -;; FIXME: gulp from file -(define xml-header - " - -") - -(define (dump-page outputter page page-number page-count landscape?) + + (if page-set? (eo 'pageSet) "") (ly:outputter-dump-string outputter (string-append - (comment (format #f "Page: ~S/~S" page-number page-count)) - ;;(format #f "\n" (* output-scale y)))) - "\n")) + (ec 'g) + (if page-set? (ec 'pageSet) "") + (ec 'svg))))) +(define (dump-page outputter page page-number page-count landscape? page-set?) ;; FIXME:landscape - (ly:outputter-dump-stencil outputter page) - (ly:outputter-dump-string - outputter - (string-append - (comment (format #f "End Page ~S/~S" page-number page-count)) - "\n"))) + outputter (comment (format #f "Page: ~S/~S" page-number page-count))) + (if page-set? (ly:outputter-dump-string outputter (eo 'page))) + (ly:outputter-dump-string outputter (string-append (eo 'g))) + (ly:outputter-dump-stencil outputter page) + (ly:outputter-dump-string outputter (string-append (ec 'g))) + (if page-set? (ly:outputter-dump-string outputter (ec 'page)))) diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 068b69d28a..b19006a342 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -41,16 +41,25 @@ "")))))) ;; Helper functions -(define (tagify tag string . attribute-alist) - (string-append - "<" - tag - (apply string-append - (map (lambda (x) - (string-append " " (symbol->string (car x)) "='" (cdr x) "'")) - attribute-alist)) - ">" - string "\n")) +(define-public (attributes attributes-alist) + (apply string-append + (map (lambda (x) (format #f " ~s=\"~a\"" (car x) (cdr x))) + attributes-alist))) + +(define-public (eo entity . attributes-alist) + (format #f "<~S~a>\n" entity (attributes attributes-alist))) + +(define-public (eoc entity . attributes-alist) + (format #f "<~S~a/>\n" entity (attributes attributes-alist))) + +(define-public (ec entity) + (format #f "\n" entity)) + +(define-public (entity entity string . attributes-alist) + (if (equal? string "") + (apply eoc entity attributes-alist) + (string-append + (apply eo (cons entity attributes-alist)) string (ec entity)))) (define (control->list c) (list (car c) (cdr c))) @@ -114,7 +123,7 @@ (font-size font) anchor))) (define (fontify font expr) - (tagify "text" expr (cons 'style (svg-font font)))) + (entity 'text expr (cons 'style (svg-font font)))) ;; FIXME (define-public (otf-name-mangling font family) @@ -149,7 +158,7 @@ (let* ((x width) (y (* slope width)) (z (sqrt (+ (sqr x) (sqr y))))) - (tagify "rect" "" + (entity 'rect "" `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" blot)) `(x . "0") `(y . ,(number->string (* output-scale (- 0 (/ thick 2))))) @@ -166,7 +175,7 @@ (let* ((first (list-tail lst 4)) (first-c0 (car (list-tail first 3))) (second (list-head lst 4))) - (tagify "path" "" + (entity 'path "" `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" thick)) `(transform . ,(format #f "scale (~f, ~f)" output-scale output-scale)) @@ -175,9 +184,9 @@ (define (char font i) (dispatch - `(fontify ,font ,(tagify "tspan" (char->entity (integer->char i)))))) + `(fontify ,font ,(entity 'tspan (char->entity (integer->char i)))))) -(define (comment s) +(define-public (comment s) (string-append "\n")) (define (filledbox breapth width depth height) @@ -185,12 +194,12 @@ (define (named-glyph font name) (dispatch - `(fontify ,font ,(tagify "tspan" + `(fontify ,font ,(entity 'tspan (integer->entity (ly:font-glyph-name-to-charcode font name)))))) (define (placebox x y expr) - (tagify "g" + (entity 'g ;; FIXME -- JCN ;;(dispatch expr) expr @@ -199,7 +208,7 @@ (- 0 (* output-scale y)))))) (define (round-filled-box breapth width depth height blot-diameter) - (tagify "rect" "" + (entity 'rect "" `(style . ,(format "stroke-linejoin:round;stroke-linecap:round;stroke-width:~f;" blot-diameter)) `(x . ,(number->string (* output-scale (- 0 breapth)))) `(y . ,(number->string (* output-scale (- 0 height)))) @@ -208,7 +217,7 @@ `(ry . ,(number->string (/ blot-diameter 2))))) (define (text font string) - (dispatch `(fontify ,font ,(tagify "tspan" (string->entities string))))) + (dispatch `(fontify ,font ,(entity 'tspan (string->entities string))))) ;; WTF is this in every backend? (define (horizontal-line x1 x2 th) -- 2.39.5