Melodeon.net Forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome to the new melodeon.net forum

Pages: 1 2 [3]   Go Down

Author Topic: EasyABC - exporting as SVG - fonts used  (Read 9996 times)

0 Members and 1 Guest are viewing this topic.

David Summers

  • Regular debater
  • ***
  • Offline Offline
  • Posts: 159
Re: EasyABC - exporting as SVG - fonts used
« Reply #40 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:



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>
Logged

Mike Hirst

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1433
  • Black Dot B/C, Bastardo C#/D, Corona II GCF
Re: EasyABC - exporting as SVG - fonts used
« Reply #41 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.  (:)
Logged
Semper idem, sed non eodem modo

David Summers

  • Regular debater
  • ***
  • Offline Offline
  • Posts: 159
Re: EasyABC - exporting as SVG - fonts used
« Reply #42 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 ...
« Last Edit: April 03, 2020, 09:38:16 AM by David Summers »
Logged

Mike Hirst

  • Hero Member
  • *****
  • Offline Offline
  • Posts: 1433
  • Black Dot B/C, Bastardo C#/D, Corona II GCF
Re: EasyABC - exporting as SVG - fonts used
« Reply #43 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. If we now convert the MusicXML output to svg using verovio, 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.

  • abc source: abc.txt
  • abc ->MusicXML: MusicXML.txt
  • MusicXML->SVG: svg.txt
  • css styling for svg: css.txt

N.B. file extensions have been unified to .txt to enable usage as forum attachments.
« Last Edit: April 03, 2020, 12:07:25 AM by Mike Hirst »
Logged
Semper idem, sed non eodem modo

David Summers

  • Regular debater
  • ***
  • Offline Offline
  • Posts: 159
Re: EasyABC - exporting as SVG - fonts used
« Reply #44 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 ...)
« Last Edit: April 03, 2020, 09:32:17 AM by David Summers »
Logged

Stiamh

  • Old grey C#/D pest
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 3611
    • Packie Manus Byrne
Re: EasyABC - exporting as SVG - fonts used
« Reply #45 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... in case anyone wants to explore it and report back!
Pages: 1 2 [3]   Go Up
 


Melodeon.net - (c) Theo Gibb; Clive Williams 2010. The access and use of this website and forum featuring these terms and conditions constitutes your acceptance of these terms and conditions.
SimplePortal 2.3.5 © 2008-2012, SimplePortal