[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cropped SVG Output

From: David Sankel
Subject: Cropped SVG Output
Date: Thu, 15 Oct 2015 14:10:53 -0600

Hello all,

I'm writing a Lilypond plugin for Sphinx and I'd like to use the SVG output
to embed the lilypond output into html files. Compared to PNG embedding,
SVG will allow a single webpage to look crisp on many different devices and
minimizes the bandwidth necessary on clients.

The problem I'm running into is that the SVG output option produces a SVG
file with a length and width of the entire page that I'm trying to render.
The PNG output, on the other hand, crops the score to the area with visible
elements on it. Of course, when embedding, I'm looking for a visible area
crop. Does anyone know if a cropped SVG output is possible?

One solution is to manually specify the page height to how tall I think the
score is going to be. I'd prefer an automated solution since presumably
lilypond already knows how to calculate the height of the visible area.

framework-svg.scm has the following code:

(define (dump-page paper filename page page-number page-count)
  (let* ((outputter (ly:make-paper-outputter (open-file filename "wb")
         (dump (lambda (str) (display str (ly:outputter-port outputter))))
         (lookup (lambda (x) (ly:output-def-lookup paper x)))
         (unit-length (lookup 'output-scale))
         (output-scale (* lily-unit->mm-factor unit-length))
         (device-width (lookup 'paper-width))
         (device-height (lookup 'paper-height))
         (page-width (* output-scale device-width))
         (page-height (* output-scale device-height)))

Here "paper-width" is being looked up and used for configuring the width
and height of the SVG element as well as the width and height of the
viewBox. How would I get the width and height of the visual area over here?

Any other suggestions as to how I could add a visible-area SVG output

Thanks in advance for any help,

David Sankel

reply via email to

[Prev in Thread] Current Thread [Next in Thread]