def separate_glyphs(gdata, height): """return (dictionary of glyphs, utf8 required)""" gl = gdata.split("\n") del gl[0] del gl[-1] for g in gl: assert "\t" not in g assert len(gl) == height + 1, repr(gdata) key_line = gl[0] del gl[0] c = None # current character key_index = 0 # index into character key line end_col = 0 # column position at end of glyph start_col = 0 # column position at start of glyph jl = [0] * height # indexes into lines of gdata (gl) dout = {} utf8_required = False while True: if c is None: if key_index >= len(key_line): break c = key_line[key_index] if key_index < len(key_line) and key_line[key_index] == c: end_col += str_util.get_width(ord(c)) key_index += 1 continue out = [] for k in range(height): l = gl[k] j = jl[k] y = 0 fill = 0 while y < end_col - start_col: if j >= len(l): fill = end_col - start_col - y break y += str_util.get_width(ord(l[j])) j += 1 assert y + fill == end_col - start_col, \ repr((y, fill, end_col)) segment = l[jl[k]:j] if not SAFE_ASCII_DEC_SPECIAL_RE.match(segment): utf8_required = True out.append(segment + " " * fill) jl[k] = j start_col = end_col dout[c] = (y + fill, out) c = None return dout, utf8_required
def separate_glyphs(gdata, height): """return (dictionary of glyphs, utf8 required)""" gl = gdata.split("\n") del gl[0] del gl[-1] for g in gl: assert "\t" not in g assert len(gl) == height+1, repr(gdata) key_line = gl[0] del gl[0] c = None # current character key_index = 0 # index into character key line end_col = 0 # column position at end of glyph start_col = 0 # column position at start of glyph jl = [0]*height # indexes into lines of gdata (gl) dout = {} utf8_required = False while True: if c is None: if key_index >= len(key_line): break c = key_line[key_index] if key_index < len(key_line) and key_line[key_index] == c: end_col += str_util.get_width(ord(c)) key_index += 1 continue out = [] for k in range(height): l = gl[k] j = jl[k] y = 0 fill = 0 while y < end_col - start_col: if j >= len(l): fill = end_col - start_col - y break y += str_util.get_width(ord(l[j])) j += 1 assert y + fill == end_col - start_col, \ repr((y, fill, end_col)) segment = l[jl[k]:j] if not SAFE_ASCII_DEC_SPECIAL_RE.match(segment): utf8_required = True out.append(segment + " " * fill) jl[k] = j start_col = end_col dout[c] = (y + fill, out) c = None return dout, utf8_required