-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip - update emoji tooling to support tr51 sequences
- Loading branch information
Showing
6 changed files
with
306 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# delete dst, then: | ||
# copy the placeholders to dst | ||
# then copy the noto images to dst | ||
# then copy the draft images to dst, skipping names with parens and | ||
# after fixing the case of the names | ||
|
||
import glob | ||
import os | ||
from os import path | ||
import re | ||
import shutil | ||
|
||
DST = "/tmp/placeholder_emoji_plus" | ||
|
||
SRC_PLACEHOLDER = "/tmp/placeholder_emoji" | ||
SRC_NOTO = "/usr/local/google/users/dougfelt/newnoto/noto-emoji/png/128" | ||
SRC_DRAFT = "/usr/local/google/home/dougfelt/Downloads/PNG_latest_working_draft" | ||
|
||
# First, scan the draft images and select which ones to use. This does | ||
# two things: | ||
# - The download package returns all the images, including previous versions. | ||
# Ensure we use the one with the highest version. | ||
# - The names often mix case. Make sure we have all lower case names. | ||
# | ||
# If something seems amiss, we fail. | ||
|
||
UPDATED_NAMES = {} | ||
FIXED_NAMES = {} | ||
VAR_PAT = re.compile(r'(.*?)\((\d+)\)\.png') | ||
for fname in glob.glob(path.join(SRC_DRAFT, '*.png')): | ||
name = path.basename(fname) | ||
m = VAR_PAT.match(name) | ||
if m: | ||
name = '%s.png' % m.group(1).lower() | ||
version = int(m.group(2)) | ||
if version > UPDATED_NAMES.get(name, (0, None))[0]: | ||
print 'update %s to version %d' % (name, version) | ||
UPDATED_NAMES[name] = (version, fname) | ||
else: | ||
name = name.lower() | ||
FIXED_NAMES[name] = fname | ||
|
||
for name in UPDATED_NAMES: | ||
if name not in FIXED_NAMES: | ||
raise Exception('updated name %s not in names' % name) | ||
fname = UPDATED_NAMES[name][1] | ||
print 'using updated image %s for %s' % (fname, name) | ||
FIXED_NAMES[name] = fname | ||
|
||
# Now, recreate the destination directory and copy the data into it. | ||
|
||
if path.isdir(DST): | ||
shutil.rmtree(DST) | ||
os.makedirs(DST) | ||
|
||
SKIP_PLACEHOLDERS = frozenset([ | ||
'emoji_u1f468_200d_1f469_200d_1f466.png', | ||
'emoji_u1f469_200d_2764_fe0f_200d_1f468.png', | ||
'emoji_u1f469_200d_2764_fe0f_200d_1f48b_200d_1f468.png', | ||
]) | ||
|
||
for fname in glob.glob(path.join(SRC_PLACEHOLDER, '*.png')): | ||
basename = path.basename(fname) | ||
if basename in SKIP_PLACEHOLDERS: | ||
print 'skip %s' % basename | ||
continue | ||
shutil.copy(fname, DST) | ||
|
||
for fname in glob.glob(path.join(SRC_NOTO, '*.png')): | ||
shutil.copy(fname, DST) | ||
|
||
for name, fname in FIXED_NAMES.iteritems(): | ||
shutil.copy(fname, path.join(DST, name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import os | ||
from os import path | ||
import subprocess | ||
|
||
OUTPUT_DIR = '/tmp/placeholder_emoji' | ||
|
||
def generate_image(name, text): | ||
print name, text.replace('\n', '_') | ||
subprocess.check_call( | ||
['convert', '-size', '100x100', 'label:%s' % text, | ||
'%s/%s' % (OUTPUT_DIR, name)]) | ||
|
||
def is_color_patch(cp): | ||
return cp >= 0x1f3fb and cp <= 0x1f3ff | ||
|
||
def has_color_patch(values): | ||
for v in values: | ||
if is_color_patch(v): | ||
return True | ||
return False | ||
|
||
def regional_to_ascii(cp): | ||
return unichr(ord('A') + cp - 0x1f1e6) | ||
|
||
def is_flag_sequence(values): | ||
if len(values) != 2: | ||
return False | ||
for v in values: | ||
v -= 0x1f1e6 | ||
if v < 0 or v > 25: | ||
return False | ||
return True | ||
|
||
def is_keycap_sequence(values): | ||
return len(values) == 2 and values[1] == 0x20e3 | ||
|
||
def get_keycap_text(values): | ||
return '-%c-' % unichr(values[0]) # convert gags on '[' | ||
|
||
char_map = { | ||
0x1f468: 'M', | ||
0x1f469: 'W', | ||
0x1f466: 'B', | ||
0x1f467: 'G', | ||
0x2764: 'H', # heavy black heart, no var sel | ||
0x1f48b: 'K', # kiss mark | ||
0x200D: '-', # zwj placeholder | ||
0xfe0f: '-', # variation selector placeholder | ||
0x1f441: 'I', # Eye | ||
0x1f5e8: 'W', # 'witness' (left speech bubble) | ||
} | ||
|
||
def get_combining_text(values): | ||
chars = [] | ||
for v in values: | ||
char = char_map.get(v, None) | ||
if not char: | ||
return None | ||
if char != '-': | ||
chars.append(char) | ||
return ''.join(chars) | ||
|
||
|
||
if not path.isdir(OUTPUT_DIR): | ||
os.makedirs(OUTPUT_DIR) | ||
|
||
with open('sequences.txt', 'r') as f: | ||
for seq in f: | ||
seq = seq.strip() | ||
text = None | ||
values = [int(code, 16) for code in seq.split('_')] | ||
if len(values) == 1: | ||
val = values[0] | ||
text = '%04X' % val # ensure upper case format | ||
elif is_flag_sequence(values): | ||
text = ''.join(regional_to_ascii(cp) for cp in values) | ||
elif has_color_patch(values): | ||
print 'skipping color patch sequence %s' % seq | ||
elif is_keycap_sequence(values): | ||
text = get_keycap_text(values) | ||
else: | ||
text = get_combining_text(values) | ||
if not text: | ||
print 'missing %s' % seq | ||
|
||
if text: | ||
if len(text) > 3: | ||
if len(text) == 4: | ||
hi = text[:2] | ||
lo = text[2:] | ||
else: | ||
hi = text[:-3] | ||
lo = text[-3:] | ||
text = '%s\n%s' % (hi, lo) | ||
generate_image('emoji_u%s.png' % seq, text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.