From a9b8e7f8e038fd5f2a6c2d725db7d20ec89ef2b7 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Fri, 29 Jan 2016 14:38:07 -0800 Subject: [PATCH 1/6] Add tool that generates an html file comparing emoji images. This uses nototools to get unicode names. It relies on new api in nototools.unicode_data to get data/names of proposed emoji that are not currently approved and so not in the standard data files. --- generate_emoji_html.py | 318 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 318 insertions(+) create mode 100755 generate_emoji_html.py diff --git a/generate_emoji_html.py b/generate_emoji_html.py new file mode 100755 index 000000000..5cbd82f60 --- /dev/null +++ b/generate_emoji_html.py @@ -0,0 +1,318 @@ +#!/usr/bin/python +# +# Copyright 2016 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Build an html page showing emoji images. + +This takes a list of directories containing emoji image files, and +builds an html page presenting the images along with their composition +(for sequences) and unicode names (for individual emoji).""" + +import argparse +import codecs +import collections +import glob +from os import path +import re +import sys +from nototools import unicode_data + +_default_dir = 'png/128' +_default_ext = 'png' +_default_prefix = 'emoji_u' +_default_title = 'Emoji List' + +# DirInfo represents information about a directory of file names. +# - directory is the directory path +# - title is the title to use for this directory +# - filemap is a dict mapping from a tuple of codepoints to the name of +# a file in the directory. +DirInfo = collections.namedtuple('DirInfo', 'directory, title, filemap') + + +def _merge_keys(dicts): + """Return the union of the keys in the list of dicts.""" + keys = [] + for d in dicts: + keys.extend(d.keys()) + return frozenset(keys) + +def _generate_row_cells(key, dir_infos): + CELL_PREFIX = '' + def _cell(key, info): + if key in info.filemap: + return '' % path.join( + info.directory, info.filemap[key]) + return '-missing-' + return [CELL_PREFIX + _cell(key, info) for info in dir_infos] + + +def _get_desc(key_tuple, dir_infos): + CELL_PREFIX = '' + def _get_filepath(cp): + cp_key = tuple([cp]) + for info in dir_infos: + if cp_key in info.filemap: + return path.join(info.directory, info.filemap[cp_key]) + return None + + def _get_part(cp): + if cp == 0x200d: # zwj, common so replace with '+' + return '+' + if cp == 0xfe0f: # emoji variation selector, we ignore it + return None + fname = _get_filepath(cp) + if fname: + return '' % fname + return '%04X' % cp + + if len(key_tuple) == 1: + desc = 'U+%04X' % key_tuple + else: + desc = ' '.join(filter(None, [_get_part(cp) for cp in key_tuple])) + return CELL_PREFIX + desc + + +def _get_name(key_tuple): + CELL_PREFIX = '' + if len(key_tuple) != 1: + name = '' + else: + cp = key_tuple[0] + if cp in unicode_data.proposed_emoji_cps(): + name = '(proposed) ' + unicode_data.proposed_emoji_name(cp) + else: + name =unicode_data.name(cp, '(error)') + return CELL_PREFIX + name + + +def _generate_content(dir_infos): + """Generate an html table for the infos.""" + lines = [''] + header_row = [''] + header_row.extend([info.title for info in dir_infos]) + header_row.extend(['Description', 'Name']) + lines.append(''.join(lines) + '\n
'.join(header_row)) + + all_keys = _merge_keys([info.filemap for info in dir_infos]) + for key in sorted(all_keys): + row = [] + row.extend(_generate_row_cells(key, dir_infos)) + row.append(_get_desc(key, dir_infos)) + row.append(_get_name(key)) + lines.append(''.join(row)) + return '\n
' + + +""" +def _generate_content(files, prefix=_default_prefix): + key_to_filename = {} + for fname in files: + filename = path.basename(fname) + if not filename.startswith(prefix): + print >> sys.stderr, 'bad prefix for filename %s' % fname + continue + key_string = path.splitext(filename)[0] + key_string = key_string[len(prefix):] + try: + key_tuple = tuple(int(k, 16) for k in key_string.split('_')) + except: + print 'bad filename: "%s"' % key_string + key_to_filename[key_tuple] = fname + + lines = [""] + for key_tuple in sorted(key_to_filename): + if len(key_tuple) == 1: + key_string = 'U+%04X' % key_tuple + else: + key_string = ' + '.join( + '' % key_to_filename[tuple([key])] + for key in key_tuple + if tuple([key]) in key_to_filename) + name = _get_name(key_tuple) + lines.append('
' + '%s' + '%s' % ( + key_to_filename[key_tuple], key_string, name)) + return '\n '.join(lines) + '\n' +""" + +def _get_image_data(image_dir, ext, prefix): + """Return a map from a tuple of cp sequences to a filename. + + This filters by file extension, and expects the rest of the files + to match the prefix followed by a sequence of hex codepoints separated + by underscore. Files that don't match, duplicate sequences (because + of casing), and out_of_range or empty codepoints raise an error.""" + + fails = [] + result = {} + expect_re = re.compile(r'%s([0-9A-Fa-f_]+).%s' % (prefix, ext)) + for f in sorted(glob.glob(path.join(image_dir, '*.%s' % ext))): + filename = path.basename(f) + m = expect_re.match(filename) + if not m: + fails.add('did not match: ' + filename) + continue + seq = m.group(1) + try: + cps = tuple(int(s, 16) for s in seq.split('_')) + except: + fails.add('bad cp sequence: ' + filename) + continue + this_failed = False + for cp in cps: + if (cp > 0x10ffff): + fails.add('cp out of range: ' + filename) + this_failed = True + break + if this_failed: + continue + if cps in result: + fails.add('duplicate sequence: %s and %s' (result[cps], filename)) + continue + result[cps] = filename + if fails: + print >> sys.stderr, 'get_image_data failed (%s, %s, %s):\n %s' % ( + image_dir, ext, prefix, '\n '.join(fails)) + raise ValueError('get image data failed') + return result + + +def _get_dir_infos( + image_dirs, exts=None, prefixes=None, titles=None, + default_ext=_default_ext, default_prefix=_default_prefix): + """Return a list of DirInfos for the image_dirs. When defined, + exts, prefixes, and titles should be the same length as image_dirs. + Titles default to using the last segments of the image_dirs, + exts and prefixes default to the corresponding default values.""" + + count = len(image_dirs) + if not titles: + titles = [None] * count + elif len(titles) != count: + raise ValueError('have %d image dirs but %d titles' % ( + count, len(titles))) + if not exts: + exts = [default_ext] * count + elif len(exts) != count: + raise ValueError('have %d image dirs but %d extensions' % ( + count, len(exts))) + if not prefixes: + prefixes = [default_prefix] * count + elif len(prefixes) != count: + raise ValueError('have %d image dirs but %d prefixes' % ( + count, len(prefixes))) + + infos = [] + for i in range(count): + image_dir = image_dirs[i] + title = titles[i] or path.basename(path.normpath(image_dir)) + ext = exts[i] or default_ext + prefix = prefixes[i] or default_prefix + filemap = _get_image_data(image_dir, ext, prefix) + infos.append(DirInfo(image_dir, title, filemap)) + return infos + + +def _instantiate_template(template, arg_dict): + id_regex = re.compile('{{([a-zA-Z0-9_]+)}}') + ids = set(m.group(1) for m in id_regex.finditer(template)) + keyset = set(arg_dict.keys()) + missing_ids = ids - keyset + extra_args = keyset - ids + if extra_args: + print >> sys.stderr, ( + 'the following %d args are unused:\n%s' % + (len(extra_args), ', '.join(sorted(extra_args)))) + text = template + if missing_ids: + raise ValueError( + 'the following %d ids in the template have no args:\n%s' % + (len(missing_ids), ', '.join(sorted(missing_ids)))) + for arg in ids: + text = re.sub('{{%s}}' % arg, arg_dict[arg], text) + return text + + +TEMPLATE = """ + + + + {{title}} + + + + {{content}} + + +""" + +STYLE = """ + tbody { background-color: rgb(210, 210, 210) } + tbody img { width: 64px; height: 64px } + tbody .desc { font-size: 20pt; font-weight: bold } + tbody .desc img { vertical-align: middle; width: 32px; height: 32px } + tbody .name { background-color: white } +""" + +def write_html_page(filename, page_title, dir_infos): + content = _generate_content(dir_infos) + text = _instantiate_template( + TEMPLATE, {'title': page_title, 'style': STYLE, 'content': content}) + with codecs.open(filename, 'w', 'utf-8') as f: + f.write(text) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument( + 'filename', help='path to output file', metavar='filename') + parser.add_argument( + '--page_title', help='page title', metavar='title', default='Emoji Table') + parser.add_argument( + '-d', '--image_dirs', help='image directories', metavar='dir', + nargs='+') + parser.add_argument( + '-e', '--exts', help='file extension, one per image dir', metavar='ext', + nargs='*') + parser.add_argument( + '-p', '--prefixes', help='file name prefix, one per image dir', + metavar='prefix', nargs='*') + parser.add_argument( + '-t', '--titles', help='title, one per image dir', metavar='title', + nargs='*'), + parser.add_argument( + '-de', '--default_ext', help='default extension', metavar='ext', + default=_default_ext) + parser.add_argument( + '-dp', '--default_prefix', help='default prefix', metavar='prefix', + default=_default_prefix) + + args = parser.parse_args() + file_parts = path.splitext(args.filename) + if file_parts[1] != 'html': + args.filename = file_parts[0] + '.html' + print 'added .html extension to filename:\n%s' % args.filename + + dir_infos = _get_dir_infos( + args.image_dirs, args.exts, args.prefixes, args.titles, args.default_ext, + args.default_prefix) + + write_html_page(args.filename, args.page_title, dir_infos) + + +if __name__ == "__main__": + main() From 0b5cf8651b49d82d250822595302ce931eba843f Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Fri, 11 Mar 2016 15:16:54 -0800 Subject: [PATCH 2/6] Add IC svg and png resources from upstream (behdad/region_flags). --- third_party/region-flags/IC.png | Bin 0 -> 356 bytes third_party/region-flags/svg/IC.svg | 743 +--------------------------- 2 files changed, 5 insertions(+), 738 deletions(-) create mode 100644 third_party/region-flags/IC.png diff --git a/third_party/region-flags/IC.png b/third_party/region-flags/IC.png new file mode 100644 index 0000000000000000000000000000000000000000..cb5d9f2fe08897b7554c40b7508c29f941e032c7 GIT binary patch literal 356 zcmeAS@N?(olHy`uVBq!ia0y~yV2WU1V4T3j3>4vy{>BZYI0Jk_T-h^L{y)R;|NsAg z3l#SO1sRjP-CdZ{xNA~?Y)(%X$B>F!Z_gPrGB9v3FPOSziRRf2=b42jtX*ohH6wF` cfWH~CAHuGsTs|ZC3>ZQTp00i_>zopr08P1u)Bpeg literal 0 HcmV?d00001 diff --git a/third_party/region-flags/svg/IC.svg b/third_party/region-flags/svg/IC.svg index 96d6b1307..87f9e7480 100644 --- a/third_party/region-flags/svg/IC.svg +++ b/third_party/region-flags/svg/IC.svg @@ -1,739 +1,6 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + From 3a57df2ac61b58882c07d57c80f8bdb457863718 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Fri, 11 Mar 2016 19:02:15 -0800 Subject: [PATCH 3/6] Improve flag support. This adds some additional flags to the default set. In addition, it contains code that creates ligatures for some flag sequences to others, for a few cases where we want different regions to share the same flag. Finally, it adds default ligatures so that pairs of regional indicator characters for which there's no predefined glyph get a 'missing flag' glyph. This avoids cases where sequences of regional indicator sequences accidentally match at odd locations because of a previous mismatch. There is no actual 'missing flag' glyph yet. The code uses an existing emoji as a placeholder. --- Makefile | 8 ++-- third_party/color_emoji/add_glyphs.py | 57 ++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 64974a823..dc450eb53 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ QUANTIZED_DIR := $(BUILD_DIR)/quantized_pngs COMPRESSED_DIR := $(BUILD_DIR)/compressed_pngs LIMITED_FLAGS = CN DE ES FR GB IT JP KR RU US -SELECTED_FLAGS = AD AE AF AG AI AL AM AO AR AS AT AU AW AX AZ \ +SELECTED_FLAGS = AC AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ \ BA BB BD BE BF BG BH BI BJ BM BN BO BR BS BT BW BY BZ \ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ \ DE DJ DK DM DO DZ \ @@ -52,7 +52,7 @@ SELECTED_FLAGS = AD AE AF AG AI AL AM AO AR AS AT AU AW AX AZ \ FI FJ FM FO FR \ GA GB GD GE GG GH GI GL GM GN GQ GR GT GU GW GY \ HK HN HR HT HU \ - ID IE IL IM IN IO IQ IR IS IT \ + IC ID IE IL IM IN IO IQ IR IS IT \ JE JM JO JP \ KE KG KH KI KM KN KP KR KW KY KZ \ LA LB LC LI LK LR LS LT LU LV LY \ @@ -62,8 +62,8 @@ SELECTED_FLAGS = AD AE AF AG AI AL AM AO AR AS AT AU AW AX AZ \ PA PE PF PG PH PK PL PN PR PS PT PW PY \ QA \ RO RS RU RW \ - SA SB SC SD SE SG SI SK SL SM SN SO SR SS ST SV SX SY SZ \ - TC TD TG TH TJ TK TL TM TN TO TR TT TV TW TZ \ + SA SB SC SD SE SG SH SI SK SL SM SN SO SR SS ST SV SX SY SZ \ + TA TC TD TG TH TJ TK TL TM TN TO TR TT TV TW TZ \ UA UG US UY UZ \ VA VC VE VG VI VN VU \ WS \ diff --git a/third_party/color_emoji/add_glyphs.py b/third_party/color_emoji/add_glyphs.py index 0d78a7d2b..2cba6a809 100644 --- a/third_party/color_emoji/add_glyphs.py +++ b/third_party/color_emoji/add_glyphs.py @@ -1,10 +1,13 @@ #!/usr/bin/env python -import collections, glob, os, sys +import collections, glob, os, re, sys from fontTools import ttx from fontTools.ttLib.tables import otTables from png import PNG +# TODO: replace with actual name once we have a glyph. +MISSING_FLAG_GLYPH_NAME = "u2764" + sys.path.append( os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) import add_emoji_gsub @@ -78,6 +81,15 @@ EXTRA_SEQUENCES = { 'u1F48F': '1F469_200D_2764_FE0F_200D_1F48B_200D_1F468', # WHKM } +# Flag aliases - from: to +FLAG_ALIASES = { + 'BV': 'NO', + 'SJ': 'NO', + 'UM': 'FR', + 'HM': 'AU', + 'UM': 'US', +} + if len (sys.argv) < 4: print >>sys.stderr, """ Usage: @@ -180,6 +192,49 @@ for n in EXTRA_SEQUENCES: else: print 'extras: no glyph for %s' % n +# Add missing regional indicator sequences and flag aliases +# if we support any. +regional_names = frozenset('u%X' % cp for cp in range(0x1F1E6, 0x1F200)) + +def _is_flag_sequence(t): + return len(t) == 2 and t[0] in regional_names and t[1] in regional_names + +have_flags = False +for k in ligatures: + if _is_flag_sequence(k): + have_flags = True + break + +# sigh, too many separate files with the same code. +# copied from add_emoji_gsub. +def _reg_indicator(letter): + assert 'A' <= letter <= 'Z' + return 0x1F1E6 + ord(letter) - ord('A') + +def _reg_lig_sequence(flag_name): + """Returns a tuple of strings naming the codepoints that form the ligature.""" + assert len(flag_name) == 2 + return tuple('u%X' % _reg_indicator(cp) for cp in flag_name) + +def _reg_lig_name(flag_name): + """Returns a glyph name for the flag name.""" + return '_'.join(_reg_lig_sequence(flag_name)) + +if have_flags: + print 'Adding flag aliases.' + for flag_from, flag_to in FLAG_ALIASES.iteritems(): + seq = _reg_lig_sequence(flag_from) + name = _reg_lig_name(flag_to) + add_lig_sequence(ligatures, seq, name) + + print 'Adding unused flag sequences' + # every flag sequence we don't have gets the missing flag glyph + for first in regional_names: + for second in regional_names: + seq = (first, second) + if seq not in ligatures: + add_lig_sequence(ligatures, seq, MISSING_FLAG_GLYPH_NAME) + keyed_ligatures = collections.defaultdict(list) for k, v in ligatures.iteritems(): From 343e9ffbf4c121ec315d92cc76c33bd855ce3df2 Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Sun, 13 Mar 2016 14:56:02 -0700 Subject: [PATCH 4/6] Add 'unknown flag' glyph. This uses PUA character U+FE82B for the unknown flag during processing. Currently I don't yet remove this from the cmap when we're done. --- Makefile | 2 ++ png/128/emoji_ufe82b.png | Bin 0 -> 2251 bytes third_party/color_emoji/add_glyphs.py | 13 +++++++++---- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 png/128/emoji_ufe82b.png diff --git a/Makefile b/Makefile index dc450eb53..cbdd6ffa1 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,8 @@ RENAMED_FLAGS_DIR := $(BUILD_DIR)/renamed_flags QUANTIZED_DIR := $(BUILD_DIR)/quantized_pngs COMPRESSED_DIR := $(BUILD_DIR)/compressed_pngs +# Unknown flag is PUA fe82b + LIMITED_FLAGS = CN DE ES FR GB IT JP KR RU US SELECTED_FLAGS = AC AD AE AF AG AI AL AM AO AQ AR AS AT AU AW AX AZ \ BA BB BD BE BF BG BH BI BJ BM BN BO BR BS BT BW BY BZ \ diff --git a/png/128/emoji_ufe82b.png b/png/128/emoji_ufe82b.png new file mode 100644 index 0000000000000000000000000000000000000000..90ffa25e62de57b8efb368f7339fef73033c20d1 GIT binary patch literal 2251 zcmV;+2sHPJP)|IT48$}e}IBrCvs5Wg>RfuNI4NeK=S`>4k$GBHG#7N~ze1rpP3I|Szq~}U; z4{(h+(vu^4F3zbO?I0lpDRQDJp^2R^Z#^59WbO6L?9ZE-_es-D>cq~@_s#p6c{?+4 zdV1;*>_v{cfCNAw0T4(41QGy&1VA7G5Ntx8x&Q|{olccq7I?I&z9lFn;SMMW%+BBcGA8*B|G5ff z0cMcD$}SrcznX{uC<{oB_#(U1SzD5Pi!xaNeaVN>+g2doa|8T+NB|lUUt$fS_e}wR zpQ;t0EFd{^U*oM1=UcN(phN<|o!ZrSz*b1;W8P&VXi*S|i*zu}klM|s@R1;{mXQ{K zb!O1VLB|#&eg!%rY;vT{MoBxNzpu#uwlcpKQtqa0c5e&X3V{2^U z79>aEt+)i9Pl@m{H(hXbGwir|#|%JUuAvnGC%wYkl0%3a<+ub8s|(;h5`v*+;wW*v z9>?NPJ|^NTJpEZDUQ%@f^-Kl8NBk-gpP3uTMgTCy$v>Qk&(;E@9|JJ*YkbrfF!#=G zZ^CQ8{xewa*g2YT4o?1ieKvo}+TiQAUpwL7Yd0&ZTq%?nARZ$72G&vUll|-<=R9ZE z!xNF;p7j2`#su&V6T_|PLDR$yG!nM}+}Ag-jd~c-PhU`C?7#S`1<>ph;MW! z&-{8C09W$E-+Avd@68@#v<6_ETd`XJMm|LO%eE39hMQBT&KEb1u!%rvaVR$;(nm9! z2j)I&@&OQMeDlW?HVZJ%)AD!(z0GEK!4X6u%7dLERyF19wAy>zO zC;O8qEK+ccC<`Ev=c5EBD*%9)1QC`ve@YerB7PUE0KfuZvI1ZMc4D4;$ifZe0;Ye( zL5|xqass%<9)6KWth#3NRyyJarTnz_x88 zfBnx(^1WN^W4}dV0az0UG`e|jlK_Iz{zEqERjPR)@~;$oy4-SA zL;ywyg0N@<6}|B2m@J?y{Il!FI^A|fL;%JDO1HlJeM;%^F{IA~M8S&UOq&gar*~c` zRO>*Q7&Jpru__20JU%X$>Ora5S8p5%7nYhL03&7tW%GOp_P%E1&rKP(fp&RZ0calw z1os7!iS!LB4GUuEVH3s)KxU!`%>K%C?SnljH*o%zwGRYkMn8~m=*W+B1IB6oFTuzk z+e4=b!VOy-GR^{sPWNiE9b8B-2qcIJ zAgm%1W&^c7T1B*0&w}*tJiNsr|FDTL0cafuXjHD1wH2rja{&|xT9gfh34j7Yi{bzZ z0`0`v;t*K?%iRFQ03-ksfTi$K{m}CQn19edIflXz*wh&+gM&-N{sB>%Jl>TgyyIq! zJ3jt^pYSoPCeRlHybg7Lu*KZ8ouP1ZR2HCZZQ!HbOJf&=!p}WactTin)JF+G%Qyf` zzGz9!vvt+T)@szPU$HiWG8?m zNq#l>AI99ZDuEVQfD7asWdR5y@gR(RK;EPvkPwPb82R;KFB&5N%O`chu*X_8>U8l? z7ocNppz5Bz2>1L|L5H>SI7iDH69hte_f5$XZ#Y!Spyva&SR4DyfLz2IX@yT`kEKon zThVLdr>J1B?AQCL3P4LM@bOi#nm||-GT`A5F!^v`)T-z&j+#1av$m*PPrw2X_;dfr z_hA_9_t!V!xxjVSRz*g=hyb*;1hBUcECoM1xVSKMYucDmUllzjPDB7kxP-YWRte>|o1~3F2PJBHH;(dhH1fKl`2Gj;> zINBSW^i*81&MsioMAf2ZBOOR@jx%+ewg9#=>`WL9Egp=vd25N7L%u~S?28k2ozGCX zE&txw{bcHDqg+5UMFDg;+08UNhTUVCe_7(q35Z0-qHKj^QgH2JTx5%~0PTbY& Date: Wed, 16 Mar 2016 15:17:00 -0700 Subject: [PATCH 5/6] fix add/append mixup --- generate_emoji_html.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/generate_emoji_html.py b/generate_emoji_html.py index 5cbd82f60..4f2fc3029 100755 --- a/generate_emoji_html.py +++ b/generate_emoji_html.py @@ -164,24 +164,26 @@ def _get_image_data(image_dir, ext, prefix): filename = path.basename(f) m = expect_re.match(filename) if not m: - fails.add('did not match: ' + filename) + if filename.startswith('unknown_flag.'): + continue + fails.append('"%s" did not match: "%s"' % (expect_re, filename)) continue seq = m.group(1) try: cps = tuple(int(s, 16) for s in seq.split('_')) except: - fails.add('bad cp sequence: ' + filename) + fails.append('bad cp sequence: ' + filename) continue this_failed = False for cp in cps: if (cp > 0x10ffff): - fails.add('cp out of range: ' + filename) + fails.append('cp out of range: ' + filename) this_failed = True break if this_failed: continue if cps in result: - fails.add('duplicate sequence: %s and %s' (result[cps], filename)) + fails.append('duplicate sequence: %s and %s' (result[cps], filename)) continue result[cps] = filename if fails: From 2a6be6884101995d490449147873841c20e8dc1b Mon Sep 17 00:00:00 2001 From: Doug Felt Date: Wed, 16 Mar 2016 16:48:39 -0700 Subject: [PATCH 6/6] fixes for review --- generate_emoji_html.py | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/generate_emoji_html.py b/generate_emoji_html.py index 4f2fc3029..e33bcc1b5 100755 --- a/generate_emoji_html.py +++ b/generate_emoji_html.py @@ -94,7 +94,7 @@ def _get_name(key_tuple): if cp in unicode_data.proposed_emoji_cps(): name = '(proposed) ' + unicode_data.proposed_emoji_name(cp) else: - name =unicode_data.name(cp, '(error)') + name = unicode_data.name(cp, '(error)') return CELL_PREFIX + name @@ -116,39 +116,6 @@ def _generate_content(dir_infos): return '\n
'.join(lines) + '\n
' -""" -def _generate_content(files, prefix=_default_prefix): - key_to_filename = {} - for fname in files: - filename = path.basename(fname) - if not filename.startswith(prefix): - print >> sys.stderr, 'bad prefix for filename %s' % fname - continue - key_string = path.splitext(filename)[0] - key_string = key_string[len(prefix):] - try: - key_tuple = tuple(int(k, 16) for k in key_string.split('_')) - except: - print 'bad filename: "%s"' % key_string - key_to_filename[key_tuple] = fname - - lines = [""] - for key_tuple in sorted(key_to_filename): - if len(key_tuple) == 1: - key_string = 'U+%04X' % key_tuple - else: - key_string = ' + '.join( - '' % key_to_filename[tuple([key])] - for key in key_tuple - if tuple([key]) in key_to_filename) - name = _get_name(key_tuple) - lines.append('
' - '%s' - '%s' % ( - key_to_filename[key_tuple], key_string, name)) - return '\n '.join(lines) + '\n' -""" - def _get_image_data(image_dir, ext, prefix): """Return a map from a tuple of cp sequences to a filename. @@ -166,7 +133,7 @@ def _get_image_data(image_dir, ext, prefix): if not m: if filename.startswith('unknown_flag.'): continue - fails.append('"%s" did not match: "%s"' % (expect_re, filename)) + fails.append('"%s" did not match: "%s"' % (expect_re.pattern, filename)) continue seq = m.group(1) try: