Search code examples
algorithmfontsrenderingtruetypecurves

Rendering curves of TTF fonts


Could you point me to an effective algorithm for rendering and filling the curves used in TTF fonts? I have the data loaded as contours of points so I;m only wondering about an effective way of drawing the curves. I'd also very much like it to support smoothing.

What I know up to this point:

  1. TTF uses bezier curves and splines
  2. TTF categorizes it's points as points defining lines, and points defining curve, the latter being either on the curve in question or our of it (control points)
  3. One can make a polygon out of a curve contour where the curved parts are made of lines the size of a pixel.
  4. One could use this polygon to render the filled contour and if one also uses the data as floats rather than ints, one could achieve font smoothing.

So could you point me to a guide of some sort or something?

Thanks.


Solution

  • If you already have the vector data, then you have to rasterize it with some scanline fill algorithm. For smoothing divide the pixels into n by n blocks, rasterize the characters and compute the a gray value corresponding to the number of filled subpixels. Handling bezier curves and splines, however, is not going to be easy, I think. If it is possible, I would use a library like freetype or similar.