Skip to content

Commit b93f1c0

Browse files
Add ShowFonts app
1 parent 2385f07 commit b93f1c0

File tree

4 files changed

+185
-0
lines changed

4 files changed

+185
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "ShowFonts",
3+
"publisher": "MicroPythonOS",
4+
"short_description": "Show installed fonts",
5+
"long_description": "Visualize the installed fonts so the user can check them out.",
6+
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.showfonts/icons/com.micropythonos.showfonts_0.0.1_64x64.png",
7+
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.showfonts/mpks/com.micropythonos.showfonts_0.0.1.mpk",
8+
"fullname": "com.micropythonos.showfonts",
9+
"version": "0.0.1",
10+
"category": "development",
11+
"activities": [
12+
{
13+
"entrypoint": "assets/showfonts.py",
14+
"classname": "ShowFonts",
15+
"intent_filters": [
16+
{
17+
"action": "main",
18+
"category": "launcher"
19+
}
20+
]
21+
}
22+
]
23+
}
24+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from mpos.apps import Activity
2+
import lvgl as lv
3+
4+
class ShowFonts(Activity):
5+
def onCreate(self):
6+
screen = lv.obj()
7+
#cont.set_size(320, 240)
8+
#cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.AUTO)
9+
#cont.set_scroll_dir(lv.DIR.VER)
10+
11+
# Make the screen focusable so it can be scrolled with the arrow keys
12+
focusgroup = lv.group_get_default()
13+
if focusgroup:
14+
focusgroup.add_obj(screen)
15+
16+
fonts = [
17+
(lv.font_montserrat_16, "Montserrat 16"),
18+
(lv.font_unscii_16, "Unscii 16"),
19+
(lv.font_unscii_8, "Unscii 8"),
20+
(lv.font_dejavu_16_persian_hebrew, "DejaVu 16 Persian/Hebrew"),
21+
]
22+
23+
dsc = lv.font_glyph_dsc_t()
24+
y = 4
25+
26+
for font, name in fonts:
27+
title = lv.label(screen)
28+
title.set_text(name)
29+
title.set_style_text_font(lv.font_montserrat_16, 0)
30+
title.set_pos(4, y)
31+
y += title.get_height() + 20
32+
33+
line_height = font.get_line_height() + 4
34+
x = 4
35+
36+
for cp in range(0x20, 0xFFFF + 1):
37+
if font.get_glyph_dsc(font, dsc, cp, cp):
38+
lbl = lv.label(screen)
39+
lbl.set_style_text_font(font, 0)
40+
lbl.set_text(chr(cp))
41+
lbl.set_pos(x, y)
42+
43+
x += 20
44+
if x + 20 > screen.get_width():
45+
x = 4
46+
y += line_height
47+
48+
y += line_height
49+
50+
screen.set_height(y + 20)
51+
self.setContentView(screen)
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Generate a 64x64 PNG icon with transparent background for the "ShowFonts" app.
4+
The icon features a stylized bold 'F' with a subtle font preview overlay,
5+
using modern flat design with vibrant colors.
6+
"""
7+
8+
import cairo
9+
from pathlib import Path
10+
11+
def create_showfonts_icon(output_path: str = "ShowFonts_icon.png"):
12+
# Icon dimensions
13+
WIDTH, HEIGHT = 64, 64
14+
RADIUS = 12 # Corner radius for rounded square background
15+
16+
# Create surface with alpha channel
17+
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
18+
ctx = cairo.Context(surface)
19+
20+
# Fully transparent background
21+
ctx.set_source_rgba(0, 0, 0, 0)
22+
ctx.paint()
23+
24+
# === Draw subtle rounded background (optional soft glow base) ===
25+
ctx.save()
26+
rounded_rect(ctx, 4, 4, 56, 56, RADIUS)
27+
ctx.set_source_rgba(0.1, 0.1, 0.1, 0.15) # Very subtle dark overlay
28+
ctx.fill()
29+
ctx.restore()
30+
31+
# === Main colorful gradient background ===
32+
ctx.save()
33+
rounded_rect(ctx, 6, 6, 52, 52, RADIUS - 2)
34+
35+
# Create radial gradient for depth
36+
grad = cairo.RadialGradient(32, 20, 5, 32, 32, 30)
37+
grad.add_color_stop_rgb(0, 0.25, 0.6, 1.0) # Bright blue center
38+
grad.add_color_stop_rgb(0.7, 0.1, 0.4, 0.9) # Mid tone
39+
grad.add_color_stop_rgb(1, 0.05, 0.25, 0.7) # Deep blue edge
40+
ctx.set_source(grad)
41+
ctx.fill()
42+
ctx.restore()
43+
44+
# === Draw bold stylized 'F' ===
45+
ctx.save()
46+
ctx.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD)
47+
ctx.set_font_size(38)
48+
49+
# Position 'F' centered
50+
x_bearing, y_bearing, text_width, text_height = ctx.text_extents("F")[:4]
51+
x = 32 - text_width / 2 - x_bearing
52+
y = 38 - text_height / 2 - y_bearing
53+
54+
ctx.move_to(x, y)
55+
ctx.set_source_rgb(1.0, 1.0, 1.0) # Pure white
56+
ctx.show_text("F")
57+
ctx.restore()
58+
59+
# === Add small font preview overlay (Aa) ===
60+
ctx.save()
61+
ctx.select_font_face("Serif", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_NORMAL)
62+
ctx.set_font_size(11)
63+
64+
extents = ctx.text_extents("Aa")
65+
x = 32 - extents.width / 2 - extents.x_bearing
66+
y = 50 - extents.height / 2 - extents.y_bearing
67+
68+
# Shadow for depth
69+
ctx.move_to(x + 0.5, y + 0.5)
70+
ctx.set_source_rgba(0, 0, 0, 0.3)
71+
ctx.show_text("Aa")
72+
73+
# Main text
74+
ctx.move_to(x, y)
75+
ctx.set_source_rgb(1.0, 1.0, 0.7) # Light yellow
76+
ctx.show_text("Aa")
77+
ctx.restore()
78+
79+
# === Add subtle highlight on 'F' ===
80+
ctx.save()
81+
ctx.set_line_width(1.5)
82+
ctx.set_source_rgba(1, 1, 1, 0.4)
83+
84+
# Top bar highlight
85+
ctx.move_to(14, 20)
86+
ctx.line_to(26, 20)
87+
ctx.stroke()
88+
89+
# Middle bar highlight
90+
ctx.move_to(14, 29)
91+
ctx.line_to(23, 29)
92+
ctx.stroke()
93+
ctx.restore()
94+
95+
# Save to PNG
96+
surface.write_to_png(output_path)
97+
print(f"Icon saved to: {Path(output_path).resolve()}")
98+
99+
def rounded_rect(ctx, x, y, width, height, radius):
100+
"""Draw a rounded rectangle path"""
101+
from math import pi
102+
ctx.move_to(x + radius, y)
103+
ctx.arc(x + width - radius, y + radius, radius, pi * 1.5, pi * 2)
104+
ctx.arc(x + width - radius, y + height - radius, radius, 0, pi * 0.5)
105+
ctx.arc(x + radius, y + height - radius, radius, pi * 0.5, pi)
106+
ctx.arc(x + radius, y + radius, radius, pi, pi * 1.5)
107+
ctx.close_path()
108+
109+
if __name__ == "__main__":
110+
create_showfonts_icon()
3.5 KB
Loading

0 commit comments

Comments
 (0)