feat: Implement super-sampling for text rendering and adjust _RENDER_H from 16 to 8.
This commit is contained in:
10
mainline.py
10
mainline.py
@@ -147,7 +147,8 @@ KATA = "ハミヒーウシナモニサワツオリアホテマケメエカキム
|
|||||||
_FONT_PATH = "/Users/genejohnson/Documents/CS Bishop Drawn/CSBishopDrawn-Italic.otf"
|
_FONT_PATH = "/Users/genejohnson/Documents/CS Bishop Drawn/CSBishopDrawn-Italic.otf"
|
||||||
_FONT_OBJ = None
|
_FONT_OBJ = None
|
||||||
_FONT_SZ = 60
|
_FONT_SZ = 60
|
||||||
_RENDER_H = 16 # terminal rows per rendered text line
|
_RENDER_H = 8 # terminal rows per rendered text line
|
||||||
|
_SSAA = 4 # super-sampling factor: render at _SSAA× then downsample
|
||||||
|
|
||||||
# Non-Latin scripts → macOS system fonts
|
# Non-Latin scripts → macOS system fonts
|
||||||
_SCRIPT_FONTS = {
|
_SCRIPT_FONTS = {
|
||||||
@@ -579,8 +580,11 @@ def _render_line(text, font=None):
|
|||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
draw.text((-bbox[0] + pad, -bbox[1] + pad), text, fill=255, font=font)
|
draw.text((-bbox[0] + pad, -bbox[1] + pad), text, fill=255, font=font)
|
||||||
pix_h = _RENDER_H * 2
|
pix_h = _RENDER_H * 2
|
||||||
scale = pix_h / max(img_h, 1)
|
hi_h = pix_h * _SSAA
|
||||||
new_w = max(1, int(img_w * scale))
|
scale = hi_h / max(img_h, 1)
|
||||||
|
new_w_hi = max(1, int(img_w * scale))
|
||||||
|
img = img.resize((new_w_hi, hi_h), Image.Resampling.LANCZOS)
|
||||||
|
new_w = max(1, int(new_w_hi / _SSAA))
|
||||||
img = img.resize((new_w, pix_h), Image.Resampling.LANCZOS)
|
img = img.resize((new_w, pix_h), Image.Resampling.LANCZOS)
|
||||||
data = img.tobytes()
|
data = img.tobytes()
|
||||||
thr = 80
|
thr = 80
|
||||||
|
|||||||
Reference in New Issue
Block a user