def _check_skintone(sorted_seq_to_filepath): """Ensure skin tone modifiers are not applied to emoji that are not defined to take them. May appear standalone, though. Also check that emoji that take skin tone modifiers have a complete set.""" base_to_modifiers = collections.defaultdict(set) for seq, fp in sorted_seq_to_filepath.iteritems(): for i, cp in enumerate(seq): if _is_skintone_modifier(cp): if i == 0: if len(seq) > 1: print >> sys.stderr, 'skin color selector first in sequence %s' % fp # standalone are ok continue pcp = seq[i - 1] if not unicode_data.is_emoji_modifier_base(pcp): print >> sys.stderr, ( 'emoji skintone modifier applied to non-base at %d: %s' % (i, fp)) elif unicode_data.is_emoji_modifier_base(cp): if i < len(seq) - 1 and _is_skintone_modifier(seq[i + 1]): base_to_modifiers[cp].add(seq[i + 1]) elif cp not in base_to_modifiers: base_to_modifiers[cp] = set() for cp, modifiers in sorted(base_to_modifiers.iteritems()): if len(modifiers) != 5: print >> sys.stderr, 'emoji base %04x has %d modifiers defined (%s) in %s' % ( cp, len(modifiers), ', '.join('%04x' % cp for cp in sorted(modifiers)), fp)
def _check_skintone(sorted_seqs): """Ensure skin tone modifiers are not applied to emoji that are not defined to take them. May appear standalone, though. Also check that emoji that take skin tone modifiers have a complete set.""" base_to_modifiers = collections.defaultdict(set) for seq in sorted_seqs: for i, cp in enumerate(seq): if _is_skintone_modifier(cp): if i == 0: if len(seq) > 1: print >> sys.stderr, 'skin color selector first in sequence %s' # standalone are ok continue pcp = seq[i-1] if not unicode_data.is_emoji_modifier_base(pcp): print >> sys.stderr, ( 'emoji skintone modifier applied to non-base at %d: %s' % ( i, _seq_string(seq))) elif unicode_data.is_emoji_modifier_base(cp): if i < len(seq) - 1 and _is_skintone_modifier(seq[i+1]): base_to_modifiers[cp].add(seq[i+1]) elif cp not in base_to_modifiers: base_to_modifiers[cp] = set() for cp, modifiers in sorted(base_to_modifiers.iteritems()): if len(modifiers) != 5: print 'emoji base %04X has %d modifiers defined (%s)' % ( cp, len(modifiers), ', '.join('%04x' % cp for cp in sorted(modifiers)))
def _check_skintone(sorted_seq_to_filepath): """Ensure skin tone modifiers are not applied to emoji that are not defined to take them. May appear standalone, though. Also check that emoji that take skin tone modifiers have a complete set.""" base_to_modifiers = collections.defaultdict(set) for seq, fp in sorted_seq_to_filepath.iteritems(): for i, cp in enumerate(seq): if unicode_data.is_skintone_modifier(cp): if i == 0: if len(seq) > 1: print( 'check skintone: skin color selector first in sequence %s' % fp, file=sys.stderr) # standalone are ok continue pcp = seq[i-1] if not unicode_data.is_emoji_modifier_base(pcp): print( 'check skintone: emoji skintone modifier applied to non-base ' + 'at %d: %s' % (i, fp), file=sys.stderr) else: if pcp not in base_to_modifiers: base_to_modifiers[pcp] = set() base_to_modifiers[pcp].add(cp) for cp, modifiers in sorted(base_to_modifiers.iteritems()): if len(modifiers) != 5: print( 'check skintone: base %04x has %d modifiers defined (%s) in %s' % ( cp, len(modifiers), ', '.join('%04x' % cp for cp in sorted(modifiers)), fp), file=sys.stderr)
def _check_skintone(sorted_seq_to_filepath): """Ensure skin tone modifiers are not applied to emoji that are not defined to take them. May appear standalone, though. Also check that emoji that take skin tone modifiers have a complete set.""" base_to_modifiers = collections.defaultdict(set) for seq, fp in sorted_seq_to_filepath.items(): for i, cp in enumerate(seq): if unicode_data.is_skintone_modifier(cp): if i == 0: if len(seq) > 1: print( f'check skintone: skin color selector first in sequence {fp}', file=sys.stderr) # standalone are ok continue pcp = seq[i - 1] if not unicode_data.is_emoji_modifier_base(pcp): print( f'check skintone: emoji skintone modifier applied to non-base at {i}: {fp}', file=sys.stderr) else: if pcp not in base_to_modifiers: base_to_modifiers[pcp] = set() base_to_modifiers[pcp].add(cp) for cp, modifiers in sorted(base_to_modifiers.items()): if len(modifiers) != 5: print( 'check skintone: base %04x has %d modifiers defined (%s) in %s' % (cp, len(modifiers), ', '.join( '%04x' % cp for cp in sorted(modifiers)), fp), file=sys.stderr)
def _fix_estrs(estrs): """Add fitzpatrick colors, and remove emoji variation selectors. 1) The emoji ordering html page omits the skin color variants. Since we want to display them, we have to add them. However, we don't add them for sequences with multiple people, since we don't support multiracial groups at the moment. 2) Currently we don't include emoji variation selectors in our sequences except after heavy black heart (and we probably don't need them there either). The font will work fine without them, but some systems doing fallback might break the sequences apart if the variation selectors are not present in text. So they should be there in the text, and not there in the font. Anyway, while we clean this up, we currently strip them except for the four cases where we retain them for legacy reasons. """ new_estrs = [] for estr in estrs: if estr in _keep_varsel_estrs: nestr = estr else: if u'\u2764' in estr: print '# oops', u''.join('\\u%04x' % ord(cp) for cp in estr) nestr = u''.join(cp for cp in estr if cp != u'\ufe0f') new_estrs.append(nestr) num_bases = sum( unicode_data.is_emoji_modifier_base(ord(cp)) for cp in estr) if num_bases != 1: continue split_before = len(nestr) for i, cp in enumerate(nestr): if unicode_data.is_emoji_modifier_base(ord(cp)): split_before = i + 1 break prefix = nestr[:split_before] suffix = nestr[split_before:] for cp in range(0x1f3fb, 0x1f3ff + 1): new_estrs.append(u''.join([prefix, unichr(cp), suffix])) return new_estrs
def _fix_estrs(estrs): """Add fitzpatrick colors, and remove emoji variation selectors. 1) The emoji ordering html page omits the skin color variants. Since we want to display them, we have to add them. However, we don't add them for sequences with multiple people, since we don't support multiracial groups at the moment. 2) Currently we don't include emoji variation selectors in our sequences except after heavy black heart (and we probably don't need them there either). The font will work fine without them, but some systems doing fallback might break the sequences apart if the variation selectors are not present in text. So they should be there in the text, and not there in the font. Anyway, while we clean this up, we currently strip them except for the four cases where we retain them for legacy reasons. """ new_estrs = [] for estr in estrs: if estr in _keep_varsel_estrs: nestr = estr else: if u'\u2764' in estr: print '# oops', u''.join('\\u%04x' % ord(cp) for cp in estr) nestr = u''.join(cp for cp in estr if cp != u'\ufe0f') new_estrs.append(nestr) num_bases = sum(unicode_data.is_emoji_modifier_base(ord(cp)) for cp in estr) if num_bases != 1: continue split_before = len(nestr) for i, cp in enumerate(nestr): if unicode_data.is_emoji_modifier_base(ord(cp)): split_before = i + 1 break prefix = nestr[:split_before] suffix = nestr[split_before:] for cp in range(0x1f3fb, 0x1f3ff + 1): new_estrs.append(u''.join([prefix, unichr(cp), suffix])) return new_estrs