Update Emoji set.

This commit is contained in:
James Porter 2016-06-03 15:03:39 -04:00 committed by Tim Abbott
parent cf93c8bce0
commit d008d96597
4 changed files with 23 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@ -5,21 +5,23 @@ import shutil
import subprocess import subprocess
import json import json
import sys import sys
import xml.etree.ElementTree as ET
from six import unichr from six import unichr
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
class MissingGlyphError(Exception): class MissingGlyphError(Exception):
pass pass
def color_font(name, code_point): def color_font(code_point, code_point_to_fname_map):
in_name = 'bitmaps/strike1/uni{}.png'.format(code_point) in_name = 'bitmaps/strike0/{}.png'.format(code_point_to_fname_map[int(code_point, 16)])
out_name = 'out/unicode/{}.png'.format(code_point) out_name = 'out/unicode/{}.png'.format(code_point)
try: try:
shutil.copyfile(in_name, out_name) shutil.copyfile(in_name, out_name)
except IOError: except IOError:
raise MissingGlyphError('name: %r code_point: %r' % (name, code_point)) raise MissingGlyphError('code_point: %r' % (code_point))
def bw_font(name, code_point): def bw_font(name, code_point):
@ -37,13 +39,26 @@ def bw_font(name, code_point):
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
draw.text((0, 0), char, font=font, fill='black') draw.text((0, 0), char, font=font, fill='black')
image.resize(SIZE, Image.ANTIALIAS).save('out/unicode/{}.png'.format(code_point), 'PNG') image.resize(SIZE, Image.ANTIALIAS).save('out/unicode/{}.png'.format(code_point), 'PNG')
def code_point_to_file_name_map(ttx):
"""Given the NotoColorEmoji.ttx file, parse it to generate a map from
codepoint to filename (a la glyph0****.png)
"""
result = {}
xml = ET.parse(ttx)
for elem in xml.find("*cmap_format_12"): # type: ignore # https://github.com/python/typeshed/pull/254
code_point = int(elem.attrib["code"], 16)
fname = elem.attrib["name"]
result[code_point] = fname
return result
# ttx is in the fonttools pacakge, the -z option is only on master # ttx is in the fonttools pacakge, the -z option is only on master
# https://github.com/behdad/fonttools/ # https://github.com/behdad/fonttools/
# NotoColorEmoji.tff is from # NotoColorEmoji.tff is from
# https://android.googlesource.com/platform/external/noto-fonts/+/kitkat-release/NotoColorEmoji.ttf # https://android.googlesource.com/platform/external/noto-fonts/+/marshmallow-release/other/NotoColorEmoji.ttf
# note that you have to run it though base64 -D before being able
# to use it, since it downloads from that page base64 encoded
subprocess.call('ttx -v -z extfile NotoColorEmoji.ttf', shell=True) subprocess.call('ttx -v -z extfile NotoColorEmoji.ttf', shell=True)
try: try:
@ -61,9 +76,10 @@ emoji_map['blue_car'] = emoji_map['red_car']
emoji_map['red_car'] = emoji_map['oncoming_automobile'] emoji_map['red_car'] = emoji_map['oncoming_automobile']
failed = False failed = False
code_point_to_fname_map = code_point_to_file_name_map("NotoColorEmoji.ttx")
for name, code_point in emoji_map.items(): for name, code_point in emoji_map.items():
try: try:
color_font(name, code_point) color_font(code_point, code_point_to_fname_map)
except MissingGlyphError: except MissingGlyphError:
try: try:
bw_font(name, code_point) bw_font(name, code_point)

File diff suppressed because one or more lines are too long