Melodeon.net Forums

Discussions => Tunes => ABC => Topic started by: Stiamh on March 29, 2020, 10:33:41 PM

Title: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 29, 2020, 10:33:41 PM
When I export a single tune as an SVG, the output disregards formatting commands such as %%titlefont, %%composerfont, etc. Everything is in what looks like Times Roman.

This does not happen when exporting to PDF, when fonts are displayed as specified.

Any ideas? Thanks in advance.

EasyABC 1.3.7.7 2017-08-31, Windows 10.

Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on March 30, 2020, 09:18:21 AM
I have had problems with this in the past. After much struggling and experimentation I did manage to get things to work using a very limited set of fonts. iirc this was limited by those fonts that I had installed on my computer and knowing the correct location. Any recommendations I make may not work on your system.

In my experience the best way to deal with this is to export the SVG then edit using either a dedicated GUI vector package such as inkscape or Adobe Illustrator, or by opening the svg/xml file using a plain text editor and making the necessary adjustments by hand.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on March 30, 2020, 11:01:03 AM
As an example of the process I have described above, the attached PDF was made made by exporting the musical notation from abc to SVG using abcm2ps. The resulting SVG was then imported to Inkscape (https://inkscape.org/) where text was added and layout defined. If I can find them, i have some examples where i have used a set of unusual fonts to replicate 18thC chapbooks.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 01:40:07 PM
Thanks Mike. I confess I was hoping for a less labour-intensive solution, since the project I am working on involves creating upwards of 500 SVG files. But thank you for the link to Inkscape, which looks like a very fine initiative.

Presumably EasyABC uses an external component to convert scores to SVG, but poking about in the settings I can't find an indication as to what that might be. Somewhere in that component these fonts must be specified. I suppose the next step is a question to the ABC users Yahoo group, which I was hoping to avoid...
 
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on March 30, 2020, 02:21:42 PM
Hi,

Easy abc is (most likely) using abcm2ps to output to svg

What are you using to view your svg files, and, can you provide some examples.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Tone Dumb Greg on March 30, 2020, 02:25:52 PM
or, import into musescore then export as SVG, maybe?
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 02:59:01 PM
Easy abc is (most likely) using abcm2ps to output to svg. What are you using to view your svg files, and, can you provide some examples.

Viewing in a browser - the intended purpose. Can't attach svg files - example here (http://www.rogermillington.com/steam/TQ002.svg).

or, import into musescore then export as SVG, maybe?

I had a hunch this suggestion would be forthcoming... Thanks, but I really don't want to add another step in the process, 500 files and all that. :|glug
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Steve_freereeder on March 30, 2020, 03:04:54 PM
or, import into musescore then export as SVG, maybe?

Yes - MuseScore export to SVG works nicely, and preserves fonts.

Just being curious though: what is the advantage in this instance of converting ABC to SVG? Why not stick with exporting to PDF, seeing as it preserves all the fonts, etc., that Stiamh (the OP) wants? As far as I can see, unless you are going to perform complex or sophisticated graphics manipulation on the resulting file, it seems a slightly odd thing to want to do to a music file.

Edit - have just seen Stiamh's last post.
I thought that PDF files can be viewed in a browser quite happily, or am I wrong?
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Anahata on March 30, 2020, 04:18:13 PM
PDFs view directly in Chrome and its many relatives, but not in Firefox, in my recent experience.
SVG is an image format like jpeg and PNG that can be simply inserted in any HTML document. PDF is not, so all you can do is display the whole PDF in the browser window by itself.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on March 30, 2020, 04:43:10 PM
SVG is an image format like jpeg and PNG
SVG (scalar vector graphic) is an XML format which can be styled using CSS. The attached PDF was produced by applying an external CSS file to SVG exported from abcm2ps.

The two line CSS instruction show below was used to style the tune title.

Code: [Select]
g:first-of-type {
font-family: Milkmoustachio !important;
font-size: 60px !important;
}
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on March 30, 2020, 04:49:37 PM
Viewing in a browser - the intended purpose. Can't attach svg files - example here (http://www.rogermillington.com/steam/TQ002.svg).

There is more than one browser, on more than one platform. Also, what is it supposed to look like.

Your SVG file has:
Code: [Select]
<title> page 1</title>
<!-- Creator: abcm2ps-8.14.7 -->
<!-- CreationDate: Mar 29, 2020 17:20 -->
<!-- CommandLine: - -O TQ002.svg -v -->
<g stroke-width="0.70">
<!-- title: Berceuse pour Hannah -->
</g>
<g stroke-width="0.70" style="font:22.00px Helvetica,">
<text x="396.90" y="45.60" text-anchor="middle">Berceuse pour Hannah</text>
</g>
<g stroke-width="0.70" style="font:14.00px Helvetica,16">
<text x="774.90" y="70.00" text-anchor="end">Réjean Brunet, Richard Forest, Sabin Jacques (Québec)</text>
</g>
<g stroke-width="0.70" style="font:20.00px Arial,">
<text x="18.90" y="78.00">ABA</text>
</g>
<g stroke-width="0.70" style="font:20.00px Arial,">
<text x="86.90" y="106.00">A</text>

At the start, meaning that it did not render the fonts out as vector images, so, you will be depending on the ability of a browser/platform to render the fonts, which is fine and normal but is a real consideration one might make. I can also see that it's going to try and use Helvetica and Arial?

What font is it supposed to be using? I'm assuming you're using the commas and such from this thread http://forum.melodeon.net/index.php?topic=21378.0 ?

Most likely, there is a more correct way to style these fonts than what is happening here.

edit I suspect this is going to be useful (to me) https://stackoverflow.com/a/7742345

Also I noticed you're using 8.14.7 - are you able to compile abcm2ps from source?
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 05:50:37 PM
There is more than one browser, on more than one platform. Also, what is it supposed to look like.

What font is it supposed to be using? I'm assuming you're using the commas and such from this thread http://forum.melodeon.net/index.php?topic=21378.0 ?

Most likely, there is a more correct way to style these fonts than what is happening here.

edit I suspect this is going to be useful (to me) https://stackoverflow.com/a/7742345

Also I noticed you're using 8.14.7 - are you able to compile abcm2ps from source?

Duh, I never realised you could open an SVG in a text editor...

The fonts and sizes are actually those specified in the formatting commands I used! So the browser is ignoring them?

Checking all my browsers: Opera, Chrome, Firefox and MS Edge all show a Times-type serif font. But the dreaded IE 11 (which I am obliged to keep to connect with a particular customer) is showing a Helvetica/Arial sans-serif font, and displaying the relative sizes.  ::)

