On Sat, May 09, 2009 at 10:11:50PM +0100, Neil Puttock wrote:
> 2009/5/7 Patrick McCarty <[email protected]>:
> 
> > Does anyone have any comments about this patch?
> 
> The SVG source is much easier to read. :)

I definitely agree!

> You're compiling the regexp each time the function's called; would it
> be better to define it outside the function so it's only compiled
> once?

Yes, I suppose that is a better idea.  Attached is a revised patch.

Thanks,
Patrick
>From 090c1ebe8f4a8a637cc1d4039c45c454b4138ec4 Mon Sep 17 00:00:00 2001
From: Patrick McCarty <[email protected]>
Date: Tue, 5 May 2009 12:21:52 -0700
Subject: [PATCH] SVG backend: In `placebox', do not group elements

* Avoid using <g>...</g> around all grobs and Pango
  text except for rotated or colored objects.  This
  makes SVG editing easier (with Inkscape, etc.)

Signed-off-by: Patrick McCarty <[email protected]>
---
 scm/output-svg.scm |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/scm/output-svg.scm b/scm/output-svg.scm
index 716f0f1..80199a1 100644
--- a/scm/output-svg.scm
+++ b/scm/output-svg.scm
@@ -107,6 +107,9 @@
   (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.]+)$"))
 
@@ -280,12 +283,18 @@
                             (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
@@ -301,13 +310,13 @@
 
 ;; 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 ""
@@ -376,9 +385,9 @@
 
 
 (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")
-- 
1.6.2.4

_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to