mirror of
https://github.com/zulip/zulip.git
synced 2025-11-07 07:23:22 +00:00
Annotate tools/setup/emoji_dump/emoji_dump.py.
This commit is contained in:
@@ -7,7 +7,8 @@ import subprocess
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from six import unichr
|
from six import unichr, text_type
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ class MissingGlyphError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
def color_font(code_point, code_point_to_fname_map):
|
def color_font(code_point, code_point_to_fname_map):
|
||||||
|
# type: (str, Dict[int, Union[text_type, bytes]]) -> None
|
||||||
name = code_point_to_fname_map[int(code_point, 16)]
|
name = code_point_to_fname_map[int(code_point, 16)]
|
||||||
|
|
||||||
in_name = 'bitmaps/strike0/{}.png'.format(name)
|
in_name = 'bitmaps/strike0/{}.png'.format(name)
|
||||||
@@ -42,6 +44,7 @@ def color_font(code_point, code_point_to_fname_map):
|
|||||||
|
|
||||||
|
|
||||||
def bw_font(name, code_point):
|
def bw_font(name, code_point):
|
||||||
|
# type: (str, str) -> None
|
||||||
char = unichr(int(code_point, 16))
|
char = unichr(int(code_point, 16))
|
||||||
|
|
||||||
# AndroidEmoji.ttf is from
|
# AndroidEmoji.ttf is from
|
||||||
@@ -59,10 +62,11 @@ def bw_font(name, code_point):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def code_point_to_file_name_map(ttx):
|
def code_point_to_file_name_map(ttx):
|
||||||
|
# type: (str) -> Dict[int, Union[text_type, bytes]]
|
||||||
"""Given the NotoColorEmoji.ttx file, parse it to generate a map from
|
"""Given the NotoColorEmoji.ttx file, parse it to generate a map from
|
||||||
codepoint to filename (a la glyph0****.png)
|
codepoint to filename (a la glyph0****.png)
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {} # type: Dict[int, Union[text_type, bytes]]
|
||||||
xml = ET.parse(ttx)
|
xml = ET.parse(ttx)
|
||||||
for elem in xml.find("*cmap_format_12"): # type: ignore # https://github.com/python/typeshed/pull/254
|
for elem in xml.find("*cmap_format_12"): # type: ignore # https://github.com/python/typeshed/pull/254
|
||||||
code_point = int(elem.attrib["code"], 16)
|
code_point = int(elem.attrib["code"], 16)
|
||||||
@@ -72,6 +76,7 @@ def code_point_to_file_name_map(ttx):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# type: () -> None
|
||||||
# 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/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user