Could someone knowledgeable be so kind and give a step by step tutorial with precise syntax on how to use the R. Piechaud Python script to create a json file for metadata for a smufl font?
I tried all kind of things but failed miserably because I do not know the basics to deal with Python scripts.
I just know that one need FontForge, the Piechaud script and a Smufl font.
But how to run the script and how to use and connect these three parts is absolutely not clear to me.
In the long run I would like to be able to convert several music fonts I own to into smufl fonts.
I have read quite a lot of threads on this and I am aware that it is quite a lot of work, but well I want to begin and the first thing I would like to do is to be able to create the necessary json file.
@ MarcLarcher
I am glad that you are interested too!
Searching further I had a look to the script in PSPad (a text editor).
Among other things I could read this:
The script must be invoked from within the fontâs directory
I then did this:
Put a .ttf file (the smufl font) and the python script in the same directory
Right click on the script, choose the option âOpen withâ, search for the program âFontForgeBuilds/bin/fontforge.exeâ and then press OK
Something happened and the dos windows opened fast and closed as fast as it opened, I could not read what has been done and I do not know if something has been generated and if yes where it is.
Any help would be really welcome.
Edit:
I also did this:
Open FontForge and load the ttf file of the Smufl font
Choose âExecute Scriptâ in the File menu: a window (editor-like) opens
Copy the script in this editor-like window
Press OK
Nothing happens or if something happens I do not know what.
Not sure if anyone is interested in my groping around in the dark but maybe it can prevent someone as unknowledgeable as I am not to do this
Out of curiosity and to get some kind of âresultâ I simply made a copy of the existing json file from another smufl font.
I just renamed the file accordingly and also renamed the font in the declaration of the json file.
At least Dorico could open and recognised the new font and I was able to choose the new font in the âChange Fontsâ window.
Selecting the new font I unchecked the option âUse fontâs recommended engraving optionsâ because when the option is active I obtain strange results!
But with this option unchecked it seems as if Dorico is then able to use quite a lot of elements of the new font.
I could recognise that the design of keys, accidents, rests and so on had changed.
This is surely not the way smufl fonts have to be used but at least I could see some changes!
As written in the SMuFl specification (https://w3c.github.io/smufl/gitbook/specification/font-specific-metadata.html) only the âfontNameâ and the âfontVersionâ are mandatory for the metadata file.
Writing the following four lines in a text editor and saving them as âmyfont.jsonâ will work as a so to say default or empty metadata file for the font âmyfontâ. At least it will allow Dorico to recognize the font.
I now must learn to understand what all the Metadata do for the font and what is the difference between an empty json file and one with all metadata.
And I still was not able to run the R. Piechaud script.
BTW I now realized that the Bravura json file contains 32152 lines of code for the âglyphBBoxesâ metadata and as far as I understand these metadata are only for Finale and they are of no use for Dorico!
Considering that the whole Bravura json file has 43481 lines I find it quite amazing:
32152 lines for Finale and 11329 for Dorico!
For the sake of completeness I write down the last results.
Abraham Lee from Music Type Foundry https://www.musictypefoundry.com/ was so kind to help me.
He gave me a comprehensive step by step explanation on how to use the Robert Piechaud script.
Before I write the steps down here are the necessary things you must do before you can run the script.
. Create your own SMuFl font or find a SMuFl font that does not have a json file.
Here are the steps:
After you created your font save the FontForge SFD file, preferably with a name that does not have any spaces in it.
If you have an existing SMuFL font, load it first in FontForge and proceed as described above.
Put Robertâs script in the same directory as the SFD font file because that makes the command line stuff a little easier. Edit: create also a folder named âjsonâ in this directory!
Open up a command prompt and navigate to the directory that contains the SFD file (Iâll call it myfont.sfd below, but you use whatever name you want to call the SFD file) and Robertâs script, then execute the following command:
This runs a specially compiled version of Python that has access to FontForgeâs functions, which executes Robertâs script, which requires you to specify the font file that it is creating the JSON file for. Once run, you should have two new files in the directory, one for SMuFL called âmyfont_metadata.jsonâ and another for LilyPond called âmyfont_data.lyâ (which is unnecessary for what weâre doing, so you can discard it). You will need to rename the JSON file to be just myfont.json since the SMuFL spec recently changed for how the file should be named.
Edit: Have a look at the created json file and take care that the first three lines are written correctly!
They should be:
{
âfontNameâ: âmyfontâ,
âfontVersionâ: 1.0,
_4. Now, generate the font binary by going to File > Generate Fonts then choosing the âOpenType (CFF)â output type, setting the name to âmyfont.otfâ and hitting âGenerateâ
Install the font like normal in C:\Windows\Fonts and put the JSON file in C:\Program Files\Common Files\SMuFL\Fonts\Fonts\myfont.
I am glad to now know how one has to proceed.
(Edit: the following problem has now be solved, see the next two posts)
Following these steps I was able to run the script, unfortunately on my system I encounter some problem running the script.
I get the following IO error:
Traceback (most recent call last):
File âgenerate_font_metadata.pyâ, line 70, in
log = open( outDir+fontName.lower()+â.logâ, âw+â )
IOError: [Errno 2] No such file or directory: âjson/myfont.logâ
As I know nothing about Python I am not able to solve this on my own.
I suspect either there is something one should change in the script (for example I do not know what this sentence from Abraham Lee means when he writes: â⌠which executes Robertâs script, which requires you to specify the font file that it is creating the JSON file for.â
It can also be that this is a problem with the right paths or possibly also a folder-rights thing.
I will search further but for the moment who knows, maybe these informations may already help someone else.
Edit 1: I added two necessary apostrophs in the code line for the command prompt! Edit 2: Thanks to Paul the problem mentioned above has been solved, it is necessary to also create a folder named âjsonâ within the directory where the script and the sfd file are! Edit 3: I added a correction in step 3, it can be necessary that the first three lines of the json file have to be corrected._
This looks to be a problem with the path. It canât find the output directory called âjsonâ. This suggests to me that either you need to set the absolute path, and if you are on Windows then you canât use the backslash in paths directly, you need to use the ârawâ string format, so set it as râc:\path\to\jsonâ (note the ârâ prefix). The other related possibility is that you have to run the script from a specific directory. Lastly, ensure that the âjsonâ directory actually exists.
Thanks a lot Paul for your contribution.
Something is working now and at least the script creates now a json file.
I only had to create indeed the folder âjsonâ!
In the script the code line 52 says:
outDir = âjson/â;
I had no folder with this name.
I created this âjsonâ folder within the folder where the script and the sfd are and now it works
Now I get a json file in this folder.
I edit my previous post accordingly.
But unfortunately now Dorico does not accept this file and I get the following error from Dorico:
Error opening file: invalid file format
C:/Program Files/Common Files/SMuFL/Fonts/myfont/myfont.json
One problem is solved and the next one is already here
Edit
It works now
I had a look at the created json file and for some reason the mandatory three lines that I mentioned in post 5 of this thread were not written correctly!
After correcting these three lines everything is working as it should.
I will then add this to the step by step explanation.