From f25af3b36a43959370c28d9c04e014d9831b9e0a Mon Sep 17 00:00:00 2001 From: Bernard Ladenthin Date: Fri, 17 Jul 2026 19:15:32 +0200 Subject: [PATCH] feat(logo): add --outline-text for font-independent wordmarks Both logo generators embed MartianMono-Regular.ttf as base64 @font-face (~64 KB, ~98% of each SVG) so the wordmark can stay real . Add an opt-in --outline-text mode that converts only the used glyphs to outlines via a shared logolib.text_to_path_d() helper (fontTools SVGPathPen + TransformPen, baking a y-flipped per-glyph affine). The result carries no font and no , dropping each file to ~13-16 KB. For srcmorph the feGaussianBlur morph is preserved by moving the filters from the onto the outlined groups. Default text mode is unchanged (byte-identical output) and fontTools is imported lazily, so it is only required when --outline-text is used. Also commit the two generated outlined SVGs and document the mode and its tradeoffs (not selectable/editable, but smaller, font-independent, and robust in renderers that strip {mdefs}" if style else mdefs return f""" @@ -187,6 +212,8 @@ def main() -> None: parser.add_argument("--write-default-config", type=Path, help="Write the default JSON config and exit") parser.add_argument("--png", type=Path, help="Also rasterise a PNG (needs 'pip install resvg-py')") parser.add_argument("--png-width", type=int, default=2250) + parser.add_argument("--outline-text", action="store_true", + help="Emit the wordmark as outlines (no embedded font, no )") args = parser.parse_args() if args.write_default_config: @@ -194,6 +221,9 @@ def main() -> None: return config = logolib.load_config(SrcmorphConfig, args.config) + if args.outline_text: + from dataclasses import replace + config = replace(config, outline_text=True) svg = build_svg(config) args.output.write_text(svg, encoding="utf-8") diff --git a/llama.cpp/projects/logo/java-llama-cpp-outlined.svg b/llama.cpp/projects/logo/java-llama-cpp-outlined.svg new file mode 100644 index 0000000..2e4b4d2 --- /dev/null +++ b/llama.cpp/projects/logo/java-llama-cpp-outlined.svg @@ -0,0 +1,19 @@ + + + java-llama.cpp cover + Shard J icon in the llama.cpp style with an outlined wordmark. + + + + + + + + + + + + + + diff --git a/llama.cpp/projects/logo/logolib.py b/llama.cpp/projects/logo/logolib.py index c3ec62b..95dc90b 100644 --- a/llama.cpp/projects/logo/logolib.py +++ b/llama.cpp/projects/logo/logolib.py @@ -54,6 +54,65 @@ def clamp01(v: float) -> float: return max(0.0, min(1.0, v)) +_FONT_CACHE: dict = {} + + +def _load_font(font_path: str): + """Load (and cache) a ``TTFont`` for outline extraction.""" + path = Path(font_path) if font_path else DEFAULT_FONT + key = str(path) + if key not in _FONT_CACHE: + if not path.exists(): + raise SystemExit(f"Font not found for outlining: {path}") + from fontTools.ttLib import TTFont # lazy: only needed for --outline-text + + _FONT_CACHE[key] = TTFont(key) + return _FONT_CACHE[key] + + +def text_to_path_d( + text: str, + font_size: float, + x0: float, + baseline: float, + letter_spacing: float = 0.0, + font_path: str = "", +) -> "tuple[str, float]": + """Convert a text run to one SVG path ``d`` string using the font outlines. + + Each glyph outline is baked into a shared path via a per-glyph affine that + scales font units to user units and flips y (font y-up -> SVG y-down): + ``(s, 0, 0, -s, x, baseline)`` with ``s = font_size / unitsPerEm``. Advances + come from the font's ``hmtx`` (monospaced 700/1000 for Martian Mono), so the + glyphs land on exactly the same x-positions the ```` layout produces. + + Returns ``(d, end_x)`` where ``end_x`` is the pen position after the run, so + callers can chain differently-coloured runs (e.g. ``java-`` then ``llama.cpp``). + """ + from fontTools.pens.svgPathPen import SVGPathPen + from fontTools.pens.transformPen import TransformPen + + font = _load_font(font_path) + upm = font["head"].unitsPerEm + cmap = font.getBestCmap() + glyph_set = font.getGlyphSet() + hmtx = font["hmtx"] + scale = font_size / upm + + pen = SVGPathPen(glyph_set) + x = x0 + for ch in text: + gname = cmap.get(ord(ch)) + if gname is None: + # No glyph for this codepoint: advance by the monospace default so + # spacing stays intact even if the mark is missing. + x += (MM_ADVANCE / upm) * font_size + letter_spacing + continue + glyph_set[gname].draw(TransformPen(pen, (scale, 0, 0, -scale, x, baseline))) + x += hmtx[gname][0] * scale + letter_spacing + return pen.getCommands(), x + + def font_face_rule(font_path: str, family: str, weight: int) -> str: """Return the bare ``@font-face { ... }`` rule with the font base64-embedded. diff --git a/llama.cpp/projects/logo/srcmorph-outlined.svg b/llama.cpp/projects/logo/srcmorph-outlined.svg new file mode 100644 index 0000000..a8d3fc2 --- /dev/null +++ b/llama.cpp/projects/logo/srcmorph-outlined.svg @@ -0,0 +1,15 @@ + + + srcmorph cover + Wordmark with a morphing (blurred, smearing) m in "morph". + + + + + + + + + +