Wednesday, 19 October 2022

How to add a char to a font with fontforge module and python from a svg file

here is my code :

import fontforge
font = fontforge.open('firacode.ttf')
shield = font.createChar(128737)
shield.importOutlines('shield.svg')
font.addLookup('shield', 'gsub_single', (), (('liga', (('DFLT', ('dflt')),)),))
font.addLookupSubtable('shield', 'shield')
font[128737].addPosSub('shield', "128737")
#font[128737] = shield
font.fullname = 'FiraCodeEmojii'
font.familyname = 'FiraCode'
font.fontname = 'FiraCodeEmojii'
font.uniqueid = 123456789
font.xuid = '123456789'
font.appendSFNTName('English (US)', 'SubFamily', "FiraCodeEmojii SemiBold Italic")
font.appendSFNTName('English (US)', 'Fullname', "FiraCodeEmojii SemiBold Italic")
font.appendSFNTName('English (US)', 'Preferred Family', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Preferred Styles', "SemiBold Italic")
font.appendSFNTName('English (US)', 'Compatible Full', "FiraCodeEmojii SemiBold Italic")
font.appendSFNTName('English (US)', 'WWS Family', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'WWS Subfamily', "SemiBold Italic")
font.appendSFNTName('English (US)', 'Sample Text', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Trademark', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Manufacturer', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Designer', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Vendor URL', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Designer URL', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'License', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'License URL', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'UniqueID', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Preferred Family', "FiraCodeEmojii")
font.appendSFNTName('English (US)', 'Preferred Styles', "SemiBold Italic")
font.appendSFNTName('English (US)', 'Compatible Full', "FiraCodeEmojii SemiBold Italic")
font.reencode('unicode')
font.generate('testtfont.ttf')

Why can't i add the shielkd svg to the font ?

When i install the new ttf file it doesn't find the shield.

I try to re encode to utf8 i try to generate more data about the shield but nothing.

And how to add colored svg as character with color ?

The code and svg are available here : https://github.com/bussiere/testfiracode

Regards



from How to add a char to a font with fontforge module and python from a svg file

No comments:

Post a Comment