File tree Expand file tree Collapse file tree 1 file changed +71
-0
lines changed
Expand file tree Collapse file tree 1 file changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ import marimo
2+
3+ __generated_with = "0.18.0"
4+ app = marimo .App ()
5+
6+ with app .setup (hide_code = True ):
7+ from pathlib import Path
8+ from PIL import Image
9+ import marimo as mo
10+
11+ from df_font_generator .font_generator import FontGenerator
12+
13+
14+ @app .function
15+ def get_font () -> Image .Image :
16+ fg = FontGenerator ()
17+ fg .set_font (Path ("./fonts/terminus_bold.ttf" ), 14 )
18+ fg .set_charset (encoding = "cp857" )
19+
20+ # clear all canvas mode
21+ fg .clear_canvas ()
22+ fg .set_padding (0 , - 1 )
23+ fg .draw_full_charset ()
24+
25+ # Patch needed, because some chars out of they boxes
26+ # Terminus 14 patch
27+ fg .set_padding (0 , 0 )
28+ fg .redraw_characters ("≡§^~" )
29+
30+ # Encoding-specific patches
31+ fg .set_padding (0 , 1 )
32+ fg .redraw_characters ("`" )
33+
34+ fg .set_padding (0 , 0 )
35+ fg .redraw_characters ("Ñкª°¨¹²³" )
36+
37+ fg .set_padding (0 , 1 )
38+ fg .redraw_characters ("ÄÅÁÂÀÃÊËÈÓÔÒÕÚÛÙ¯´¾" )
39+ return fg .image
40+
41+
42+ @app .cell
43+ def _ (image ):
44+ # Show resulting image (upscaled to see details)
45+ preview = None
46+ if mo .running_in_notebook ():
47+ scale = 2
48+ width = image .width * scale
49+ height = image .height * scale
50+ preview = image .resize ((width , height ), Image .Resampling .NEAREST )
51+
52+ preview # type: ignore
53+ return
54+
55+
56+ @app .cell
57+ def _ ():
58+ image = get_font ()
59+ return (image ,)
60+
61+
62+ @app .cell
63+ def _ (image ):
64+ file = "cp857.png"
65+ image .save (file )
66+ print (f"File { file } written" )
67+ return
68+
69+
70+ if __name__ == "__main__" :
71+ app .run ()
You can’t perform that action at this time.
0 commit comments