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.
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:
_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
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.