3
$\begingroup$

Do anyone know any algorithm which would calculate automatically kerning of characters based on glyph shapes when user types text?

I don't mean trivial calculation of advance widths or similar, I mean analyzing the shape of glyphs to estimate the visually optimal distance between characters. For example if we lay out three characters sequentially in a line, the middle character should SEEM to be in the center of the line despite of the character's shapes. An example enlightens the kerning-on-the-fly functionality:

An example of kerning-on-the-fly can be seen from below snapshot: enter image description here

In the above image a seems to be too right. It should be shifted a certain amount towards T so that it seems to be in the middle of T and g. The algorithm should examine the shapes of T and a (and possibly other letters also) and decide how much a have to be shifted to the left. This certain amount is the thing that the algorithm should calculate - WITHOUT EXAMINING THE POSSIBLE KERNING PAIRS OF THE FONT.

I'm thinking of coding a javascript (+svg+html) program that uses hand drawn fonts and many of them lacks kerning pairs. The textfields will be editable and can include text of multiple fonts. I think that kerning-on-the-fly could be one way to ensure mean text flow in this case.

EDIT: One starting point to this could be to use svg font, so it's easy to get path values. In svg font the path is defined this way:

   

The algorithm (or javascript code) should examine those paths some way and determine the optimal distance between them.

  • 0
    Because this is considered as off topic in Stackoverflow and here, I made a new try in http://graphicdesign.stackexchange.com/questions/11016/kerning-on-the-fly .2012-10-13

1 Answers 1

0

Here's an idea for how to find the kerning automatically.

For each glyph, find the convex hull of the glyph, i.e. the smallest convex shape with encloses the glyph (Convex means that if two points $a$,$b$ lie inside the shape, then the line connecting $a$ and $b$ also lies inside the shape).

Then define the distance between two glyphs $g_1$,$g_2$ the geometric distance between their convex hulls $H(g_1),H(g_2)$, i.e. $d(g_1,g_2) = \text{min }\{\||a-b||:a \in H(g_1), b \in H(g_2)\}$.

The kerning is then obtained by moving $g_2$ to the right until $d(g_1,g_2) = d$, where $d$ is some percentage of the font size or so.

  • 0
    This is a good example of one possible basic algorithm, sort of starting point. I believe that all kerning-on-the-fly implementations have one basic algorithm and several sub algorithms for fine tuning.2012-10-13