From 7459c02eccd6a77c1d3c5fb2b7edda12c887601d Mon Sep 17 00:00:00 2001
From: Patrick McCarty <pnorcks@gmail.com>
Date: Sun, 10 May 2009 22:25:48 -0700
Subject: [PATCH] SVG backend: Fix dimensions of SVG document

* Use ly:format instead for rounding page dimensions;
  it gives more accurate results.

* Use the "viewBox" attribute for <svg> to scale the
  output instead of <g scale="">...</g>

* Remove other superfluous grouping tags

Signed-off-by: Patrick McCarty <pnorcks@gmail.com>
---
 scm/framework-svg.scm | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/scm/framework-svg.scm b/scm/framework-svg.scm
index b2e0b5604d..c1afaf8d2d 100644
--- a/scm/framework-svg.scm
+++ b/scm/framework-svg.scm
@@ -34,8 +34,8 @@
 	 (page-count (length page-stencils))
 	 (paper-width (ly:output-def-lookup paper 'paper-width))
 	 (paper-height (ly:output-def-lookup paper 'paper-height))
-	 (page-width (inexact->exact (ceiling (* output-scale paper-width))))
-	 (page-height (inexact->exact (ceiling (* output-scale paper-height))))
+	 (page-width (* output-scale paper-width))
+	 (page-height (* output-scale paper-height))
 	 (page-set? (or (> page-count 1) landscape?)))
 
     (ly:outputter-output-scheme outputter
@@ -44,19 +44,17 @@
 	      '(xmlns . "http://www.w3.org/2000/svg")
 	      '(xmlns:xlink . "http://www.w3.org/1999/xlink")
 	      '(version . "1.2")
-
-	      ;; Argggghhhh: SVG takes the px <-> mm mapping from the windowing system
-	      `(width . ,(format "~s" page-width))
-	      `(height . ,(format "~s" page-height))))
+	      `(width . ,(ly:format "~2fmm" page-width))
+	      `(height . ,(ly:format "~2fmm" page-height))
+	      `(viewBox . ,(ly:format "0 0 ~4f ~4f"
+				      paper-width paper-height))))
     
     (dump (dump-fonts outputter paper))
     (dump
      (string-append
       ;; FIXME: only use pages if there are more than one, pageSet is
       ;; not supported by all SVG applications yet.
-      (if page-set? (eo 'pageSet) "")
-      (eo 'g `(transform . ,(format "scale(~a, ~a) "
-				    output-scale output-scale)))))
+      (if page-set? (eo 'pageSet) "")))
     
     (for-each
      (lambda (page)
@@ -67,7 +65,6 @@
     (if page-set? (eo 'pageSet) "")
     (dump
      (string-append
-      (ec 'g)
       (if page-set? (ec 'pageSet) "")
       (ec 'svg)))
     
@@ -84,9 +81,7 @@
 	   (eo 'page '(page-orientation . "270"))
 	   (eo 'page))))
   
-  (dump (string-append (eo 'g )))
   (ly:outputter-dump-stencil outputter page)
-  (dump (string-append (ec 'g)))
   (if (or landscape? page-set?)
       (dump (ec 'page))))
 
-- 
2.39.5