X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Foutput-svg.scm;h=9f10629eacf7a6f2a3f4fc913aaa5ff3ee9a65a3;hb=8841948d136631e7547cd52665129bdb06f882f8;hp=9004694a058d7e3b71c2dc12bfe9b2fe81c5d72e;hpb=040fcffaf3d2a7e95dc08c4162d32fa5bc37a32d;p=lilypond.git diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 9004694a05..9f10629eac 100644 --- a/scm/output-svg.scm +++ b/scm/output-svg.scm @@ -1,6 +1,6 @@ ;;;; This file is part of LilyPond, the GNU music typesetter. ;;;; -;;;; Copyright (C) 2002--2010 Jan Nieuwenhuizen +;;;; Copyright (C) 2002--2012 Jan Nieuwenhuizen ;;;; Patrick McCarty ;;;; ;;;; LilyPond is free software: you can redistribute it and/or modify @@ -29,6 +29,7 @@ (guile) (ice-9 regex) (ice-9 format) + (ice-9 optargs) (lily) (srfi srfi-1) (srfi srfi-13)) @@ -54,20 +55,26 @@ (value (cdr x))) (if (number? value) (set! value (ly:format "~4f" value))) - (format " ~s=\"~a\"" attr value))) + (format #f " ~s=\"~a\"" attr value))) attributes-alist))) (define-public (eo entity . attributes-alist) "o = open" - (format "<~S~a>\n" entity (attributes attributes-alist))) + (format #f "<~S~a>\n" entity (attributes attributes-alist))) (define-public (eoc entity . attributes-alist) - " oc = open/close" - (format "<~S~a/>\n" entity (attributes attributes-alist))) + "oc = open/close" + (format #f "<~S~a/>\n" entity (attributes attributes-alist))) (define-public (ec entity) "c = close" - (format "\n" entity)) + (format #f "\n" entity)) + +(define (start-enclosing-id-node s) + (string-append "\n")) + +(define (end-enclosing-id-node) + "\n") (define-public (comment s) (string-append "\n")) @@ -85,7 +92,7 @@ (define (helper lst) (if (null? lst) '() - (cons (format "~S ~S" (car lst) (- (cadr lst))) + (cons (format #f "~S ~S" (car lst) (- (cadr lst))) (helper (cddr lst))))) (string-join (helper lst) " ")) @@ -322,18 +329,6 @@ ;;; stencil outputters ;;; -(define (bezier-sandwich lst thick) - (let* ((first (list-tail lst 4)) - (second (list-head lst 4))) - (entity 'path "" - '(stroke-linejoin . "round") - '(stroke-linecap . "round") - '(stroke . "currentColor") - '(fill . "currentColor") - `(stroke-width . ,thick) - `(d . ,(string-append (svg-bezier first #f) - (svg-bezier second #t)))))) - (define (char font i) (dispatch `(fontify ,font ,(entity 'tspan (char->entity (integer->char i)))))) @@ -350,7 +345,7 @@ (define (dashed-line thick on off dx dy phase) (draw-line thick 0 0 dx dy - `(stroke-dasharray . ,(format "~a,~a" on off)))) + `(stroke-dasharray . ,(format #f "~a,~a" on off)))) (define (draw-line thick x1 y1 x2 y2 . alist) (apply entity 'line "" @@ -384,8 +379,7 @@ (* (* x-radius x-radius) (* (sin angle) (sin angle))))))) (let* - ((dummy (format #t "INFO XR ~a YR ~a SA ~a EA ~a\n" x-radius y-radius start-angle end-angle)) - (new-start-angle (* PI-OVER-180 (angle-0-360 start-angle))) + ((new-start-angle (* PI-OVER-180 (angle-0-360 start-angle))) (start-radius (make-ellipse-radius x-radius y-radius new-start-angle)) (new-end-angle (* PI-OVER-180 (angle-0-360 end-angle))) (end-radius (make-ellipse-radius x-radius y-radius new-end-angle)) @@ -393,8 +387,7 @@ (x-end (- (* end-radius (cos new-end-angle)) (* start-radius (cos new-start-angle)))) (y-end (- (* end-radius (sin new-end-angle)) - (* start-radius (sin new-start-angle)))) - (dummy (format #t "INFO NSA ~a SR ~a NEA ~a ER ~a\n" new-start-angle start-radius new-end-angle end-radius))) + (* start-radius (sin new-start-angle))))) (if (and (< (abs x-end) epsilon) (< (abs y-end) epsilon)) (entity 'ellipse "" @@ -432,38 +425,6 @@ (- (* start-radius (sin new-start-angle)))) ""))))))) -(define (connected-shape pointlist thick x-scale y-scale connect fill) - (entity - 'path "" - `(fill . ,(if fill "currentColor" "none")) - `(stroke . "currentColor") - `(stroke-width . ,thick) - '(stroke-linejoin . "round") - '(stroke-linecap . "round") - (cons - 'd - (ly:format - "M0 0~a ~a" - (string-concatenate - (map (lambda (x) - (apply - (if (eq? (length x) 6) - (lambda (x1 x2 x3 x4 x5 x6) - (ly:format "C~4f ~4f ~4f ~4f ~4f ~4f" - (* x1 x-scale) - (- (* x2 y-scale)) - (* x3 x-scale) - (- (* x4 y-scale)) - (* x5 x-scale) - (- (* x6 y-scale)))) - (lambda (x1 x2) - (ly:format "L~4f ~4f" - (* x-scale x1) - (- (* y-scale x2))))) - x)) - pointlist)) - (if connect "z " ""))))) - (define (embedded-svg string) string) @@ -530,27 +491,7 @@ (define (no-origin) "") -(define (oval x-radius y-radius thick is-filled) - (let ((x-max x-radius) - (x-min (- x-radius)) - (y-max y-radius) - (y-min (- y-radius))) - (entity - 'path "" - '(stroke-linejoin . "round") - '(stroke-linecap . "round") - `(fill . ,(if is-filled "currentColor" "none")) - `(stroke . "currentColor") - `(stroke-width . ,thick) - `(d . ,(ly:format "M~4f ~4fC~4f ~4f ~4f ~4f ~4f ~4fS~4f ~4f ~4f ~4fz" - x-max 0 - x-max y-max - x-min y-max - x-min 0 - x-max y-min - x-max 0))))) - -(define (path thick commands) +(define* (path thick commands #:optional (cap 'round) (join 'round) (fill? #f)) (define (convert-path-exps exps) (if (pair? exps) (let* @@ -572,17 +513,31 @@ (closepath . z)) ""))) - (cons (format "~a~a" svg-head (number-list->point args)) + (cons (format #f "~a~a" svg-head (number-list->point args)) (convert-path-exps (drop rest arity)))) '())) - (entity 'path "" - `(stroke-width . ,thick) - '(stroke-linejoin . "round") - '(stroke-linecap . "round") - '(stroke . "currentColor") - '(fill . "none") - `(d . ,(apply string-append (convert-path-exps commands))))) + (let* ((line-cap-styles '(butt round square)) + (line-join-styles '(miter round bevel)) + (cap-style (if (not (memv cap line-cap-styles)) + (begin + (ly:warning (_ "unknown line-cap-style: ~S") + (symbol->string cap)) + 'round) + cap)) + (join-style (if (not (memv join line-join-styles)) + (begin + (ly:warning (_ "unknown line-join-style: ~S") + (symbol->string join)) + 'round) + join))) + (entity 'path "" + `(stroke-width . ,thick) + `(stroke-linejoin . ,(symbol->string join-style)) + `(stroke-linecap . ,(symbol->string cap-style)) + '(stroke . "currentColor") + `(fill . ,(if fill? "currentColor" "none")) + `(d . ,(apply string-append (convert-path-exps commands)))))) (define (placebox x y expr) (if (string-null? expr) @@ -617,23 +572,15 @@ `(points . ,(string-join (map offset->point (ly:list->offsets '() coords)))))) -(define (repeat-slash width slope thickness) - (define (euclidean-length x y) - (sqrt (+ (* x x) (* y y)))) - (let* ((x-width (euclidean-length thickness (/ thickness slope))) - (height (* width slope))) - (entity - 'path "" - '(fill . "currentColor") - `(d . ,(ly:format "M0 0l~4f 0 ~4f ~4f ~4f 0z" - x-width width (- height) (- x-width)))))) - (define (resetcolor) "\n") (define (resetrotation ang x y) "\n") +(define (resetscale) + "\n") + (define (round-filled-box breapth width depth height blot-diameter) (entity 'rect "" @@ -653,7 +600,7 @@ '(fill . "currentColor"))) (define (setcolor r g b) - (format "\n" + (format #f "\n" (* 100 r) (* 100 g) (* 100 b))) ;; rotate around given point @@ -661,6 +608,10 @@ (ly:format "\n" (- ang) x (- y))) +(define (setscale x y) + (ly:format "\n" + x y)) + (define (text font string) (dispatch `(fontify ,font ,(entity 'tspan (string->entities string))))) @@ -678,4 +629,8 @@ (ec 'a))) (define (utf-8-string pango-font-description string) - (dispatch `(fontify ,pango-font-description ,(entity 'tspan string)))) + (let ((escaped-string (string-regexp-substitute + "<" "<" + (string-regexp-substitute "&" "&" string)))) + (dispatch `(fontify ,pango-font-description + ,(entity 'tspan escaped-string)))))