0

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?

Adrian Seidel
  • 23
  • 1
  • 6
  • Maybe `fontforge.loadNamelist('glyphlist.txt')` could help with [glyphlist.txt](https://git.itextsupport.com/projects/I5J/repos/itextpdf/browse/openpdf/src/main/java/com/lowagie/text/pdf/fonts/glyphlist.txt?at=a0a1518b92bf02095697ee58fc6469cdd80e841c) – JosefZ Dec 22 '20 at 17:03
  • can you explain a bit more please? what should I put into the file – Adrian Seidel Dec 23 '20 at 07:26
  • Take a look here: [Import a sequence of .svg files into FontForge as glyphs and output a font file](https://stackoverflow.com/q/22124130/3439404). – JosefZ Dec 23 '20 at 10:22
  • Okay, I downloaded the glyph list.txt and did fontforge.loadNamelist("glyphlist.txt") but still same error – Adrian Seidel Dec 23 '20 at 11:18
  • hey? what can I do? – Adrian Seidel Dec 23 '20 at 17:19
  • [`font.createMappedChar(name)`](https://fontforge.org/docs/scripting/python/fontforge.html) and `name` for `U+263A` is defined in `glyphlist.txt` as _smileface_ (imho) so I'd use `font.createMappedChar('smileface')` – JosefZ Dec 23 '20 at 20:45
  • same error . ValueError: Glyph name, smileface, not in current encoding – Adrian Seidel Dec 24 '20 at 09:05

1 Answers1

0

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"

tolson
  • 1
  • 1