Edge and Segment Alignment |
Introduction & Background:Once segments and edges have been detected and properly linked together to reveal stems and serifs, they needed to be scaled and aligned to the pixel grid. This page explains how this process is performed in the current auto-hinter. Basic alignment strategyBecause we want to perform real-time hinting easily, we need a strategy that scales well. This means that the algorithm must be very fast at large pixel sizes (because hinting doesn't really change much things there) though takes more time at smaller pixel sizes in order to deal with specific problems of low-resolution display. A two-step method was thus chosen: on a first pass, stems and serifs are directly aligned to the pixel grid with a direct and simple algorithm. Then, for sufficiently small sizes (e.g. under 24 pixels), we measure the distortion of the generated glyph according to a set of rules defined below, and try to optimise the grid-fitted outline if the distortion falls over a certian threshold. Direct AlignmentDirect alignment is performed in each direction following a set of very simple rules:
Note that the current implementation is actually a bit more complex than that, given that we try to avoid any changes in the relative order of edges, and use some heuristics to correctly position edges on the pixel grid (basically, we take into account the first edge that was aligned, and use its delta to shift the rest of the outline). Distortion MeasurementAs stated above, direct alignment is fast and gives very good results for a large variety of glyphs and sizes. However, there are some cases where it simply doesn't generate adequate results. The following picture shows the character "e" from the Arial face, renderer at a small pixel size. As you can see, the inside contour completely disappears because of the direct alignment: As you can see, there are basically three horizontal stems in this glyph. The bottom stem is moved up-wards and the top stem down-wards due to blue zone alignement. The middle stem is aligned, but the direct alignment algorithm doesn't take all stem movements in consideration, hence that stem is moved upwards. Because all three stems are strengthened by height normalization, the inside contour disappears. We thus need a way to detect when direct alignment produces outlines that are too distorted (in this example, a "white distance" simply disappeared). XXX NOTE : For now, distortion measurement and optimisation is not implemented in the current auto-hinter, the following is a description of a method I've come up with, and trying to implement. Outline OptimisationSorry, outline optimisation isn't currently implemented. |