X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=scm%2Foutput-svg.scm;h=d993c356358c94fa21fe70f57c09e28cce49687b;hb=4a03918c90866800b208ad12ffc019f577c8ab83;hp=654c3a36a1c9d4514c3959b3b1404ce0efe2be9f;hpb=432c07343e1e5f97fe35c63b2573ce32f0f8b395;p=lilypond.git diff --git a/scm/output-svg.scm b/scm/output-svg.scm index 654c3a36a1..d993c35635 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--2011 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,20 @@ (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-public (comment s) (string-append "\n")) @@ -85,7 +86,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) " ")) @@ -350,7 +351,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 "" @@ -430,38 +431,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) @@ -548,7 +517,7 @@ 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* @@ -570,17 +539,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) @@ -632,6 +615,9 @@ (define (resetrotation ang x y) "\n") +(define (resetscale) + "\n") + (define (round-filled-box breapth width depth height blot-diameter) (entity 'rect "" @@ -651,7 +637,7 @@ '(fill . "currentColor"))) (define (setcolor r g b) - (format "\n" + (format #f "\n" (* 100 r) (* 100 g) (* 100 b))) ;; rotate around given point @@ -659,6 +645,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))))) @@ -679,5 +669,5 @@ (let ((escaped-string (string-regexp-substitute "<" "<" (string-regexp-substitute "&" "&" string)))) - (dispatch `(fontify ,pango-font-description - ,(entity 'tspan escaped-string))))) + (dispatch `(fontify ,pango-font-description + ,(entity 'tspan escaped-string)))))