mirror of
https://github.com/googlefonts/noto-emoji.git
synced 2025-07-09 13:55:31 +00:00
Merge 3ba53cba1d
into 7159f45c58
This commit is contained in:
commit
207baa5de5
1 changed files with 74 additions and 43 deletions
43
third_party/color_emoji/emoji_builder.py
vendored
43
third_party/color_emoji/emoji_builder.py
vendored
|
@ -25,15 +25,40 @@ from os import path
|
||||||
|
|
||||||
from nototools import font_data
|
from nototools import font_data
|
||||||
|
|
||||||
|
def myunichr(cp):
|
||||||
|
if sys.maxunicode < 0x10FFFF and cp > 0xFFFF:
|
||||||
|
return ("\\U" + hex(cp)[2:].zfill(8)).decode("unicode-escape")
|
||||||
|
return unichr(cp)
|
||||||
|
|
||||||
|
def myord(high, low):
|
||||||
|
return (ord(high) - 0xD800) * 0x400 + (ord(low) - 0xDC00) + 0x10000
|
||||||
|
|
||||||
|
def begins_with_surrogate(string):
|
||||||
|
return sys.maxunicode < 0x10FFFF and len(string) > 1 and (0xD800 <= ord(string[0]) <= 0xDBFF) and (0xDC00 <= ord(string[1]) <= 0xDFFF)
|
||||||
|
|
||||||
def get_glyph_name_from_gsub (string, font, cmap_dict):
|
def get_glyph_name_from_gsub (string, font, cmap_dict):
|
||||||
ligatures = font['GSUB'].table.LookupList.Lookup[0].SubTable[0].ligatures
|
ligatures = font['GSUB'].table.LookupList.Lookup[0].SubTable[0].ligatures
|
||||||
|
|
||||||
|
if begins_with_surrogate(string):
|
||||||
|
first_glyph = cmap_dict[myord(string[0], string[1])]
|
||||||
|
string = string[2:]
|
||||||
|
else:
|
||||||
first_glyph = cmap_dict[ord (string[0])]
|
first_glyph = cmap_dict[ord (string[0])]
|
||||||
rest_of_glyphs = [cmap_dict[ord (ch)] for ch in string[1:]]
|
string = string[1:]
|
||||||
|
|
||||||
|
rest_of_glyphs = []
|
||||||
|
while (len(string) > 0):
|
||||||
|
if begins_with_surrogate(string):
|
||||||
|
rest_of_glyphs.append(cmap_dict[myord(string[0], string[1])])
|
||||||
|
string = string[2:]
|
||||||
|
else:
|
||||||
|
rest_of_glyphs.append(cmap_dict[ord (string[0])])
|
||||||
|
string = string[1:]
|
||||||
|
|
||||||
for ligature in ligatures[first_glyph]:
|
for ligature in ligatures[first_glyph]:
|
||||||
if ligature.Component == rest_of_glyphs:
|
if ligature.Component == rest_of_glyphs:
|
||||||
return ligature.LigGlyph
|
return ligature.LigGlyph
|
||||||
|
|
||||||
|
|
||||||
def div (a, b):
|
def div (a, b):
|
||||||
return int (round (a / float (b)))
|
return int (round (a / float (b)))
|
||||||
|
|
||||||
|
@ -463,13 +488,13 @@ By default they are dropped.
|
||||||
if "_" in codes:
|
if "_" in codes:
|
||||||
pieces = codes.split ("_")
|
pieces = codes.split ("_")
|
||||||
cps = [int(code, 16) for code in pieces]
|
cps = [int(code, 16) for code in pieces]
|
||||||
uchars = "".join ([unichr(cp) for cp in cps if not is_vs(cp)])
|
uchars = "".join ([myunichr(cp) for cp in cps if not is_vs(cp)])
|
||||||
else:
|
else:
|
||||||
cp = int(codes, 16)
|
cp = int(codes, 16)
|
||||||
if is_vs(cp):
|
if is_vs(cp):
|
||||||
print "ignoring unexpected vs input %04x" % cp
|
print "ignoring unexpected vs input %04x" % cp
|
||||||
continue
|
continue
|
||||||
uchars = unichr(cp)
|
uchars = myunichr(cp)
|
||||||
img_files[uchars] = img_file
|
img_files[uchars] = img_file
|
||||||
if not img_files:
|
if not img_files:
|
||||||
raise Exception ("No image files found in '%s'." % glb)
|
raise Exception ("No image files found in '%s'." % glb)
|
||||||
|
@ -484,14 +509,20 @@ By default they are dropped.
|
||||||
except:
|
except:
|
||||||
print "no cmap entry for %x" % ord(uchars)
|
print "no cmap entry for %x" % ord(uchars)
|
||||||
raise ValueError("%x" % ord(uchars))
|
raise ValueError("%x" % ord(uchars))
|
||||||
|
elif len (uchars) == 2 and begins_with_surrogate(uchars):
|
||||||
|
cp = myord(uchars[0], uchars[1])
|
||||||
|
try:
|
||||||
|
glyph_name = unicode_cmap.cmap[cp]
|
||||||
|
except:
|
||||||
|
print "no cmap entry for %x" % cp
|
||||||
|
raise ValueError("%x" % ord(uchars))
|
||||||
else:
|
else:
|
||||||
glyph_name = get_glyph_name_from_gsub (uchars, font, unicode_cmap.cmap)
|
glyph_name = get_glyph_name_from_gsub (uchars, font, unicode_cmap.cmap)
|
||||||
glyph_id = font.getGlyphID (glyph_name)
|
glyph_id = font.getGlyphID (glyph_name)
|
||||||
glyph_imgs[glyph_id] = img_file
|
glyph_imgs[glyph_id] = img_file
|
||||||
if "verbose" in options:
|
if "verbose" in options:
|
||||||
uchars_name = ",".join (["%04X" % ord (char) for char in uchars])
|
uchars_name = ",".join (["%04X" % ord (char) for char in uchars])
|
||||||
# print "Matched U+%s: id=%d name=%s image=%s" % (
|
# print "Matched U+%s: id=%d name=%s image=%s" % (uchars_name, glyph_id, glyph_name, img_file)
|
||||||
# uchars_name, glyph_id, glyph_name, img_file)
|
|
||||||
|
|
||||||
advance += glyph_metrics[glyph_name][0]
|
advance += glyph_metrics[glyph_name][0]
|
||||||
w, h = PNG (img_file).get_size ()
|
w, h = PNG (img_file).get_size ()
|
||||||
|
|
Loading…
Add table
Reference in a new issue