|
@ -0,0 +1,22 @@ |
|
|
|
|
|
from ..data import Glyph, Font |
|
|
|
|
|
from ._utils import strip_ws, desc2glyph_list |
|
|
|
|
|
import re |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse(inp: str) -> Font: |
|
|
|
|
|
m: re.Match = re.match(r"TXTF 1 (\d+) (\d+) (\d+) (..)", inp) |
|
|
|
|
|
cl, w, h, a = m.groups() |
|
|
|
|
|
cl, w, h = int(cl), int(w), int(h) |
|
|
|
|
|
inp = inp[m.end()+1:] |
|
|
|
|
|
comment = [] |
|
|
|
|
|
for _ in range(cl): |
|
|
|
|
|
m = re.match(fr"(^.*$)", inp, re.MULTILINE) |
|
|
|
|
|
comment.append(m.groups()[0]) |
|
|
|
|
|
inp = inp[m.end()+1:] |
|
|
|
|
|
inp = strip_ws(inp) |
|
|
|
|
|
glyphs: dict[str, Glyph] = {} |
|
|
|
|
|
while (m := re.match(r".{" + str(w * h + 1) + "}", inp)) is not None: |
|
|
|
|
|
d = m.group(0) |
|
|
|
|
|
glyphs[d[0]] = Glyph(width=w, height=h, glyph=desc2glyph_list(w, a, d[1:])) |
|
|
|
|
|
inp = inp[m.end():] |
|
|
|
|
|
return Font(mode=1,comment="\n".join(comment),glyphs=glyphs) |