Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

3.3 KB
Raw Blame
"""Writes crates/rf-app/assets/rustyfiles-wordmark.svg: the logo (assets/rustyfiles.svg) beside the name, "rusty" in ink and
"files" in ember, with the letters drawn as outlines from Bricolage Grotesque 96pt SemiBold (assets/fonts), so the file is the
whole picture on its own: no font needed to show it. The speed test card and the About page draw it; the site and posts can
use it as it is.

    python tools/make_wordmark.py      (needs fonttools and uharfbuzz)

The ink colour is #f2f0ec (for dark backgrounds); the app swaps it for a dark one on a light theme.
"""
import re
from pathlib import Path

import uharfbuzz as hb
from fontTools.pens.svgPathPen import SVGPathPen
from fontTools.pens.transformPen import TransformPen
from fontTools.ttLib import TTFont

ROOT = Path(__file__).resolve().parent.parent
ASSETS = ROOT / "crates" / "rf-app" / "assets"
FONT = ASSETS / "fonts" / "BricolageGrotesque96pt-SemiBold.otf"
INK, EMBER = "#f2f0ec", "#ff6a1a"

LOGO_SIZE = 1000.0  # the logo is drawn in a square this big
TEXT_SIZE = 640.0  # the name's font size, in the same units
GAP = 120.0  # between the logo and the name
TRACKING = -0.03  # letter spacing, in ems (the posts' headlines are set a little tight)


def shape(font_bytes, text):
    face = hb.Face(font_bytes)
    font = hb.Font(face)
    buf = hb.Buffer()
    buf.add_str(text)
    buf.guess_segment_properties()
    hb.shape(font, buf, {"kern": True, "liga": True})
    return [(info.codepoint, pos.x_advance, pos.x_offset, pos.y_offset) for info, pos in zip(buf.glyph_infos, buf.glyph_positions)]


def main():
    data = FONT.read_bytes()
    tt = TTFont(FONT)
    upem = tt["head"].unitsPerEm
    glyphs = tt.getGlyphSet()
    order = tt.getGlyphOrder()
    scale = TEXT_SIZE / upem
    cap = tt["OS/2"].sCapHeight * scale
    xh = tt["OS/2"].sxHeight * scale
    # the name sits so that its x-height is centred on the folder's body (the lower part of the logo square)
    baseline = LOGO_SIZE * 0.80
    x = LOGO_SIZE + GAP
    parts = []
    for word, colour in (("rusty", INK), ("files", EMBER)):
        pen = SVGPathPen(glyphs)
        for gid, adv, xo, yo in shape(data, word):
            # font units have y up; the SVG has y down
            t = TransformPen(pen, (scale, 0, 0, -scale, x + xo * scale, baseline - yo * scale))
            glyphs[order[gid]].draw(t)
            x += adv * scale + TRACKING * TEXT_SIZE
        parts.append(f'<path fill="{colour}" d="{pen.getCommands()}"/>')
    width = x - TRACKING * TEXT_SIZE

    logo = (ASSETS / "rustyfiles.svg").read_text(encoding="utf-8")
    m = re.search(r'<svg[^>]*viewBox="([^"]+)"[^>]*>(.*)</svg>', logo, re.S)
    view, body = m.group(1), m.group(2).strip()
    out = (
        "<!-- rustyfiles wordmark: the logo and the name, letters as outlines (Bricolage Grotesque, SIL OFL 1.1, see fonts/OFL.txt). "
        "Made by tools/make_wordmark.py. -->\n"
        f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width:.1f} {LOGO_SIZE:.0f}">\n'
        f'<svg x="0" y="0" width="{LOGO_SIZE:.0f}" height="{LOGO_SIZE:.0f}" viewBox="{view}">\n{body}\n</svg>\n'
        + "\n".join(parts)
        + "\n</svg>\n"
    )
    (ASSETS / "rustyfiles-wordmark.svg").write_text(out, encoding="utf-8", newline="\n")
    print(f"{ASSETS / 'rustyfiles-wordmark.svg'}: {width:.0f} x {LOGO_SIZE:.0f}, cap {cap:.0f}, x-height {xh:.0f}")


if __name__ == "__main__":
    main()