This commit is contained in:
NikolajDanger
2022-06-02 16:04:14 +02:00
parent 7ad5092665
commit 62e0275e00
18 changed files with 67 additions and 26 deletions

View File

@ -1,29 +1,33 @@
## Sans Serif
Akzidenz Grotesk Akzidenz Grotesk
Arial Arial
#Baskerville
#Bembo
#Bodoni
#Cambria
Calibri Calibri
#Clarendon
#Dax Pro
#Didot
#Franklin Gothic
#Frutiger
Futura Futura
#Garamond
#Georgia ## Serif
#Gill Sans Cambria
#Gotham
Baskerville
Bembo
Bodoni
Clarendon
Dax Pro
Didot
Franklin Gothic
Frutiger
Garamond
Georgia
Gill Sans
Gotham
Helvetica Helvetica
#Minion Minion
#Mrs Eaves Mrs Eaves
#Myriad Myriad
#News Gothic News Gothic
Roboto Roboto
#Roboto Slab Roboto Slab
#Rockwell Rockwell
#Sabon Sabon
#Segoe UI Segoe UI
#Times New Roman Times New Roman
#Verdana Verdana

View File

@ -1,7 +1,7 @@
import string import string
import pathlib import pathlib
import time import time
from PIL import ImageFont from PIL import ImageFont, Image, ImageDraw
BASE64_DIGITS = string.digits + string.ascii_letters + "+_" BASE64_DIGITS = string.digits + string.ascii_letters + "+_"
@ -12,6 +12,9 @@ IMAGE_SIZE = (1800, 1200)
MARGINS = 60 MARGINS = 60
MAKE_TESTS = True
TEST_TEXT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
def read_file(path: str) -> dict: def read_file(path: str) -> dict:
with open(path, "r", encoding="utf-8") as file: with open(path, "r", encoding="utf-8") as file:
game_dict = dict( game_dict = dict(
@ -43,13 +46,40 @@ def gen_id() -> str:
micro_seconds = int(time.time() * 1000000) micro_seconds = int(time.time() * 1000000)
return base64((micro_seconds * 9876534021204356789) % 0xfffffffffffffff) return base64((micro_seconds * 9876534021204356789) % 0xfffffffffffffff)
def make_test_pages(fonts: dict[str, ImageFont.FreeTypeFont]):
image_width = FONT_SIZE*8
image_height = FONT_SIZE*8
image_margin = FONT_SIZE//3
writable_area = image_width - image_margin*2
for font_name, font in fonts.items():
final_text = []
current_text = ""
for char in TEST_TEXT:
if font.getsize(current_text + char)[0] > (writable_area):
final_text.append(current_text)
current_text = char
else:
current_text += char
final_text.append(current_text)
im = Image.new("RGB", (image_width, image_height), (255, 255, 255))
drawer = ImageDraw.ImageDraw(im)
drawer.text(
(image_margin, image_margin),
'\n'.join(final_text),
(0, 0, 0),
font
)
im.save(f"fonts/test_pages/{font_name}.png")
def make_fonts(): def make_fonts():
with open("font-list.txt", "r", encoding="utf-8") as file_pointer: with open("font-list.txt", "r", encoding="utf-8") as file_pointer:
fonts = file_pointer.read().split("\n") fonts = file_pointer.read().split("\n")
image_fonts = {} image_fonts = {}
for font_name in fonts: for font_name in fonts:
if font_name[0] == "#": if font_name == "" or font_name[0] == "#":
continue continue
font_name = font_name.replace(" ","-") font_name = font_name.replace(" ","-")
if pathlib.Path(f"./fonts/{font_name}.TTF").is_file(): if pathlib.Path(f"./fonts/{font_name}.TTF").is_file():
@ -61,10 +91,17 @@ def make_fonts():
continue continue
font_path = f"./fonts/{font_name}.{file_type}" font_path = f"./fonts/{font_name}.{file_type}"
new_font = ImageFont.truetype(font_path, FONT_SIZE) tmp_font = ImageFont.truetype(font_path, FONT_SIZE)
letter_height = tmp_font.getsize("A")[1]
new_size = (FONT_SIZE**2)//letter_height
new_font = ImageFont.truetype(font_path, new_size)
image_fonts[font_name] = new_font image_fonts[font_name] = new_font
print(f"Successfully loaded font \033[0;32m{font_name}\033[0m") print(f"Successfully loaded font \033[0;32m{font_name}\033[0m")
if MAKE_TESTS:
make_test_pages(image_fonts)
print("Successfully created test pages")
return image_fonts return image_fonts

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

BIN
fonts/test_pages/Arial.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

BIN
fonts/test_pages/Bembo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 133 KiB

BIN
fonts/test_pages/Bodoni.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

BIN
fonts/test_pages/Futura.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

BIN
fonts/test_pages/Roboto.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB