rename from_bytes to _from_bytes in generated font files

pull/3/head
Brian Cappello 2017-06-29 11:24:09 -04:00
rodzic 12811b8542
commit 247098465b
1 zmienionych plików z 11 dodań i 11 usunięć

Wyświetl plik

@ -494,37 +494,36 @@ class Font(dict):
HEADER = """# Code generated by font-to-py.py. HEADER = """# Code generated by font-to-py.py.
# Font: %(font)s # Font: %(font)s
version = '0.2' version = '0.2'
def from_bytes(data):
return int.from_bytes(data, 'little')
""" """
HEADER_CHARSET = """# Code generated by font-to-py.py. HEADER_CHARSET = """# Code generated by font-to-py.py.
# Font: %(font)s # Font: %(font)s
version = '0.2' version = '0.2'
CHARSET = %(charset)s CHARSET = %(charset)s
"""
def from_bytes(data): FROM_BYTES = """\
def _from_bytes(data):
return int.from_bytes(data, 'little') return int.from_bytes(data, 'little')
""" """
CHAR_BOUNDS = """\ CHAR_BOUNDS = """
def _char_bounds(ch): def _char_bounds(ch):
index = ord(ch) - %(minchar)d index = ord(ch) - %(minchar)d
offset = 2 * index offset = 2 * index
start = from_bytes(_index[offset:offset+2]) start = _from_bytes(_index[offset:offset+2])
next_offset = 2 * (index + 1) next_offset = 2 * (index + 1)
end = from_bytes(_index[next_offset:next_offset+2]) end = _from_bytes(_index[next_offset:next_offset+2])
return start, end return start, end
""" """
CHAR_BOUNDS_CHARSET = """\ CHAR_BOUNDS_CHARSET = """
def _char_bounds(ch): def _char_bounds(ch):
index = CHARSET[ch] index = CHARSET[ch]
offset = 2 * index offset = 2 * index
start = from_bytes(_index[offset:offset+2]) start = _from_bytes(_index[offset:offset+2])
next_offset = 2 * (index + 1) next_offset = 2 * (index + 1)
end = from_bytes(_index[next_offset:next_offset+2]) end = _from_bytes(_index[next_offset:next_offset+2])
return start, end return start, end
""" """
@ -533,7 +532,7 @@ _mvfont = memoryview(_font)
def get_char(ch): def get_char(ch):
start, end = _char_bounds(ch) start, end = _char_bounds(ch)
width = from_bytes(_mvfont[start:start + 2]) width = _from_bytes(_mvfont[start:start + 2])
return _mvfont[start + 2:end], %(height)s, width return _mvfont[start + 2:end], %(height)s, width
""" """
@ -594,6 +593,7 @@ def write_data(stream, fnt, font_path, monospaced, hmap, lmap, reverse, charset)
bw_index = ByteWriter(stream, '_index') bw_index = ByteWriter(stream, '_index')
bw_index.odata(index) bw_index.odata(index)
bw_index.eot() bw_index.eot()
stream.write(FROM_BYTES)
if sequential_charset: if sequential_charset:
stream.write(CHAR_BOUNDS % {'minchar': ord(charset[0])}) stream.write(CHAR_BOUNDS % {'minchar': ord(charset[0])})
else: else: