]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/output-svg.scm
Doc-de: update macros.itely and nitpicks
[lilypond.git] / scm / output-svg.scm
index 51a491a8ef5d4d07277a952fb31fb5327b92e40d..80199a1f952871334a18b8dd595e38152c59ba9d 100644 (file)
@@ -2,7 +2,7 @@
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;;
-;;;; (c) 2002--2006 Jan Nieuwenhuizen <janneke@gnu.org>
+;;;; (c) 2002--2009 Jan Nieuwenhuizen <janneke@gnu.org>
 
 ;;;; http://www.w3.org/TR/SVG11
 ;;;; http://www.w3.org/TR/SVG12/ -- page, pageSet in draft
   (apply string-append
         (map (lambda (x) (char->entity x)) (string->list string))))
 
+(define svg-element-regexp
+  (make-regexp "^(<[a-z]+) (.*>)"))
+
 (define pango-description-regexp-comma
   (make-regexp "([^,]+), ?([-a-zA-Z_]*) ([0-9.]+)$"))
 
                             (ly:font-glyph-name-to-charcode font name))))))
 
 (define (placebox x y expr)
-  (entity 'g
-         expr
-         ;; FIXME: Not using GNU coding standards [translate ()] here
-         ;; to work around a bug in Microsoft Internet Explorer 6.0
-         `(transform . ,(ly:format "translate(~f, ~f)"
-                                x (- y)))))
+  (let*
+    ((match (regexp-exec svg-element-regexp expr))
+     (tagname (match:substring match 1))
+     (attributes (match:substring match 2)))
+
+    (string-append tagname
+                  ;; FIXME: Not using GNU coding standards
+                  ;; [translate ()] here to work around a
+                  ;; bug in Microsoft Internet Explorer 6.0
+                  (ly:format " transform=\"translate(~f, ~f)\" " x (- y))
+                  attributes
+                  "\n")))
 
 (define (polygon coords blot-diameter is-filled)
   (entity
 
 ;; rotate around given point
 (define (setrotation ang x y)
-  (format "<g transform=\"rotate(~a,~a,~a)\">"
+  (format "<g transform=\"rotate(~a,~a,~a)\">\n"
     (number->string (* -1 ang))
     (number->string x)
     (number->string (* -1 y))))
 
 (define (resetrotation ang x y)
-  "</g>")
+  "</g>\n")
 
 (define (round-filled-box breapth width depth height blot-diameter)
   (entity 'rect ""
    `(stroke-width . ,thick)
    `(r . ,radius)))
 
+(define (ellipse x-radius y-radius thick is-filled)
+  (entity
+   'ellipse ""
+   '(stroke-linejoin . "round")
+   '(stroke-linecap . "round")
+   `(fill . ,(if is-filled "currentColor" "none"))
+   `(stroke . "currentColor")
+   `(stroke-width . ,thick)
+   `(rx . ,x-radius)
+   `(ry . ,y-radius)))
+
+(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,~4f C~4f,~4f  ~4f,~4f ~4f,~4f S~4f,~4f ~4f,~4f" 
+               x-max 0
+               x-max y-max
+               x-min y-max
+               x-min 0
+               x-max y-min
+               x-max 0)))))
+
 (define (text font string)
   (dispatch `(fontify ,font ,(entity 'tspan (string->entities string)))))
 
 
 
 (define (setcolor r g b)
-  (format "<g color=\"rgb(~a%,~a%,~a%)\">"
+  (format "<g color=\"rgb(~a%,~a%,~a%)\">\n"
          (* 100 r) (* 100 g) (* 100 b)
          ))
 
 (define (resetcolor)
-  "</g>")
+  "</g>\n")