font_maker.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # TODO:
  2. # Look into using: https://github.com/adobe-fonts/adobe-blank
  3. # It should both reduce the size of the font and support all possible UTF8 chars
  4. import fontforge
  5. def generate(name, block):
  6. print("Generating " + name)
  7. # TODO:
  8. # This needs to reach 0x9FCF to complete the CJK Ideographs
  9. # But above around 0x7f00, we get this error:
  10. # `Internal Error: Attempt to output 81854 into a 16-bit field. It will be
  11. # truncated and the file may not be useful.`
  12. for i in range(0x0000, 0x7F00):
  13. if i == codepoint: continue
  14. glyph = blocks.createChar(i)
  15. glyph.width = 600
  16. glyph.addReference(block)
  17. print(blocks[codepoint].foreground)
  18. blocks.fontname = name
  19. blocks.fullname = name
  20. blocks.familyname = name
  21. # Fontforge's WOFF output doesn't seem to work. No matter, this isn't for an actual
  22. # remote production website. The font is served locally from the extension and doesn't
  23. # even need to look good.
  24. blocks.generate(name + '.ttf')
  25. # A font with just the █ (0x2588) for all unicode characters
  26. blocks = fontforge.font()
  27. blocks.encoding = 'UnicodeFull'
  28. codepoint = 0x2588
  29. glyph = blocks.createChar(codepoint)
  30. glyph.width = 600
  31. pen = blocks[codepoint].glyphPen()
  32. pen.moveTo((0, -200))
  33. pen.lineTo((0, 800))
  34. pen.lineTo((600, 800))
  35. pen.lineTo((600, -200))
  36. pen.closePath()
  37. generate('BlockCharMono', blocks[codepoint].glyphname)
  38. # A font with just the space character, used to hide all text
  39. blocks = fontforge.font()
  40. blocks.encoding = 'UnicodeFull'
  41. codepoint = 0x2003
  42. glyph = blocks.createChar(codepoint)
  43. glyph.width = 600
  44. pen = blocks[codepoint].glyphPen()
  45. pen.moveTo((0, 0))
  46. pen.lineTo((0, 0))
  47. pen.closePath()
  48. generate('BlankMono', blocks[codepoint].glyphname)