def
font_mapping(b64_code):
with
open
(
"map.txt"
,
"r"
, encoding
=
"utf-8"
) as f:
keys
=
json.loads(f.read())
kes_sign_list
=
{}
for
i
in
keys:
kes_sign_list[keys[i]]
=
i
lists_base_all
=
[]
keylist
=
{}
text_font
=
TTFont(BytesIO(base64.decodebytes(b64_code.encode())))
text_font.save(
"font.ttf"
)
text_font.saveXML(
"font.xml"
)
with
open
(
'font.xml'
) as f_baes:
xml_base
=
f_baes.read()
s_base
=
xml_base.split(
"</TTGlyph>"
)[:
-
1
]
for
i
in
range
(
0
,
len
(s_base)):
lists_base
=
[]
contour
=
re.findall(
'<pt (.*?)/>'
, s_base[i])
name
=
re.findall(
'name="(.*?)"'
,s_base[i])[
0
]
for
j
in
range
(
0
,
len
(contour)):
x
=
re.findall(
'x=\"(.*?)\"'
, contour[j])
y
=
re.findall(
'y=\"(.*?)\"'
, contour[j])
on
=
re.findall(
'on=\"(.*?)\"'
, contour[j])
lists_base.append(x[
0
]
+
y[
0
]
+
on[
0
])
keylist[name]
=
hashlib.md5("".join(lists_base).encode(
'utf8'
)).hexdigest()
lists_base_all.append(lists_base)
keys_list
=
{}
for
i
in
keylist:
keys_list[i]
=
kes_sign_list[keylist[i]].replace(
"uni"
,
"\\u"
).encode(
"utf-8"
).decode(
'unicode_escape'
)
return
keys_list