I have never got into compiling stuff. I just downloaded the latest version of abcm2ps and pointed EasyABC to it.

Edited to add: Firefox  :(
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on March 30, 2020, 06:25:55 PM
May I have the ABC styling commands, please?

At some point, abcm2ps switched to using css invoking style to set the font and size. At the very least as a result of this, trailing commas are bad and may cause the whole font code to be ignored. This may however mean it can use webfonts, but, I'm no expert. I haven't updated my abcm2ps binary and it uses a different method to set the font.

Otherwise, if you're using Helvetica, you should know that basically only mac users will have that font.

If you need to use a font for some particular reason, and want everyone to see it no matter what, it turns out it's possible to use Inkscape via command line (and thus, easily batchable across 500 files) to convert text to paths, which will basically render the text on your PC (which has the font) and convert it to vectors so everyone else's computer will always know how to render it. However this is kinda the same as taking a screen shot of text? It will remain crisp because vectors, but, it will cease to actually be text. It will also make your files significantly larger and may create some minor differences when compared side by side. My test file was 10x larger.

Advice #1) Try making sure no trailing commas are being invoked.
Advice #2) Consider rendering text-to-path via inkscape cli, inkscape in.svg --export-text-to-path --export-plain-svg out.svg worked for me.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 06:45:44 PM
May I have the ABC styling commands, please?

%%titlefont Helvetica, 22
%%subtitlefont Helvetica,16
%%composerfont Helvetica,16
%%wordsfont Helvetica,16
%%partsfont Arial, 20
%%partsbox
%%gchordfont Arial, 16
%%barnumbers 0
%%printtempo 0
%%writefields S

I'm feeling pretty silly now. I think I inherited the formatting commands from a Mac-using collaborator on the project, hence the Helvetica specification.

Strangely enough, the partsfont was Arial, but that wasn't working.

However, I just changed the titlefont to Arial and for fun the composerfont to Courier New and they worked. Font size respected, too.

CSS allows you to specify a series of possible fonts such as

   {font: bold 11pt/12pt Verdana, Arial, Helvetica, sans-serif}

I wonder if abc2mps and SVG do? More experiments coming up.

Thanks for pointing me down the right path, as you have done before  :|glug

Quote
At some point, abcm2ps switched to using css invoking style to set the font and size. At the very least as a result of this, trailing commas are bad and may cause the whole font code to be ignored. This may however mean it can use webfonts, but, I'm no expert. I haven't updated my abcm2ps binary and it uses a different method to set the font.

Otherwise, if you're using Helvetica, you should know that basically only mac users will have that font.

If you need to use a font for some particular reason, and want everyone to see it no matter what, it turns out it's possible to use Inkscape via command line (and thus, easily batchable across 500 files) to convert text to paths, which will basically render the text on your PC (which has the font) and convert it to vectors so everyone else's computer will always know how to render it. However this is kinda the same as taking a screen shot of text? It will remain crisp because vectors, but, it will cease to actually be text. It will also make your files significantly larger and may create some minor differences when compared side by side. My test file was 10x larger.

Advice #1) Try making sure no trailing commas are being invoked.
Advice #2) Consider rendering text-to-path via inkscape cli, inkscape in.svg --export-text-to-path --export-plain-svg out.svg worked for me.

I'll investigate using CSS and style, and will bear all the rest in mind if I can't get things to work with simpler remedies! Thanks.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on March 30, 2020, 07:03:24 PM
I wouldn't feel silly - there's a good chance that at some point one of the many rendering pathways required the presence of such a comma. There's a good chance that may still be the case. People in that other thread found it was necessary, for whatever reason.

Odds are, yes, abcm2ps will take whatever you type in and will pass it through to the outputted svg without thinking too much about it. The exact code that's used is here: https://github.com/leesavide/abcm2ps/blob/master/svg.c#L1278 and you can see it doesn't do much except attempt to fix capital letters in 'Bold' 'Italic' and 'Oblique', then after that I'm guessing prints whatever wasn't interpreted as the font size out after the size (as a 2 decimal point float for some reason).

Worst case you can put some placeholder word in there and find/replace, again as a batch operation with a powerful text editor, and replace it with the font instructions you would like to be present. In theory you should be able to suggest several fonts exactly as you describe, however, should that list of fonts end in a comma (and it was getting sent 'Helvetica,', css is most likely going to say 'you did a bad' and ignore the whole list, size and all.

So hopefully the fix is:

%%titlefont Helvetica, 22
->
%%titlefont Helvetica 22
->
%%titlefont Helvetica, Some_Other_Font 22


But idk maybe it's going to split on the first space and explode, I'm not sure.

Best of luck.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Steve_freereeder on March 30, 2020, 07:33:38 PM
PDFs view directly in Chrome and its many relatives, but not in Firefox, in my recent experience.
SVG is an image format like jpeg and PNG that can be simply inserted in any HTML document. PDF is not, so all you can do is display the whole PDF in the browser window by itself.
Thanks for the explanation! I can upload and view PDFs in Firefox with no trouble, but I take your point about insertion in an HTML document.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 09:02:07 PM
@Gena, I was feeling silly because of Helvetica being only available on Macs.

But I needn't have because

Quote from: Guido Gonzato's ABC Plus Bible
Formatting  commands specify the character fonts used in various parts of a score. Please note that the common True Type fonts used by the operating system are not the fonts used by abcm2ps. In fact, abcm2ps uses the PostScript fonts provided for and managed by Ghostscript. Standard fonts are shown in Appendix A.4 (p. 134). I remind you that indications for adding new fonts are given in Section 4.3.5 (p. 82).

These standard fonts include Helvetica.  (:)

And yes, it was the bleeding comma.

Thanks to all for the helpful comments and interesting avenues to explore - and especially to Gena (as usual!).
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on March 30, 2020, 09:57:46 PM
Right but in this case we are only using abcm2ps as a conduit to write svg code, we're not actually using ghostscript to render the text at the time of creating the svg, so, that job is left for the end user's browser, and it most likely becomes the standard problem of fonts-on-the-internet.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 30, 2020, 10:47:48 PM
Right but in this case we are only using abcm2ps as a conduit to write svg code, we're not actually using ghostscript to render the text at the time of creating the svg, so, that job is left for the end user's browser, and it most likely becomes the standard problem of fonts-on-the-internet.

Ah shite  :D
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on March 31, 2020, 11:07:43 AM
Yes if you want to inline a score into a web page, svg works well, but pdf don't natively inline. E.g. see:

http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html)

These were transcribed in lilypond, a text file method of typsetting music. And its a thought, would going via lilypond work better e.g. the lilypond command "abc2ly" converts abc files into lilypond.

svg support in browsers should be solid, it was available natively in html 4.0, and as most browsers aim to support most standards, it should be supported.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Anahata on March 31, 2020, 11:53:07 AM
Yes if you want to inline a score into a web page, svg works well, but pdf don't natively inline. E.g. see:

http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html)


