Home Forums Nazca OCR B font

Tagged: 

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #5670
    paul
    Member

    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 the nd.Font(fontfile='font.nst') command. Any idea of how I could generate such a font file for OCR-B?

    Thanks,

    Paul

    #5675
    Xaveer
    Moderator

    Dear 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

     

    #5679
    Xaveer
    Moderator

    Dear 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

     

    #5681
    paul
    Member

    Dear Xaveer,

    Thank you very much!

    Paul

    #6731
    lorenzo_btbw
    Participant

    Dear 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

    #6732
    lorenzo_btbw
    Participant

    Update: I made the nft file with a python script.

    Thanks

    • This reply was modified 2 years, 9 months ago by lorenzo_btbw.
    #6734
    Xaveer
    Moderator

    Dear 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

    #6735
    lorenzo_btbw
    Participant

    Dear 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

    #6736
    Xaveer
    Moderator

    Dear 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

     

    #6737
    lorenzo_btbw
    Participant

    I 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.
    #6743
    Xaveer
    Moderator

    Dear 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

    #6744
    lorenzo_btbw
    Participant

    Dear 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

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.