make-logo.py (3895B)
1 #!/usr/bin/env python3 2 """Makes the Sector F Labs logo for Sector F Linux: the Sector F flask and the words Sector F Labs beside it, 3 as one SVG. 4 5 It is made the way the desktop's default wallpaper is (patina-desktop's 6 wallpaper/src/main.rs): the flask from system/assets/sector-f.svg and the lettering in Ubuntu 7 Mono, but with the word beside the flask, not under it, and as a single file for the places that 8 want an image (GDM's login screen). The letters are turned into outlines here, so the SVG needs 9 no font when it is drawn. 10 11 linux/branding/make-logo.py [PATINA_DESKTOP] 12 13 PATINA_DESKTOP is the checkout the flask and the font come from (default: beside patina-os). It 14 writes system/usr/share/pixmaps/seflos-logo.svg, which the image's `COPY system/ /` puts in 15 place, and needs fontTools (`pip install fonttools`, or python3-fonttools). It is all white, 16 as GDM's own logo is. 17 """ 18 19 import re 20 import sys 21 from pathlib import Path 22 23 from fontTools.pens.svgPathPen import SVGPathPen 24 from fontTools.pens.transformPen import TransformPen 25 from fontTools.ttLib import TTFont 26 27 WORD = "Sector F Labs" 28 # White, as GDM draws its own UI and the Fedora logo it shows now, on its #222226 background: 29 # the logo should look like part of the login screen, not of the desktop's wallpaper. 30 FLASK_COLOUR = "#ffffff" 31 WORD_COLOUR = "#ffffff" 32 # The word's capital height as a share of the flask's height, and the gap between them as a 33 # share of its width. 34 CAP_SHARE = 0.40 35 GAP_SHARE = 0.14 36 TRACKING = 0.04 # extra space between letters, in em 37 # The size GDM draws it at, in pixels: it shows an image at its own size, so a bare viewBox would be 38 # drawn thousands of pixels wide. Fedora's logo there is about 44 pixels tall. 39 DISPLAY_HEIGHT = 48 40 41 here = Path(__file__).resolve().parent 42 desktop = Path(sys.argv[1] if len(sys.argv) > 1 else here / "../../../patina-desktop").resolve() 43 flask_svg = (desktop / "system/assets/sector-f.svg").read_text() 44 font = TTFont(desktop / "system/assets/UbuntuMono-Regular.ttf") 45 out = here.parent / "system/usr/share/pixmaps/seflos-logo.svg" 46 47 # The flask's own drawing, between its <svg> tags, and its view box. 48 x0, y0, w, h = map(float, re.search(r'viewBox="([^"]+)"', flask_svg).group(1).split()) 49 flask = re.search(r"<svg[^>]*>(.*)</svg>", flask_svg, re.S).group(1) 50 flask = re.sub(r"<!--.*?-->", "", flask, flags=re.S).replace("currentColor", FLASK_COLOUR) 51 52 # The word as outlines: one path, in font units (y up), then scaled and flipped into place. 53 glyphs = font.getGlyphSet() 54 cmap = font.getBestCmap() 55 units = font["head"].unitsPerEm 56 cap = font["OS/2"].sCapHeight 57 scale = (h * CAP_SHARE) / cap 58 pen = SVGPathPen(glyphs) 59 x = 0.0 60 for ch in WORD: 61 name = cmap[ord(ch)] 62 glyphs[name].draw(TransformPen(pen, (1, 0, 0, 1, x, 0))) 63 x += glyphs[name].width + TRACKING * units 64 width = (x - TRACKING * units) * scale 65 66 text_x = x0 + w + w * GAP_SHARE 67 # The flask's visual centre, so the word's capitals sit on its middle. 68 centre_y = y0 + h / 2 69 baseline = centre_y + (cap * scale) / 2 70 pad = h * 0.04 71 total_w, total_h = text_x + width - x0 + 2 * pad, h + 2 * pad 72 view = f"{x0 - pad:.1f} {y0 - pad:.1f} {total_w:.1f} {total_h:.1f}" 73 display_w = round(DISPLAY_HEIGHT * total_w / total_h) 74 75 svg = f"""<svg xmlns="http://www.w3.org/2000/svg" width="{display_w}" height="{DISPLAY_HEIGHT}" viewBox="{view}" role="img" aria-label="Sector F Labs"> 76 <title>Sector F Labs</title> 77 <!-- Made by linux/branding/make-logo.py: the Sector F flask (patina-desktop's 78 system/assets/sector-f.svg) and Sector F Labs in Ubuntu Mono (Ubuntu Font Licence), as outlines. --> 79 <g>{flask}</g> 80 <path fill="{WORD_COLOUR}" transform="translate({text_x:.1f} {baseline:.1f}) scale({scale:.5f} {-scale:.5f})" d="{pen.getCommands()}"/> 81 </svg> 82 """ 83 out.parent.mkdir(parents=True, exist_ok=True) 84 out.write_text(svg) 85 print(f"wrote {out.relative_to(here.parent.parent)} ({len(svg)} bytes, view box {view})")