Hmm... Unfortunately Firefox (68.6.0esr on Linux) makes a dog's dinner of the SVG on that page, the text in huge letters overlapping all over the music.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on March 31, 2020, 01:35:52 PM
Yes if you want to inline a score into a web page, svg works well, but pdf don't natively inline. E.g. see:

http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html)


Hmm... Unfortunately Firefox (68.6.0esr on Linux) makes a dog's dinner of the SVG on that page, the text in huge letters overlapping all over the music.
Hmm - thanks for letting me know. For what its worth I'm looking at it on firefox (73.0.1) on ArchLinux, and its as intended. let me check how the fonts are encoded in the svg, I suspect as text so the machine needs to know the font. Looks like Times Roman to me. Oh yes - if you click on any of the bits of music, it will download a pdf, so you can see how it was meant to look ...

OK sample of the xml svg text:
Quote
  <text
     font-size="2.4696"
     id="text88"
     style="font-size:2.46959996px;font-family:serif;text-anchor:start;fill:currentColor"
     x="16.344711"
     y="23.406433">
    <tspan
       id="tspan86">Down</tspan>
  </text>
Which looks fine, and should be the right size. So suspect the serif font isn't recognised. Which seems very strange. As commented about changing all fonts into path is possible, but not a great solution as give huge files. Hmmm ...
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on March 31, 2020, 11:15:28 PM
Since Gena pointed out that, in the case of SVGs, fonts will be rendered on the user's machine, I think it would be best to stick to common fonts, and I have prepared files using Times, Arial, Helvetica, and Verdana.

