tools/unicode_dbl_width: do not redefine range

devs/bu5hm4n/fix-for-billiob
Boris Faure 2 years ago
parent 8c970b8804
commit 7d1536c8e9
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
  1. 31
      tools/unicode_dbl_width.py

@ -10,7 +10,7 @@ import argparse
from collections import namedtuple
import xml.etree.ElementTree as ET
Range = namedtuple('range', ['width', 'start', 'end'])
URange = namedtuple('unicode_range', ['width', 'start', 'end'])
def get_ranges(xmlfile, emoji_as_wide):
tree = ET.parse(xmlfile)
@ -19,14 +19,13 @@ def get_ranges(xmlfile, emoji_as_wide):
chars = repertoire.findall("{http://www.unicode.org/ns/2003/ucd/1.0}char")
ranges = []
range = Range('N', 0, 0)
r = URange('N', 0, 0)
for c in chars:
ea = c.get('ea')
if ea in ('Na', 'H'):
ea = 'N'
if ea in ('F'):
ea = 'W'
assert ea in ('N', 'A', 'W')
cp = c.get('cp')
if not cp:
continue
@ -36,26 +35,26 @@ def get_ranges(xmlfile, emoji_as_wide):
ea = 'W'
cp = int(cp, 16)
if ea != range[0]:
ranges.append(range)
range = Range(ea, cp, cp)
if ea != r[0]:
ranges.append(r)
r = URange(ea, cp, cp)
else:
range = range._replace(end=cp)
r = r._replace(end=cp)
ranges.append(range)
ranges.append(r)
return ranges
def merge_ranges(ranges, is_same_width):
res = []
range = ranges[0]
cur_range = ranges[0]
for r in ranges:
if is_same_width(r, range):
range = range._replace(end=r.end)
if is_same_width(r, cur_range):
cur_range = cur_range._replace(end=r.end)
else:
res.append(range)
range = r
res.append(range)
res.append(cur_range)
cur_range = r
res.append(cur_range)
return res
def skip_ranges(ranges, width_skipped):
@ -65,7 +64,7 @@ def skip_ranges(ranges, width_skipped):
res.append(r)
return res
def gen_header(range, file_header):
def gen_header(cur_range, file_header):
file_header.write(
"""/* XXX: Code generated by tool unicode_dbl_width.py */
#ifndef _TERMPTY_DBL_H__
@ -79,7 +78,7 @@ _termpty_is_dblwidth_get(const Termpty *ty, const Eina_Unicode g)
{
/* optimize for latin1 non-ambiguous */
""")
file_header.write(f" if (g <= 0x{range.end:X})")
file_header.write(f" if (g <= 0x{cur_range.end:X})")
file_header.write(
"""
return EINA_FALSE;

Loading…
Cancel
Save