Stroke templates


Using a horizontal-stroke template called “héng” as the example, this page shows how to create a stroke template, set up its parameters, and use it in glyphs as a component.

  1. Stroke templates and components
  2. Add a template and control parameters
  3. Edit the template’s layers
  4. Insert a component into a glyph
  5. Adjust component parameters and position
  6. Edit the template to update every component
  7. Decompose into contours

Key concepts

Term Description
Stroke template The definition of a stroke, stored in the font’s stroke template library. Can have control parameters
Control parameter An adjustable value on the template, such as the length of a horizontal stroke. Each parameter has a minimum, maximum and default
Master layers The template’s contours at either end of a parameter. For values in between, the contour is interpolated from the layers
Component A single use of a template in a glyph. Each component has its own parameter values, position, scale and rotation

When you edit a template, every component that uses it updates too—the equivalent of Smart Components in Glyphs.

Stroke template library

The library sits in the lower half of the Glyphs overview. Each card can be assigned a stroke type (horizontal, vertical, left-falling, right-falling, dot, rising, hook, turning, other) and offers Edit, Duplicate and Delete.

Stroke template library

Button Function
+ New template Create a blank template and open the template editor
Import template JSON Import a previously exported template file
Edit Open the template editor
Duplicate Make a copy, handy for similar strokes
Delete Delete the template. This can’t be undone

Add a template

  1. In the library, click + New template to open the template editor.
  2. Enter the template name in the name field at the top.

A new blank template

The template editor has the same toolbar as the glyph editor; see Making a variable font for drawing. The left panel adds a Control parameters section, and there are Import JSON and Export JSON buttons at the top.

Add a control parameter

  1. Under Control parameters, click +.
  2. Enter a name plus min, max and default. Here: width, 10, 100, 50.
  3. Click Add.

Entering a control parameter

Master layers now shows a layer for each end of the parameter: width=10 and width=100.

Layers at each end of the parameter

Select a parameter and click - to remove it.

Edit the template’s layers

The rest of this page uses the existing template “héng”. Click Edit in the library to open it.

The héng template

Click width under Control parameters to change its name and range.

Control parameter settings

Click a layer under Master layers to edit the contour for that parameter value. At width=10 héng is a short stroke and at width=100 a long one; the ending has the same shape, and only the stroke length differs.

The width=100 layer

Check layer compatibility

All layers need the same number of contours, the same number of nodes and the same start points to interpolate. Press Shift + Q to open the compatibility view; green means they match.

Layer compatibility view

Insert a component into a glyph

We’ll build 三 from three héng components.

  1. Open the glyph editor. The Components tab in the right panel lists the stroke template library.

Components panel in the glyph editor

  1. Click the héng thumbnail to insert a component onto the canvas. Components are shown with a gray fill and are automatically named heng1.cpn.

Inserted component

Adjust a component

Click a component to select it; a control panel appears in the bottom-right of the editing area.

Component control panel

Field Function
Parameter slider (width here) Adjust the template’s control parameter
X / Y Position
Sx / Sy Horizontal / vertical scale
Rotation Rotation angle
Decompose Convert to regular contours, unlinked from the template
Delete Delete the component

Set width to 65: the stroke gets longer while the ending keeps its shape.

Adjusting width

Type a position into X and Y, or drag the selected component.

Moving a component

Action Function
Click a component Select
Shift + click Add to selection
Ctrl + click Invert
Drag selected components Move; Shift constrains direction
Alt + drag a component Move a copy
Arrow keys / Shift + arrow keys Nudge 1 / 10 units
Delete / Backspace Delete
Double-click a component Open the template editor
Double-click the component name in the panel Rename

Finish 三

Insert two more components and set their parameters and positions.

Component width X Y
heng1.cpn 65 126 -345
heng2.cpn 50 178 -95
heng3.cpn 90 40 185

三 made of three components

Hold Space to see the filled result.

Fill preview

Edit the template to update every component

Double-click any component to open the template editor and edit the contours. Here, the top node at the stroke ending is moved up 40 units on both layers.

Editing the template

Back in 三, the endings of all three components have changed, while each keeps its own width and position.

Components updated

When editing a template, make the same change on every layer, or the shapes at either end of the parameter will no longer match.

Decompose into contours

Select a component and click Decompose in the control panel to turn it into regular contours whose nodes you can edit directly. Decomposed contours no longer follow template updates.

Decomposed contours

Export and import templates

Export JSON at the top of the template editor saves the current template to a file; Import JSON, or Import template JSON in the library, loads it into another font.

Further reading