I know that these work well on my Windows machine using all the browsers I have. Could those of you who are on different platforms, esp. Macintosh and Linux, report on how they look to you, specifying OS and browser.

Is the title font in each case different and presentable, resembling what you would expect for these fonts (Times being the only serif font)?

Thanks in advance!

Times (http://rogermillington.com/steam/TimesPourHannah.svg)
Helvetica (http://rogermillington.com/steam/HelveticaPourHannah.svg)
Arial (http://rogermillington.com/steam/ArialPourHannah.svg)
Verdana (http://rogermillington.com/steam/VerdanaPourHannah.svg)
Verdana bold (http://rogermillington.com/steam/VerdanaBoldPourHannah.svg)


PS Does anybody know if it is possible to control the font used for symbols such as !FINE! and !D.C.! ? I have tried all the font commands listed in the Guido guide and elsewhere, but none seem to work on these.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Anahata on April 01, 2020, 12:05:17 AM
On Firefox 68, Debian Linux, the Helvetica is coming up with a serif font. It may be my browser's default font.
The others look like the fonts they are supposed to be.

Note that any system will generally display any font that is installed on it, whether it's Windows, Linux or a Macintosh; for example I could install any Truetype font here. The only Helveticas I have are bitmapped fonts, so Firefox doesn't use them (unless, perhaps, they happen to match a specified size.)

Unlike Postscript and PDF, SVG doesn't seem to have "standard" or "base" fonts - you are simply advised to use web-safe fonts (or presumably embed special fonts if you need them.)

Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on April 01, 2020, 12:30:39 AM
Does anybody know if it is possible to control the font used for symbols such as !FINE! and !D.C.! ?

Look at the last few lines of the svg/xml source.

Code: [Select]
<text style="font:16px serif"
x="752.50" y="334.80" text-anchor="middle">D.C.</text>
</g>
<g stroke-width="0.70" style="font:16.00px Courier">
<text x="68.90" y="415.60">Some comments by Jean Duval in Courier. Pas bon!!!</text>
</g>
</svg>

note the styling for both the inline D.C. and the comment below the stave. Changing these will change the display. making these changes by hand is easy, but laborious. It might be possible to write an external CSS stylesheet that would work for individual display, but it would be difficult to ensure that this would work for all instances.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Steve_freereeder on April 01, 2020, 12:43:31 AM
... Could those of you who are on different platforms, esp. Macintosh and Linux, report on how they look to you, specifying OS and browser.

Is the title font in each case different and presentable, resembling what you would expect for these fonts (Times being the only serif font)?

Thanks in advance!

Times (http://rogermillington.com/steam/TimesPourHannah.svg)
Helvetica (http://rogermillington.com/steam/HelveticaPourHannah.svg)
Arial (http://rogermillington.com/steam/ArialPourHannah.svg)
Verdana (http://rogermillington.com/steam/VerdanaPourHannah.svg)
Verdana bold (http://rogermillington.com/steam/VerdanaBoldPourHannah.svg)

On MacOS 10.14.6 (Mojave) I get the following:
Using Firefox (v. 74) all fonts display correctly.
Using Safari (v. 13.0.5) Verdana and Verdana Bold are showing up as a serif font (looks a bit like Times New Roman). The others are all OK.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on April 01, 2020, 02:03:56 AM
Thanks, Anahata & Steve. More feedback from others would be appreciated!

Thanks Mike. I will try hand-tweaking the styling. Since I will be producing a large number of images in this project, the easiest thing would be to write a macro in my text editor or script to make the changes (although actually the proportion of tunes having !symbols! is not very high).
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Steve_freereeder on April 01, 2020, 09:00:22 AM
On MacOS 10.14.6 (Mojave) I get the following:
Using Firefox (v. 74) all fonts display correctly.
Using Safari (v. 13.0.5) Verdana and Verdana Bold are showing up as a serif font (looks a bit like Times New Roman). The others are all OK.
Also, using Opera v. 67 on the same platform, I can confirm that all the fonts are dispalying correctly.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 01, 2020, 09:03:12 AM
Times (http://rogermillington.com/steam/TimesPourHannah.svg)
Helvetica (http://rogermillington.com/steam/HelveticaPourHannah.svg)
Arial (http://rogermillington.com/steam/ArialPourHannah.svg)
Verdana (http://rogermillington.com/steam/VerdanaPourHannah.svg)
Verdana bold (http://rogermillington.com/steam/VerdanaBoldPourHannah.svg)
All worked on my ArchLinux and firefox. Interesting almost none worked on my tablet (android, something like 10), all had the same sans-serif font,  (bold was bold though). Note that my desk top has a good selection of fonts in /usr/share/fonts - including a host of ttf, which is probably what firefox svg interpreter uses. (or whatever firefox uses, probably pango/cairo ...).

This svg page is instructive: https://www.w3.org/TR/SVG/fonts.html (https://www.w3.org/TR/SVG/fonts.html) - fonts used to be in the specification but were removed. This could explain the problems, programs that use the old specification have fonts in the svg; but new svg specification is clear, should use CSS fonts https://www.w3.org/TR/css-fonts/ (https://www.w3.org/TR/css-fonts/).

Sigh - I'll see if I can create a page using the new sodding specification ....
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on April 01, 2020, 10:58:57 AM
Since I will be producing a large number of images in this project, the easiest thing would be to write a macro in my text editor or script to make the changes (although actually the proportion of tunes having !symbols! is not very high).

Identifying the tunes which include !symbols! would be easiest doing some sort of global search over the abc source(s). If you are OK with using regular expressions this should not be too difficult. If the number is not too small, I would suggest that hand editing would be the quickest way to go.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on April 01, 2020, 06:54:48 PM
PS Does anybody know if it is possible to control the font used for symbols such as !FINE! and !D.C.! ? I have tried all the font commands listed in the Guido guide and elsewhere, but none seem to work on these.

How are they defined in the ABC? Honestly I should have just asked for (a link to) the ABC for this tune by now. My guess is they are decorations:
http://abcnotation.com/wiki/abc:standard:v2.2#decorations so, they are very specific words put in between !s, exactly as you put in your post, (a-duh)

This means that they're considered decorations by abcm2ps and likely are looked up in this list:
https://github.com/leesavide/abcm2ps/blob/master/deco.c#L124
which sets up a command word 'dacs' which gets used in the output SVG code via this switch case statement
https://github.com/leesavide/abcm2ps/blob/master/svg.c#L2331

(Thanks for your post, Mike, with that example, it was the first breadcrumb I followed to figure out the above)

Basically: you get you a hard coded serif font output with at least !FINE! and !D.C.! - so, to answer your question, I can tell you that no, without modifying the binary either by compiling the source code yourself, or hex editing to turn that particular serif into a keyword to find later, you're out of luck in terms of having the program do the job for you.

The good news is that font:16px serif is only found in your discussed decorations & those other few covered by the 'dacs' keyword in deco.c, and whatever dacoda would be (per ABC spec, !dacoda!               the word "Da" followed by a Coda sign) so, you can probably search for the above text throughout all your SVG files and it will most likely be unique to these problem cases, because of the lack of decimal points after the 16, there.

You might be better served just searching for 'serif', if you potentially have other examples of !! decorations, as these will have slightly different handling that also results in hard coded serif font, with either bold/italics or a different size.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on April 02, 2020, 02:19:50 AM
Editing the SVGs manually to adjust the font and size of the decorations is definitely a possibility. Actually a further, and bigger, gripe with the !D.C.! symbol in the examples I posted is that it is too high and interferes with "volta bracket" whereas the !FINE! does not. I don't think I want to get into fiddling with the instructions that produce that result.

Thank you to everyone for the feedback on the samples, and to Mike and Gena esp. for all the technical information and impressive sleuthing. I am much obliged to you all! :|glug
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on April 02, 2020, 07:05:23 AM
So, there's this to consider. It seems it's very cleverly positioning the decoration text based on the notes below it, but, it may not have any idea about the volta bracket to realise it should avoid it. The reason why it'll be higher in one place than another is most likely because of the note below it.

Most likely there isn't any good way to win, however, you may find making the text smaller will solve most of your problems.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 02, 2020, 12:43:06 PM
Yes if you want to inline a score into a web page, svg works well, but pdf don't natively inline. E.g. see:

http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html)


Hmm... Unfortunately Firefox (68.6.0esr on Linux) makes a dog's dinner of the SVG on that page, the text in huge letters overlapping all over the music.
OK, try this updated: https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html).

I've updated the svg to close to the SVG 2.0 standard. The fonts I've taken into a CSS; alas the font sizes I couldn't get to work in a style sheet, so these are still specified in the <text> tabs.

Would be good to know if this makes it displayable in more places. Next thing to do would be to change to WOFF fonts, and distribute the font with the page. Don't want to do that .... but seems only way to break the dependence on the fonts installed on the computer ...
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Anahata on April 02, 2020, 01:41:44 PM
OK, try this updated: https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html).

I've updated the svg to close to the SVG 2.0 standard. The fonts I've taken into a CSS; alas the font sizes I couldn't get to work in a style sheet, so these are still specified in the <text> tabs.


Sorry, no obvious improvement. Perhaps I should try the latest version of Firefox.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Anahata on April 02, 2020, 01:47:35 PM
Here's what it looks like (In case it's any help)

Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 02, 2020, 02:25:34 PM
OK, try this updated: https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html (https://davidjohnsummers.uk/music/CastletonCarol/CastletonCarol.html).

I've updated the svg to close to the SVG 2.0 standard. The fonts I've taken into a CSS; alas the font sizes I couldn't get to work in a style sheet, so these are still specified in the <text> tabs.


Sorry, no obvious improvement. Perhaps I should try the latest version of Firefox.
Ta - thanks for checking again. Yes what it looks like doesn't surprise me - I went through many graphics like that whilst attempting to update to SVG 2.0.

I try (harder) to get the font size into the CSS, but suspect its the host machine not finding fonts (especially as you and I are on similar machines). Alas as font specified (serif) should be available in one standard form or other, sounding like unless font provided (WOFF), may not work.

Anyway let me check the specification *very* carefully to see how to specify size - alas the SVG spec are evolving, and often you get to see something in draft that half way between two standards ....

Actually looking carefully at that graphic, everything in the CSS did work. E.g. The font is serif, and the bits in bold are in bold, so it just the font size thats failed ....
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Steve_freereeder on April 02, 2020, 03:12:36 PM
Here's what it looks like (In case it's any help)
It looks like a piece of artwork. If you printed it at very large (e.g. A0 size) and then framed it, you could hang it on the wall, or better still, print a limited edition number of copies and flog 'em on Etsy or e-bay.  ;)
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Gena Crisman on April 02, 2020, 05:14:06 PM
Would adding a backup font to the font-family help this one, seemingly rare occurrence?

It's super weird though, frankly that even if the font is not found, that the size would be so ridiculous. Maybe it's throwing a fit at the perfectly valid floating point sizes?
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on April 02, 2020, 05:38:55 PM
It might be useful here to clarify the situation with regard to styling SVG using external CSS.

SVG referenced using <img>, <object> or <embed> tags cannot be styled using external css. All styling must be included in the SVG. This can be inline or in a <style> block, usually at the start of the file.

If SVG is inline - i.e SVG code is included in html <body> external css will work. This can be either an external file referenced in the html head, or css style rules defined in a <style> block included in the html <head>.

The most common work around with referenced SVG is to use jquery.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 02, 2020, 06:15:46 PM
Here's what it looks like (In case it's any help)
OK managed to get the size into the CSS. Problem was the font-size in CSS had a totally different meaning than in the main body, and that maybe explains what was going wrong. To get things right kind of size had to use 2pt font and smaller!

Anyway can you try:

(http://davidjohnsummers.uk/music/CastletonCarol/CastletonCarolRVW.svg)

If that works I'll convert all to that. Then come up with a script to do automatically - alas will only work on linux.

Oh yes - I'm embedding the CSS in the SVG file:
Quote
<style text="style/css">
<![CDATA[
tspan { white-space: pre; }
text.heading { font-weight: bold; font-family: serif; font-size: 2pt; }
text.subheading { font-weight: bold; font-family: serif; font-size: 1.5pt; }
text.composer { font-family: serif; font-size: 1.6pt; }
text.arranger { font-family: serif; font-size: 1.6pt; }
text.verseno { font-family: serif; font-size: 1.6pt; font-weight: bold; }
text.verse { font-family: serif; font-size: 1.8pt; }
text.exverse { font-family: serif; font-size: 1.6pt; }
]]>
</style>
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on April 02, 2020, 06:29:57 PM
Dunno about anyone else, but I'm learning a lot from this thread.

WRT to styling !symbols! I have a method which works. Will post when i have finished cooking and eating.  (:)
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 02, 2020, 06:40:12 PM
I'm learning a lot as well, alas not the kind of thing I like to learn. In this case that there is a fair bit of movement between SVG 1.1 and SVG 2.0 - my <text> elements are totally different. Its a pity of a worry that specifications move so fast, and half wonder if it is what gives the problems rendering my files on some machines, which are only slightly different from mine! Given how long SVG has been around, I'd have expected it to be stable by now ...
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Mike Hirst on April 02, 2020, 09:29:42 PM
Styling abc decorations and symbols

As has been identified through previous posts the problem with styling svg text elements generated using abcm2ps is that all elements are the same.

Take this simple example:

Code: [Select]
X:1
T:text
L:1/1
M:none
K:none
c|c|c|c|!fine!c||
%%text text text text

svg output wraps title, decoration and text all in the same <text> element. fonts differ, but everything else is the same.

Code: [Select]
<g stroke-width="0.70" style="font:20.00px Times">
<text x="350.80" y="22.00" text-anchor="middle">text</text>
</g>

<text style="font:16px serif"
x="216.60" y="50.80" text-anchor="middle">FINE</text>
</g>

<g stroke-width="0.70" style="font:16.00px Times">
<text x="10.00" y="125.60">text text text</text>
</g>

This makes it difficult to define a CSS selector that work for all abcm2ps output.

Even though it would be possible to identify these problems in the abc source, there is no easy way to control output.

However, if we convert the abc source to MusicXML we find that the text based !fine! decoration is contained in a <direction-type> element block:

Code: [Select]
<direction placement="above">
<direction-type>
<words>Fine</words>
</direction-type>
<sound fine="yes" />
</direction>

Now we're getting somewhere.

I made the conversion using Willem G. Vree's python script abc2xml.py (https://wim.vree.org/svgParse/abc2xml.html). If we now convert the MusicXML output to svg using verovio (https://www.verovio.org/overview.xhtml), we find that the text decoration is typed using XML attributes in the <g> and <tspan> elements.

Code: [Select]
<g class="dir" id="dir-0000000826100347">
<text x="7402" y="1121" font-size="0px">
<tspan class="text" id="text-0000000487730185">
<tspan font-size="405px" class="text">Fine</tspan>
</tspan>
</text>
</g>

These can be used to make CSS selectors to style SVG display.

Code: [Select]
.dir {
fill:red;
}

The files attached below illustrate the steps involved in the process. Although it might at first appear over complicated. Piping output direct from abc2xml to verovio the process can be streamlined. WRT the OP, a single line cli string is all that is needed to run the command recursively over large numbers of files. Adding the css reference to the svg output can also be scripted. Using one common css file makes maintenance and upgrading simple and flexible.


N.B. file extensions have been unified to .txt to enable usage as forum attachments.
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: David Summers on April 03, 2020, 08:16:39 AM
Good stuff Mike. Yes we are both going down the same direction. Me, I'm modifying lilypond output.

I guess another thing one learns from this, is how ugly most of these programs svg output is.

E.g. abcm2ps
Quote
<text style="font:16px serif"
x="216.60" y="50.80" text-anchor="middle">FINE</text>
</g>
Is missing the open group "<g>". But it also begs the question, of why a group has been set up with just a single <text> element. Especially as the style could go in the <text> tab as as done in this code.

The MusicXML is well constructed, but who can say what it means - its not elements for placement and style etc - so thats all elsewhere.

My original lilypond output is quite horrible:
Quote
<text transform="translate(40.8866, 6.4989)" font-family="serif" font-weight="bold" font-size="3.4927" text-anchor="start" fill="currentColor">
<tspan>Down in Yon Forest</tspan>
</text>
It at least is well formatted, a <tspan> inside a <text>, the <tspan> is not strictly necessary. But the text sub elements are strange. The text has been placed with a "translate" when <text> has its own placement mechanism (x= y=). The passing of the font weight etc, I think is technically correct - but it would more usually be done in a style element.

For what its worth, I'm translating the above to:
 
Quote
<text x="40.8866" y="6.4989" class="heading">
<tspan>Down in Yon Forest</tspan>
</text>
So using the standard placement mechanism, and taking all the decoration information into a class (which is defined in the CSS).

Lukily changing all this code, is just simple pattern matching, so should be able to automate it. Classes also make it easy to change fonts etc, there is just one line in the style that needs changing - and it will change *all* times its used in the page (which is many ...)
Title: Re: EasyABC - exporting as SVG - fonts used
Post by: Stiamh on April 03, 2020, 01:48:55 PM
I guess another thing one learns from this, is how ugly most of these programs svg output is.

E.g. abcm2ps
Quote
<text style="font:16px serif"
x="216.60" y="50.80" text-anchor="middle">FINE</text>
</g>
Is missing the open group "<g>".

I can't find any examples of mismatched tags in my SVGs linked to earlier, generated by EasyABC using abcm2ps.

I don't know what you are using to inspect the innards of the files, but my text editor (Editpad Pro) highlights opening and closing tags (put the cursor on one and the other lights up) and traces the path between them with a vertical line in the left margin, making it very easy to detect any such errors. Sometimes the </g> is a long way from the <g> and what comes in between is not indented, though.

@Mike: you are obviously a total perfectionist. I too am learning heaps through this thread but given the scope of the current project (and the fact that it has been pending for nearly three years now), and despite your assurances that the apparently overcomplicated process you have developed can be simplified  (:), I am going to live with the imperfect but passable output of EasyABC/abcm2ps for the time being, with gratitude to everyone for the improvements I have been able to make so far, and the instructive discussion. But I am saving your posts and method for possible future reference.  :|glug

PS In case this is news to anyone, Jef Moine has released abc2svg (https://www.npmjs.com/package/abc2svg)... in case anyone wants to explore it and report back!
SimplePortal 2.3.5 © 2008-2012, SimplePortal