Technically PostScript uses cubic Bézier splines. Each control point determines the slope of the spline at the corresponding end point. TrueType uses quadratic Bézier splines, in these there is only one control point between two end points and that point determines the slope of the spline at both end points.
It is also possible to have other degree Bézier splines. For a quartic spline there would be 3 control points, for a quintic 4 control points, etc. Of these only the quadratic and cubic splines are interesting to us-- those used by TrueType and PostScript. As the example at right shows one control point is used to determine the slopes at both end points.
In general if there are n+1 points labeled P_{0}, P_{1}, ... P_{n}, with P_{0} and P_{n} the end points (and all the others control points) then the equation of the Bézier spline between them is: . If there are two points then this is just the line between the two end points, if three then the quadratic spline used by TrueType, if four then the cubic spline used by PostScript.
A cubic Bézier curve may be viewed as:
x = a_{x}*t^{3} + b_{x}*t^{2} + c_{x}*t +d_{x}
y = a_{y}*t^{3} + b_{y}*t^{2} + c_{y}*t +d_{y}
Where
d_{x }= P0.x | d_{y} = P0.y | |
c_{x} = 3*P1.x-3*P0.x | c_{y} = 3*P1.y-3*P0.y | |
b_{x} = 3*P2.x-6*P1.x+3*P0.x | b_{y} = 3*P2.y-6*P1.y+3*P0.y | |
a_{x} = P3.x-3*P2.x+3*P1.x-P0.x | a_{y} = P3.y-3*P2.y+3*P1.y-P0.y |
And a quadratic Bézier curve:
d_{x }= P0.x | d_{y} = P0.y | |
c_{x} = 2*P1.x-2*P0.x | c_{y} = 2*P1.y-2*P0.y | |
b_{x} = P2.x-2*P1.x+P0.x | b_{y} = P2.y-2*P1.y+P0.y |
Any quadratic spline can be expressed as a cubic (where the cubic term is zero). The end points of the cubic will be the same as the quadratic's.
CP_{0} = QP_{0}
CP_{3} = QP_{2}
The two control points for the cubic are:
CP_{1} = QP_{0} + 2/3 *(QP_{1}-QP_{0})
CP_{2} = CP_{1} + 1/3 *(QP_{2}-QP_{0})
So converting from TrueType to PostScript is trivial. There is a slight error introduced due to rounding, but it is unlikely to be noticeable.
(Anish Mehta points out that in truetype it is possible to specify points which are in the middle of a pixel (ie. with an x or y value ending in 1/2). These will also introduce rounding errors when converted to postscript, but here the solution is simple: Scale the em-square of the font by a factor of 2 and the problem vanishes).
Most cubic splines cannot be represented exactly by a quadratic (or even by a series of quadratics). The best that can be done is to approximate the cubic to within some margin of error. Here is a way to do that:
Start from the end of the spline and every so often (ie. within the margin of error) check to see if the one permissible quadratic approximation actually matches the cubic closely enough (the one quadratic has its end points as the end points of the interval, and its control point is determined by the intersections of the lines tangent to the cubic at the start and end of the interval).
If this approximation works then keep it as part of the result, and continue the process by advancing our start point along to the cubic spline to the end of the quadratic we just created.
(There are some slight complexities introduced because there may not be a quadratic approximation at a given point (if the tangents happen to be parallel) or because the approximation happens to be linear, but these are easily dealt with).
It may, of course, happen that the "cubic" we are given is actually a quadratic (if it's third degree term is 0), the most likely cause is that the font came from a truetype source. In that case the control point for the quadratic is at:
QP_{1} = CP_{0} + 3/2 * (CP_{1} - CP_{0})
Other sources I have read on the net suggest checking the cubic spline for points of inflection (which quadratic splines cannot have) and forcing breaks there. To my eye this actually makes the result worse, it uses more points and the approximation does not look as close as it does when ignoring the points of inflection. So I ignore them.
Adobe and Microsoft decided to produce one font format which could hold either a true type font or a postscript font. This is called Open Type. It is essentially a superset of TrueType. Any TrueType font is a valid Open Type font, but Open Type fonts can also contain postscript. Anything that supports Open Type will not require converting between PostScript and True Type.
^{1 }Bézier splines were developed by Pierre Bézier (1910-1999).