Skip to content

Font generator

The Font Generator converts any TrueType or OpenType font into a JSCAD JavaScript file. Once added to your project you can render text as 2D outlines for laser cutting, or extrude them into 3D lettering for engraving and signage.

Switch to the Modelling tab in the left sidebar and click the + button next to the file list. Select New font from the dropdown. The Font Generator overlay opens on top of the workspace.

You have three options:

By name — type a font family name (e.g. Roboto, Playfair Display) into the search box and press Enter. JavaSculpt fetches it automatically.

By URL — paste a Google Fonts URL such as https://fonts.google.com/specimen/Roboto and the font is resolved for you.

Upload — drag a .ttf, .otf, .woff, or .woff2 file onto the drop zone, or click the upload button to browse.

A live preview updates in the right panel as soon as the font loads.

By default only the characters you actually need are included, keeping the generated file small. Use the checkboxes to select character classes:

Class Characters included
Decimal 0–9
Uppercase A–Z
Lowercase a–z
Common punctuation . , ! ? ( ) - _ and others
Extended Latin Accented and diacritic characters

Enable Include all glyphs to bundle the entire font — useful when the text content is not known ahead of time, but produces a much larger file.

Click Resolution… to choose how many straight-line segments are used to approximate each Bézier curve. Higher values give smoother letterforms at the cost of larger files and slower geometry operations. The default of 8 steps is a good balance for most uses; drop to 4 for screen preview work or raise to 16 for high-quality print or CNC output.

Click Add to project. The font data file is written to your workspace:

  • fonts/<font-name>.js — the font data (glyph outlines and metrics)

The font rendering helper is built in and available as @javasculpt/lib/font-loader.

Require the font file and the built-in helper, then call renderText:

const { renderText } = require('@javasculpt/lib/font-loader')
const FONT_ROBOTO = require('./fonts/roboto').FONT_DATA
function main() {
return renderText(FONT_ROBOTO, 'Hello world', { size: 20 })
}

renderText(font, text, options) returns a 2D geometry (geom2) — a flat outline of the text ready for laser-cutting export or further operations.

Option Default Effect
size 10 Cap height in JSCAD units (mm)
letterSpacing 0 Extra gap between glyphs in JSCAD units

Wrap the result with extrudeLinear to produce solid 3D lettering:

const { renderText } = require('@javasculpt/lib/font-loader')
const { extrudeLinear } = require('@jscad/modeling').extrusions
const FONT_ROBOTO = require('./fonts/roboto').FONT_DATA
function main() {
const outline = renderText(FONT_ROBOTO, 'HELLO', { size: 15 })
return extrudeLinear({ height: 4 }, outline)
}

Combine with getParameterDefinitions to let users change the text or size interactively:

const { renderText } = require('@javasculpt/lib/font-loader')
const { extrudeLinear } = require('@jscad/modeling').extrusions
const FONT_ROBOTO = require('./fonts/roboto').FONT_DATA
const getParameterDefinitions = () => [
{ name: 'text', type: 'text', caption: 'Text', default: 'HELLO' },
{ name: 'size', type: 'number', widget: 'slider', caption: 'Size (mm)', default: 15, min: 5, max: 60, step: 1 },
{ name: 'depth', type: 'number', widget: 'slider', caption: 'Extrude depth', default: 4, min: 1, max: 20, step: 0.5 },
]
function main({ text, size, depth }) {
const outline = renderText(FONT_ROBOTO, text, { size })
return extrudeLinear({ height: depth }, outline)
}

If you select a fonts/*.js file in the file tree, a Preview font… button appears in the toolbar above the editor. Click it to open a quick preview of the glyphs included in that file.