def get_charset_info(charset): """Returns an encoding of the charset as pairs of lengths of runs of chars to skip and chars to include. Each length is written as length - 1 in hex-- except when length == 1, which is written as the empty string-- and separated from the next length by a comma. Thus successive commas indicate a length of 1, a 1 indicates a length of 2, and so on. Since the minimum representable length is 1, the base is -1 so that the first run (a skip) of 1 can be output as a comma to then start the first included character at 0 if need be. Only as many pairs of values as are needed to encode the last run of included characters.""" ranges = coverage.convert_set_to_ranges(charset) prev = -1 range_list = [] for start, end in ranges: range_len = start - 1 - prev if range_len > 0: range_list.append('%x' % range_len) else: range_list.append('') range_len = end - start if range_len > 0: range_list.append('%x' % range_len) else: range_list.append('') prev = end + 1 return ','.join(range_list)
def charset_to_ranges(font_charset): # Ignore basic common characters charset = font_charset - {0x00, 0x0D, 0x20, 0xA0, 0xFEFF} ranges = coverage.convert_set_to_ranges(charset) output_list = [] for start, end in ranges: output_list.append(('%04X' % start, '%04X' % end)) return output_list