[Top][All Lists]

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

Re: SVG in \markup Block?

From: Aaron Hill
Subject: Re: SVG in \markup Block?
Date: Sun, 19 Jan 2020 18:22:22 -0800
User-agent: Roundcube Webmail/1.3.8

On 2020-01-19 5:41 pm, Arle Lommel wrote:
In a nutshell, I’d like to do one of the following:

1. Use an SVG description of a shape directly in a \markup block. (I
want something entirely portable within a single Lilypond file, rather
than referencing external files, hence the desire to have it directly
in the \markup block.)

The \postscript markup command embeds PostScript within \markup, but that is merely passed through to the PS output. If you were to output with SVG, then that markup would be omitted.

A similar markup command could be made that would allow embedding SVG that is passed through to SVG output; but again, it would not do anything for PS output.

If you want to go this route, lookup the embedded-svg stencil command. I posted about this not to long ago with the topic on embedding JavaScript in SVG output.

2. Convert the SVG description to appropriate native Lilypond drawing
commands. (I’m guessing this is entirely trivial for someone who knows
what to do, but I don’t.)

This is the only option if you want to avoid tying the output to the input. By using the \path command (or other drawing commands), your document would be able to output both PS and SVG formats.

This would require conversion of SVG to \path syntax, but it turns out to be pretty easy for most of SVG's primitives.

P.S., for a concrete example of the kind of thing I want to do, I’d
like to convert an SVG string such as this:

<path class="st0" d="M2.94,8.32L0,0h1.38L3.1,5.36L4.56,0h0.68L2.94,8.32z”/>

That would convert to:

\markup \path #0.1 #'(
  (moveto 2.94 8.32) (lineto 0 0) (rlineto 1.38 0)
  (lineto 3.1 5.36) (lineto 4.56 0) (rlineto 0.68 0)
  (lineto 2.94 8.32) (closepath)

(I had to guess at the styling of the path, but know that \path supports a number of properties you can \override to control how it strokes and/or fills the shape.)

It should not be too difficult to create a procedure to unpack an SVG string into the equivalent shown above. If I get a few moments, I might try my hand and sketching something.

-- Aaron Hill

reply via email to

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