Text on a Path (or Text Warping)

A Work in Progress

This is a quick study of the different ways that Inkscape can be used to distort text.

Motivation

SVG allows text to be placed along a path. Normally the glyphs are just placed along the path with no distortion to the glyphs themselves. The <textPath> method attribute can be set to "stretch" in which case "the glyph outlines will be converted into paths, and then all end points and control points will be adjusted to be along the perpendicular vectors from the path, thereby stretching and possibly warping the glyphs. With this approach, connected glyphs, such as in cursive scripts, will maintain their connections." See SVG 1.1 2nd Edition. Few SVG renders actually implement this feature, Opera being one.

Text placed around circle.
SVG
Text placed around circle.
PNG (as rendered by Opera)
Examples of <textPath>. For each figure: left: method="align", right: method="stretch".

While in some cases using "stretch" can lead to better results, Opera's implementation is still not optimal when one has wide glyphs as seen below.

Text placed around circle.
SVG
Text placed around circle.
PNG (as rendered by Opera)
Examples of <textPath>. For each figure: left: method="align", right: method="stretch".

It has been noted in an email from Israel Eisenberg that the SVG Spec doesn't define exactly how to implement "stretch". He suggests that the best option would be to distort glyphs so that "all points will be adjusted to be along the perpendicular vectors from the path, preserving vertical distance from the path." He has some examples that are quite compelling in this regard:

As a practical matter, these demonstrations seem to be done by adding hundreds of nodes to each glyph (in one case a B has 481 nodes).

Israel has also proposed allowing text to stretch between a lower path and an upper path. He has created a number of examples.

Inkscape Extensions and Live Path Effects

Generic distortion or warping of shapes is an often asked for feature of Inkscape (as is a perspective transform) and Inkscape provides a number of ways of accomplishing that. Distorting text can be as a subclacss of this. In the following study, two problems specific to text can be noted:

  1. Text must be converted to a path before warping.
  2. The distortions are based on the bounding box of the path rather than on the text properties like baseline.

Inkscape methods to distort shapes can be divided into two groups: Extensions (typically written in Python) which modify a path permanently, and Live Path Effects (written in C++) which non-destructively change a path (the original path is stored in the Inkscape namespace).

Extensions

In general, extensions work by moving nodes and control points. Straight lines remain straight.

Live Path Effects

In general, a path is converted to an SBasis (Symmetric power basis) polynomial representation, transformed, and then converted back to Bezier curves. This is done using the lib2geom library package. (SBasis curves are described by functions defined over the interval t in [0, 1] with terms in the form Pi,j(t) = ti(1-t)j.)

Additional References