feature: line spacing + characters are aligned
This commit is contained in:
@ -13,25 +13,29 @@ with open(sys.argv[1]) as f:
|
||||
font_name: str = os.path.basename(sys.argv[1]).split(".")[0]
|
||||
|
||||
img_file_relative_path: str = re.findall(r"file=\"(\w+[^\"]+)\"", fnt_data)[0]
|
||||
img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") + 1] + img_file_relative_path
|
||||
img_file_absolute_path: str = sys.argv[1][0:sys.argv[1].rfind("/") +
|
||||
1] + img_file_relative_path
|
||||
|
||||
image = Image.open(img_file_absolute_path)
|
||||
|
||||
width, height = image.size
|
||||
pixels = list(image.getdata())
|
||||
pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
|
||||
pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
|
||||
|
||||
characteres: list[list[int]] = [None for i in range(128)]
|
||||
|
||||
for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)", fnt_data):
|
||||
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance)
|
||||
for id, x, y, width, height, xoffset, yoffset, xadvance in re.findall(
|
||||
r"id=(\d+) x=(\d+) y=(\d+) width=(\d+) height=(\d+) xoffset=(-?\d+) yoffset=(-?\d+) xadvance=(\d+)",
|
||||
fnt_data):
|
||||
id, x, y, width, height, xoffset, yoffset, xadvance = int(id), int(x), int(
|
||||
y), int(width), int(height), int(xoffset), int(yoffset), int(xadvance)
|
||||
bitmap: list[str] = []
|
||||
for line in pixels[y:y + height]:
|
||||
tmp: str = ""
|
||||
for r,g,b,a in line[x:x + width]:
|
||||
for r, g, b, a in line[x:x + width]:
|
||||
tmp += "#" if a else " "
|
||||
bitmap.append(tmp)
|
||||
characteres[id] = [height, width, bitmap]
|
||||
bitmap.append(tmp)
|
||||
characteres[id] = [height, width, yoffset, bitmap]
|
||||
|
||||
string: str = f"""\
|
||||
#pragma once
|
||||
@ -45,11 +49,12 @@ struct font {font_name}_font[] = {{\\\
|
||||
|
||||
for charactere in characteres:
|
||||
if (charactere is not None):
|
||||
height, width, bitmap = charactere
|
||||
height, width, yoffset, bitmap = charactere
|
||||
string += f"""
|
||||
{{
|
||||
.width = {width},
|
||||
.height = {height},
|
||||
.yoffset = {yoffset},
|
||||
.bitmap = "{"".join(bitmap)}",
|
||||
}},\
|
||||
"""
|
||||
@ -58,6 +63,7 @@ for charactere in characteres:
|
||||
{{
|
||||
.width = 0,
|
||||
.height = 0,
|
||||
.yoffset = 0,
|
||||
.bitmap = NULL,
|
||||
}},\
|
||||
"""
|
||||
@ -67,4 +73,4 @@ if not os.path.exists("./headers/fonts"):
|
||||
os.makedirs("./headers/fonts")
|
||||
|
||||
with open(f"./headers/fonts/{font_name}.h", "w") as f:
|
||||
f.write(string)
|
||||
f.write(string)
|
||||
|
Reference in New Issue
Block a user