"""Génère les favicons « Sh » à partir des glyphes Epilogue variable. Usage : python3 favicon-gen.py """ import sys, os from fontTools.ttLib import TTFont from fontTools.varLib.instancer import instantiateVariableFont from fontTools.pens.svgPathPen import SVGPathPen from fontTools.pens.boundsPen import BoundsPen F = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../fonts/epilogue/") UP, IT = "Epilogue-VariableFont_wght.ttf", "Epilogue-Italic-VariableFont_wght.ttf" def glyph(font, ch, w): f = instantiateVariableFont(TTFont(F + font), {"wght": w}) gs = f.getGlyphSet(); name = f.getBestCmap()[ord(ch)] p = SVGPathPen(gs); gs[name].draw(p) b = BoundsPen(gs); gs[name].draw(b) return p.getCommands(), b.bounds def make(out, letters, gap=40): parts, x = [], None for font, ch, w in letters: d, b = glyph(font, ch, w) dx = -b[0] if x is None else x + gap - b[0] parts.append((d, dx, b)); x = dx + b[2] x0 = 0; W = x y0 = min(b[1] for _, _, b in parts); y1 = max(b[3] for _, _, b in parts); H = y1 - y0 S, pad = 1000, 140; sc = (S - 2 * pad) / max(W, H) tx = pad + ((S - 2 * pad) - W * sc) / 2 ty = pad + ((S - 2 * pad) - H * sc) / 2 + y1 * sc paths = "".join(f'' for d, dx, _ in parts) open(out, "w").write( f'' f'' f'{paths}') o = sys.argv[1] # S italique très gras, h droit fin (contraste du logo « Le Shed »). make(o + "/favicon.svg", [(IT, "S", 900), (UP, "h", 100)]) # 180 px et plus make(o + "/favicon-tab.svg", [(IT, "S", 900), (UP, "h", 300)]) # onglets make(o + "/favicon-small.svg", [(IT, "S", 900), (UP, "h", 400)]) # ico 16/32 # variante inverse, pour comparaison make(o + "/alt.svg", [(IT, "S", 100), (UP, "h", 900)]) make(o + "/alt-small.svg", [(IT, "S", 400), (UP, "h", 900)])