|
| 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() |
0 commit comments