✨
@ -1,29 +1,33 @@
|
||||
## Sans Serif
|
||||
Akzidenz Grotesk
|
||||
Arial
|
||||
#Baskerville
|
||||
#Bembo
|
||||
#Bodoni
|
||||
#Cambria
|
||||
Calibri
|
||||
#Clarendon
|
||||
#Dax Pro
|
||||
#Didot
|
||||
#Franklin Gothic
|
||||
#Frutiger
|
||||
Futura
|
||||
#Garamond
|
||||
#Georgia
|
||||
#Gill Sans
|
||||
#Gotham
|
||||
|
||||
## Serif
|
||||
Cambria
|
||||
|
||||
Baskerville
|
||||
Bembo
|
||||
Bodoni
|
||||
Clarendon
|
||||
Dax Pro
|
||||
Didot
|
||||
Franklin Gothic
|
||||
Frutiger
|
||||
Garamond
|
||||
Georgia
|
||||
Gill Sans
|
||||
Gotham
|
||||
Helvetica
|
||||
#Minion
|
||||
#Mrs Eaves
|
||||
#Myriad
|
||||
#News Gothic
|
||||
Minion
|
||||
Mrs Eaves
|
||||
Myriad
|
||||
News Gothic
|
||||
Roboto
|
||||
#Roboto Slab
|
||||
#Rockwell
|
||||
#Sabon
|
||||
#Segoe UI
|
||||
#Times New Roman
|
||||
#Verdana
|
||||
Roboto Slab
|
||||
Rockwell
|
||||
Sabon
|
||||
Segoe UI
|
||||
Times New Roman
|
||||
Verdana
|
@ -1,7 +1,7 @@
|
||||
import string
|
||||
import pathlib
|
||||
import time
|
||||
from PIL import ImageFont
|
||||
from PIL import ImageFont, Image, ImageDraw
|
||||
|
||||
BASE64_DIGITS = string.digits + string.ascii_letters + "+_"
|
||||
|
||||
@ -12,6 +12,9 @@ IMAGE_SIZE = (1800, 1200)
|
||||
|
||||
MARGINS = 60
|
||||
|
||||
MAKE_TESTS = True
|
||||
TEST_TEXT = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
||||
def read_file(path: str) -> dict:
|
||||
with open(path, "r", encoding="utf-8") as file:
|
||||
game_dict = dict(
|
||||
@ -43,13 +46,40 @@ def gen_id() -> str:
|
||||
micro_seconds = int(time.time() * 1000000)
|
||||
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():
|
||||
with open("font-list.txt", "r", encoding="utf-8") as file_pointer:
|
||||
fonts = file_pointer.read().split("\n")
|
||||
|
||||
image_fonts = {}
|
||||
for font_name in fonts:
|
||||
if font_name[0] == "#":
|
||||
if font_name == "" or font_name[0] == "#":
|
||||
continue
|
||||
font_name = font_name.replace(" ","-")
|
||||
if pathlib.Path(f"./fonts/{font_name}.TTF").is_file():
|
||||
@ -61,10 +91,17 @@ def make_fonts():
|
||||
continue
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
BIN
fonts/test_pages/Akzidenz-Grotesk.png
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
fonts/test_pages/Arial.png
Normal file
After Width: | Height: | Size: 99 KiB |
BIN
fonts/test_pages/Baskerville.png
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
fonts/test_pages/Bembo.png
Normal file
After Width: | Height: | Size: 133 KiB |
BIN
fonts/test_pages/Bodoni.png
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
fonts/test_pages/Calibri.png
Normal file
After Width: | Height: | Size: 106 KiB |
BIN
fonts/test_pages/Cambria.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
fonts/test_pages/Futura.png
Normal file
After Width: | Height: | Size: 87 KiB |
BIN
fonts/test_pages/Garamond.png
Normal file
After Width: | Height: | Size: 132 KiB |
BIN
fonts/test_pages/Georgia.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
fonts/test_pages/Helvetica.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
fonts/test_pages/Roboto-Slab.png
Normal file
After Width: | Height: | Size: 86 KiB |
BIN
fonts/test_pages/Roboto.png
Normal file
After Width: | Height: | Size: 83 KiB |
BIN
fonts/test_pages/Segoe-UI.png
Normal file
After Width: | Height: | Size: 77 KiB |
BIN
fonts/test_pages/Times-New-Roman.png
Normal file
After Width: | Height: | Size: 107 KiB |
BIN
fonts/test_pages/Verdana.png
Normal file
After Width: | Height: | Size: 87 KiB |