mirror of
https://github.com/1j01/textual-paint.git
synced 2024-10-05 20:07:45 +03:00
Optimize meta glyph rendering?
This commit is contained in:
parent
22635bc007
commit
64e63f5cf3
@ -306,9 +306,17 @@ class Canvas(Widget):
|
||||
if x >= len(glyph_line) or x < 0:
|
||||
return " "
|
||||
return glyph_line[x]
|
||||
if ch in " ░▒▓█":
|
||||
return ch
|
||||
match ch:
|
||||
case " ":
|
||||
return " "
|
||||
case "░":
|
||||
return "░"
|
||||
case "▒":
|
||||
return "▒"
|
||||
case "▓":
|
||||
return "▓"
|
||||
case "█":
|
||||
return "█"
|
||||
# These are now obsolete special cases of below fractional block character handling.
|
||||
# case "▄":
|
||||
# return "█" if y >= magnification // 2 else " "
|
||||
|
@ -19,6 +19,11 @@ class MetaGlyphFont:
|
||||
"""The height in characters of a meta-glyph."""
|
||||
self.covered_characters = covered_characters
|
||||
"""The characters supported by this font."""
|
||||
|
||||
# EXCLUDE certain characters which are better handled by procedural glyph rendering.
|
||||
for ch in " ░▒▓██▔🮂🮃▀🮄🮅🮆▇▆▅▄▃▂▁▏▎▍▌▋▊▉███🮋🮊🮉▐🮈🮇▕":
|
||||
self.covered_characters = self.covered_characters.replace(ch, "")
|
||||
|
||||
self.load()
|
||||
|
||||
def load(self):
|
||||
@ -46,6 +51,7 @@ meta_glyph_fonts: dict[int, MetaGlyphFont] = {
|
||||
2: MetaGlyphFont(os.path.join(os.path.dirname(__file__), "fonts/NanoTiny/NanoTiny_v14_2x2.flf"), 2, 2, covered_characters),
|
||||
# 4: MetaGlyphFont(os.path.join(os.path.dirname(__file__), "fonts/NanoTiny/NanoTiny_v14_4x4.flf"), 4, 4, covered_characters),
|
||||
# TODO: less specialized (more practical) fonts for larger sizes
|
||||
# Also ASCII-only fonts for --ascii-only mode
|
||||
}
|
||||
|
||||
def largest_font_that_fits(max_width: int, max_height: int) -> MetaGlyphFont | None:
|
||||
|
Loading…
Reference in New Issue
Block a user