Tagged: font
- This topic has 11 replies, 3 voices, and was last updated 2 years, 9 months ago by lorenzo_btbw.
-
AuthorPosts
-
2 October 2019 at 13:07 #5670paulMember
Hello
Is there a way to use the OCR-B font with nazca?
I had a look at the tutorial and it looks like the font is not available (nazca 0.5.1).
From looking at the code it seems to me that the current fonts are loaded from a ‘font.nst’ file with thend.Font(fontfile='font.nst')
command. Any idea of how I could generate such a font file for OCR-B?Thanks,
Paul
3 October 2019 at 23:15 #5675XaveerModeratorDear Paul,
Currently there is no OCR-B font for Nazca. Indeed they are loaded from a ‘font.nft’ file. I’ll look into providing this font and inform you when it’s available. The nft file itself is a (pickled) set of polygons and size+spacing info, that is a Nazca-specific format. You can (of course) generate it yourself, but the details are not documented yet.
Xaveer
5 October 2019 at 18:47 #5679XaveerModeratorDear Paul,
The OCR-B font will be available in the next Nazca release.
Nazca font files have the following structure:
- version: font file version number
- height: total height of the font
- space: interword spacing (=0 for fixed fonts)
- font: dictionary of characters:
- key: character
- w: width of that character
- p: list of polygons, of which each is a list of (x,y) coordinate points
Xaveer
7 October 2019 at 10:25 #5681paulMemberDear Xaveer,
Thank you very much!
Paul
7 March 2022 at 17:56 #6731lorenzo_btbwParticipantDear Xaveer,
Can you please explain how to generate a font.nft file with custom font style, please?
I already have the list of polygons (p) with the coordinate points
Thank you
Kind Regards,
Lorenzo
8 March 2022 at 12:06 #6732lorenzo_btbwParticipantUpdate: I made the nft file with a python script.
Thanks
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
8 March 2022 at 13:58 #6734XaveerModeratorDear Lorenzo,
Great. I was working on documentation, but reverse engineering should indeed not be too difficult. Glad you found a way to do it.
Xaveer
8 March 2022 at 15:17 #6735lorenzo_btbwParticipantDear Xaveer,
I have an issue though, the characters don’t match when I use nd.text().
Does the font dictionary entries need to be in the same order as yours? If I open the dictionary, it automatically shows me the content ordered with the keys, therefore all font dictionaries are with same order, but if I write something the text is wrong.
Thanks
8 March 2022 at 15:52 #6736XaveerModeratorDear Lorenzo,
The order should not matter. It is a dictionaly lookup. You use a different font by specifying something like my_font = nd.Font(‘my_font_file’) and then my_font.text() should write the proper text. my_font_file.nft can be in your current directory, or you can specify the full path to the font file.
You can get a sample of all characters in a font with my_font.sample(height=50).put() or a string with all characters in your font via my_font.characters()
Hope that helps.
Xaveer
8 March 2022 at 16:17 #6737lorenzo_btbwParticipantI did that but the text doens’t match. is it possible a problem of pickle writing?
I used this code:
with open(font_filename+’.nft’, ‘wb’) as handle:
pickle.dump(nft_tuple, handle, protocol=pickle.HIGHEST_PROTOCOL)
being nft_tuple my structure
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
- This reply was modified 2 years, 9 months ago by lorenzo_btbw.
8 March 2022 at 16:35 #6743XaveerModeratorDear Lorenzo,
The pickle command should be:
pickle.dump((version, height, inter_character_space, font), fontfile)
where version can be anything, height is the font height, measured from lowest (e.g. “j”) to highest (e.g. “A”), inter_character_space is just that, font is the dictionary with the (any) character as key and a list of polygons (x,y tuples) as value. Fontfile is the name of the .nft file to write.
Xaveer
8 March 2022 at 18:31 #6744lorenzo_btbwParticipantDear Xaveer,
after a long debugging session I found it was an if loop causing the reshuffling of the alphabet dictionary. Now it’s all sorted and it works as it should.
Thank you so much
Cheers,
Lorenzo
-
AuthorPosts
- You must be logged in to reply to this topic.