abc2svg
View Ticket
Not logged in
Ticket UUID: b219622aee535d5f02452ce856aa9c0008e6bda7
Title: SVG rendered improperly
Status: Closed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Resolution: Misconfiguration
Last Modified: 2018-10-31 15:25:48
Version Found In:
User Comments:
wincent added as text/x-fossil-markdown on 2018-09-23 15:03:14:

Hello Jean-François,

I try to implement minimal environment for conversion from ABC to SVG in a web page. Unfortunately, it seems that the resulting SVG is rendered improperly; I think I am missing some include statement. Otherwise, all example pages from this repository are rendered beautifully. I use the current version of Firefox. The testing web page is opened locally.


wincent added as text/x-fossil-plain on 2018-09-23 15:05:53:
The testing web page is here: [https://gist.github.com/wincentbalin/7a27e5b3c8485646d236d4119848953b]

moinejf added as text/x-fossil-plain on 2018-09-24 08:15:34:
Hi,
The problem comes from your user function 'img_out'.
This one is called many times, once for each SVG image, and only the first image contains the display attributes (music font).
So, just replace
    output.innerHTML = str;
by
    output.innerHTML += str;
and don't forget to clear output.innerHTML before calling abc.tosvg
(it is simpler to use a global variable, cleared before abc.tosvg(), filled in user.img_out() and copied to output.innerHTML after abc.tosvg())

wincent added as text/x-fossil-plain on 2018-09-25 14:49:42:
Many thanks! This was the error indeed. I will update the example accordingly.

wincent added as text/x-fossil-plain on 2018-09-25 21:52:18:
Now I tried rendering using a global variable (the script under the link above was updated accordingly).

The first time the rendering works as expected. But when pressing the Update button the second time, it looks like the styles are removed. The generated SVG code looks okay for me, but the rendered result does not. What did I misconfigure?

moinejf added as text/x-fossil-plain on 2018-10-30 17:03:58:
Sorry for the delay.
The problem comes from your abc object. Once created, it gets ABC sequences from the function tosvg() and calls user.img_out() for each SVG image. Without anymore parameter (%%fullsvg) only the first image has all the definitions (fonts/glyphs).
In your code, on update, as you use the same abc object, the SVG images have no definition after the first update.
So, the right way is to create a new abc object inside the update function.

wincent added as text/x-fossil-plain on 2018-10-31 15:25:48:
I fixed the SVG update function in the way you described and it worked. Hence I consider this issue as resolved and this ticket as closed.

I uploaded the working testbed to the link further above in the discussion. Feel free to reference it in any documentation/discussion. The testbed is helpful for anyone who tries to program an ABC to SVG in a web page within a larger framework (wiki etc.).