'Python fontforge Emoji encoding and colored glyphs
I want to create a .ttf font with python and fontforge which also contains emojis.
my glyphs are .svg files which have a resolution of 512x512 pixels.
I already tried the Following:
import fontforge
blank = fontforge.font()
blank.save("blank.sfd")
font = fontforge.open("blank.sfd")
glyph = font.createMappedChar("\U0000263A")
glyph.importOutlines("263A.svg")
font.generate("font.ttf")
However, I get the following error:
Traceback (most recent call last):
File "/home/adrian/dev/font/glyphs/test.py", line 5, in <module>
glyph = font.createMappedChar("\U0000263A")
ValueError: Glyph name, ☺️, not in current encoding
I looked into thebblank.sfd and there is a line: "Encoding: ISO8859-1". I tried to replace the " ISO8859-1" with "UTF-8" or "Univode" but then I get the following error:
Internal Error: SFD file specifies too few slots for its encoding.
How can I solve that?
I tried to use the emoji glyph for letter "A" for first. then font get created and it works. However, it is just a black circle and face, eyes, smile, blush,... aren't recognizable because it is black instead of Yellow, orange, white, pink,... In the blank.sfd file is something written about layers:
Layer: 0 0 "Back" 1
Layer: 1 0 "Fore" 0
I guess that I have to change something with the layers to make the colors to take effect but I am not sure and if that's the case I don't know how and how I can assign the layers with elements in the. svg glyph. I use the program Inkscape to create the glyps, by the way.
How can I solve these 2 things?
Solution 1:[1]
I have stumbled across this wanting a simple character added to my terminal, here's a mix on the question that solves it for me.
For making your own Emoji, you might find this rather difficult with Font Forge in its current state. Just try loading a font like NotoColorEmoji.ttf into FontForge's app and you'll see an error. There is a github issue for it:
https://github.com/fontforge/fontforge/issues/677 https://github.com/fontforge/fontforge/issues/2044
But if the emoji you're trying to make is a single color glyphs like: https://github.com/powerline/powerline, you're in luck.
This script is close to yours but works well:
import fontforge
blank = fontforge.font()
blank.encoding = "UnicodeBMP"
glyph = blank.createChar(int("F10F", 16))
glyph.importOutlines("logo.svg")
blank.generate("myfont.ttf")
Feel free to change the unicode to any sequence in the private use area.
Then copy it to your font directory (if linux)
sudo cp myfont.ttf /usr/share/fonts/TTF/
In a new terminal or reloading display you can: echo -e "\uf10f"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | tolson |