惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
D
Docker
GbyAI
GbyAI
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Stack Overflow Blog
Stack Overflow Blog
WordPress大学
WordPress大学
小众软件
小众软件
Engineering at Meta
Engineering at Meta
酷 壳 – CoolShell
酷 壳 – CoolShell
I
InfoQ
B
Blog
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog RSS Feed
Microsoft Security Blog
Microsoft Security Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Render any font to a crisp SVG path in the browser with o...
Zerrin Arslan · 2026-06-24 · via DEV Community

Zerrin Arslan

A designer asked me for a logo word as an SVG path — not a PNG, not "the font file," an actual <path> they could drop into Figma and a cutting machine. My first instinct was to screenshot it and trace it. Don't do that. If you have the font file, the outlines are already vectors — you just have to ask for them. Here's how I do it client-side with opentype.js.

The idea

A font glyph is a set of Bézier curves. opentype.js parses a .ttf/.otf and hands you those curves as an SVG path string. No tracing, no quality loss, no server.

Load the font and get a path

import opentype from "opentype.js";

const font = await opentype.load("/fonts/MyFont.ttf");

// getPath(text, x, y, fontSize) → a Path object
const path = font.getPath("Hello", 0, 150, 120);

// .toSVG() gives you the <path d="..."/> markup
const pathMarkup = path.toSVG(2); // 2 = decimal precision

That pathMarkup is a real vector outline of your text in that font. Wrap it in an <svg> and you're done.

Size the viewBox correctly

The gotcha is the canvas/viewBox. getPath draws from a baseline, so you need the bounding box to avoid clipping:

const bb = path.getBoundingBox(); // {x1, y1, x2, y2}
const pad = 16;
const w = (bb.x2 - bb.x1) + pad * 2;
const h = (bb.y2 - bb.y1) + pad * 2;

const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${bb.x1 - pad} ${bb.y1 - pad} ${w} ${h}">
  ${path.toSVG(2)}
</svg>`;

Now the SVG is tightly cropped to the glyphs, whatever the text.

Download it from the browser

No backend needed — make a Blob and click a link:

const blob = new Blob([svg], { type: "image/svg+xml" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "text.svg";
a.click();
URL.revokeObjectURL(a.href);

Things that bit me

  • CORS on the font fetch. opentype.load does an XHR/fetch under the hood; the font has to be same-origin or CORS-enabled or it silently fails. Self-host the file.
  • Licensing. Converting a glyph to a path is still using the font. Check the license allows it before you ship outlines of a commercial font.
  • Right-to-left / complex shaping. getPath does basic layout, not full HarfBuzz shaping. For Latin display text it's perfect; for Arabic/Indic you'll want a shaping engine.
  • Precision vs file size. toSVG(2) is plenty for cutting/printing. Higher precision just bloats the path string.

Why client-side is nice here

The whole thing runs in the browser: the user picks a font, types text, and gets an SVG without a single byte hitting a server. That's exactly how I wired up the font-to-SVG tool on FontBoxDL — handy if you want to see it in action or grab a quick cut file (it pulls from a library of 60k+ free fonts you can use as the source).

opentype.js is one of those libraries that makes a "hard" task almost embarrassingly short. If you're doing anything with fonts in JS — metrics, kerning, glyph inspection — it's worth an afternoon.

Anyone else using it in production? Curious what you've built.