X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Foutput-svg.scm;h=56665a6a792601c3aa53487df7fc113267202825;hb=c64ea487b74396f5fd655b55a39c6a0371923b72;hp=c1d4ea4cbb09382f0a65705bf9beb13b922597ce;hpb=63aae20f4934f0b0c014b67946c1fe8e461e1331;p=lilypond.git diff --git a/scm/output-svg.scm b/scm/output-svg.scm index c1d4ea4cbb..56665a6a79 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -2,12 +2,17 @@ ;;;; ;;;; source file of the GNU LilyPond music typesetter ;;;; -;;;; (c) 2002--2004 Jan Nieuwenhuizen +;;;; (c) 2002--2005 Jan Nieuwenhuizen ;;;; http://www.w3.org/TR/SVG11 ;;;; http://www.w3.org/TR/SVG12/ -- page, pageSet in draft ;;;; TODO: +;;;; * .cff MUST NOT be in fc's fontpath. +;;;; - workaround: remove mf/out from ~/.fonts.conf, +;;;; instead add ~/.fonts and symlink all /mf/out/*otf there. +;;;; - bug in fontconfig/freetype/pango? + ;;;; * inkscape page/pageSet support ;;;; * inkscape SVG-font support ;;;; - use fontconfig/fc-cache for now, see output-gnome.scm @@ -22,13 +27,8 @@ (lily) (srfi srfi-13)) -;; GLobals -;; FIXME: 2? -(define output-scale (* 2 scale-to-unit)) -(define (debugf string . rest) - (if #f - (apply stderr (cons string rest)))) +(define lily-unit-length 1.75) (define (dispatch expr) (let ((keyword (car expr))) @@ -50,12 +50,15 @@ attributes-alist))) (define-public (eo entity . attributes-alist) + "o = open" (format #f "<~S~a>\n" entity (attributes attributes-alist))) (define-public (eoc entity . attributes-alist) + " oc = open/close" (format #f "<~S~a/>\n" entity (attributes attributes-alist))) (define-public (ec entity) + "c = close" (format #f "\n" entity)) (define-public (entity entity string . attributes-alist) @@ -65,7 +68,7 @@ (apply eo (cons entity attributes-alist)) string (ec entity)))) (define (offset->point o) - (format #f " ~S,~S" (car o) (cdr o))) + (format #f " ~S,~S" (car o) (- (cdr o)))) (define (svg-bezier lst close) (let* ((c0 (car (list-tail lst 3))) @@ -80,16 +83,6 @@ (define (sqr x) (* x x)) -(define (font-size font) - (let* ((designsize (ly:font-design-size font)) - (magnification (* (ly:font-magnification font))) - (ops 2) - (scaling (* ops magnification designsize))) - (debugf "scaling:~S\n" scaling) - (debugf "magnification:~S\n" magnification) - (debugf "design:~S\n" designsize) - scaling)) - (define (integer->entity integer) (format #f "&#x~x;" integer)) @@ -100,34 +93,60 @@ (apply string-append (map (lambda (x) (char->entity x)) (string->list string)))) +(define pango-description-regexp-comma + (make-regexp "^([^,]+), ?([-a-zA-Z_]*) ([0-9.]+)$")) + +(define pango-description-regexp-nocomma + (make-regexp "^([^ ]+) ([-a-zA-Z_]*) ?([0-9.]+)$")) + +(define (pango-description-to-svg-font str) + (let* + ((size 4.0) + (family "Helvetica") + (style #f) + (match-1 (regexp-exec pango-description-regexp-comma str)) + (match-2 (regexp-exec pango-description-regexp-nocomma str)) + (match (if match-1 + match-1 + match-2))) + + (if (regexp-match? match) + (begin + (set! family (match:substring match 1)) + (if (< 0 (string-length (match:substring match 2))) + (set! style (match:substring match 2))) + (set! size + (string->number (match:substring match 3)))) + + (display (format "Cannot decypher Pango description: ~a\n" str))) + + (set! style + (if (string? style) + (format "font-style:~a;" style) + "")) + + (format "font-family:~a;~afont-size:~a;text-anchor:west" + family + style + (/ size lily-unit-length)) + )) + +;;; FONT may be font smob, or pango font string (define (svg-font font) - (let* ((encoding (ly:font-encoding font)) - (anchor (if (memq encoding '(fetaMusic fetaBraces)) 'start 'start)) - (family (font-family font))) - (format #f "font-family:~a;font-style:~a;font-size:~a;text-anchor:~S;" - (otf-name-mangling font family) - (otf-style-mangling font family) - (font-size font) anchor))) + (if (string? font) + (pango-description-to-svg-font font) + (let ((name-style (font-name-style font)) + (size (modified-font-metric-font-scaling font)) + (anchor "west")) + + (format #f "font-family:~a;font-style:~a;font-size:~a;text-anchor:~a;" + (car name-style) (cadr name-style) + size anchor)))) (define (fontify font expr) - (entity 'text expr (cons 'style (svg-font font)))) - -;; FIXME -(define-public (otf-name-mangling font family) - ;; Hmm, family is bigcheese20/26? - (if (string=? (substring family 0 (min (string-length family) 9)) - "bigcheese") - "LilyPond" - (if (string=? family "aybabtu") - "LilyPondBraces" - family))) - -(define-public (otf-style-mangling font family) - ;; Hmm, family is bigcheese20/26? - (if (string=? (substring family 0 (min (string-length family) 9)) - "bigcheese") - (substring family 9) - "Regular")) + (entity 'text expr + `(style . ,(svg-font font)) + )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; stencil outputters @@ -135,11 +154,35 @@ ;;; catch-all for missing stuff ;;; comment this out to see find out what functions you miss :-) -(define (dummy . foo) "") -(map (lambda (x) (module-define! this-module x dummy)) - (append - (ly:all-stencil-expressions) - (ly:all-output-backend-commands))) + +(if #f + (begin + (define (dummy . foo) "") + (map (lambda (x) (module-define! this-module x dummy)) + (append + (ly:all-stencil-expressions) + (ly:all-output-backend-commands))) + )) + +(define (url-link url x y) + (string-append + (eo 'a `(xlink:href . ,url)) + (eoc 'rect + `(x . ,(car x)) + `(y . ,(car y)) + `(width . ,(- (cdr x) (car x))) + `(height . ,(- (cdr y) (car y))) + '(fill . "none") + '(stroke . "none") + '(stroke-width . "0.0")) + (ec 'a))) + +(define (grob-cause offset grob) + "") + +(define (no-origin) + "") + (define (rect-beam width slope thick blot-diameter) (let* ((x width) @@ -159,10 +202,8 @@ `(width . ,width) `(height . ,(+ thick (* (abs z) (/ thick 2)))) `(rx . ,(/ blot-diameter 2)) - `(transform . ,(string-append - (format #f "matrix (1, ~f, 0, 1, 0, 0)" (- z)) - (format #f " scale (~f, ~f)" - output-scale output-scale)))))) + `(transform . ,(format #f "matrix (1, ~f, 0, 1, 0, 0)" z) + )))) (define (beam width slope thick blot-diameter) (let* ((b blot-diameter) @@ -181,8 +222,7 @@ (cons (+ w (/ b 2)) (+ h (/ t 2))) (cons (+ w (/ b 2)) (+ h (- (/ t 2)))) (cons (/ b 2) (- (/ t 2))))))) - `(transform - . ,(format #f "scale (~f, -~f)" output-scale output-scale))))) + ))) (define (path-beam width slope thick blot-diameter) (let* ((b blot-diameter) @@ -201,8 +241,7 @@ 0 (- t) (- w) h 0 t)) - `(transform - . ,(format #f "scale (~f, ~f)" output-scale output-scale))))) + ))) (define (bezier-sandwich lst thick) (let* ((first (list-tail lst 4)) @@ -216,8 +255,7 @@ '(fill . "black") `(d . ,(string-append (svg-bezier first #f) (svg-bezier second first-c0))) - `(transform - . ,(format #f "scale (~f, -~f)" output-scale output-scale))))) + ))) (define (char font i) (dispatch @@ -226,22 +264,23 @@ (define-public (comment s) (string-append "\n")) -(define (dashed-line thick on off dx dy) - (draw-line thick 0 0 dx dy)) +(define (draw-line thick x1 y1 x2 y2 . alist) + + (apply entity 'line "" + (append + `((stroke-linejoin . "round") + (stroke-linecap . "round") + (stroke-width . ,thick) + (stroke . "black") + ;;'(fill . "black") + (x1 . ,x1) + (y1 . ,y1) + (x2 . ,x2) + (y2 . ,y2)) + alist))) -(define (draw-line thick x1 y1 x2 y2) - (entity 'line "" - '(stroke-linejoin . "round") - '(stroke-linecap . "round") - `(stroke-width . ,thick) - '(stroke . "black") - ;;'(fill . "black") - `(x1 . ,x1) - `(y1 . ,y1) - `(x2 . ,x2) - `(y2 . ,y2) - `(transform - . ,(format #f "scale (~f, -~f)" output-scale output-scale)))) +(define (dashed-line thick on off dx dy) + (draw-line thick 0 0 dx dy `(style . ,(format "stroke-dasharray:~a,~a;" on off)))) ;; WTF is this in every backend? (define (horizontal-line x1 x2 th) @@ -262,8 +301,8 @@ ;;(dispatch expr) expr `(transform . ,(format #f "translate (~f, ~f)" - (* output-scale x) - (- (* output-scale y)))))) + x (- y))))) + (define (polygon coords blot-diameter) (entity 'polygon "" @@ -274,8 +313,7 @@ ;;'(fill . "black") `(points . ,(string-join (map offset->point (ly:list->offsets '() coords)))) - `(transform - . ,(format #f "scale (~f, -~f)" output-scale output-scale)))) + )) (define (round-filled-box breapth width depth height blot-diameter) (entity 'rect "" @@ -292,8 +330,10 @@ `(width . ,(+ breapth width)) `(height . ,(+ depth height)) `(ry . ,(/ blot-diameter 2)) - `(transform - . ,(format #f "scale (~f, ~f)" output-scale output-scale)))) + )) (define (text font string) (dispatch `(fontify ,font ,(entity 'tspan (string->entities string))))) + +(define (utf8-string pango-font-description string) + (dispatch `(fontify ,pango-font-description ,(entity 'tspan string))))