freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Devel] Hinting metrics


From: Reino Ruusu
Subject: Re: [Devel] Hinting metrics
Date: Fri, 4 Jul 2003 22:55:02 +0300 (EEST)

On Fri, 4 Jul 2003, David Chester wrote:
>
> In the grand scheme of things, I think uniformly increasing kerning
> values would do more harm than good.
>
> A better way to improve kerning would be to keep track of errors due
> to rounding, pass them to the next level up (e.g. Xft), and then
> make adjustments at that time if necessary.  For instance, if the
> right boundary of a character is rounded left, and the left boundary
> of the subsequent character is rounded right, and further, if the
> magnitude of the errors taken together exceeds half a pixel, then
> this should be corrected.  Under the conditions just described,
> glyphs would be kerned too closely, and a pixel's worth of white
> space should added between them.
>
> Here's a graphic showing three examples: the output from an
> unmodified freetype, the previously proposed solution which would
> increasing kerning values across the board, and finally, my solution
> as described above:
>
> http://www.cs.mcgill.ca/~dchest/kern.png

I think that looks very nice, and you are absolutely right in saying that
the kerning should be adjusted between a pair of adjacent characters.

I think though, that it is justifiable to not always blindly round the
kerning values to the nearest pixel. Thinking in terms of the viewer, if
we have a gap half a pixel wide, making it go to zero (infinitely smaller)
is a much larger error than increasing it to a single pixel (100 %
larger).

On Fri, 4 Jul 2003, Werner LEMBERG wrote:
>
> Very nice!  Anyway, I think that Reino's idea -- as presented in the
> second version of his algorithm -- is still a good one: Look e.g. at
> the `co' in the word `second' which your kerning patch doesn't fix.

Whoops. I think I posted that second version only to Werner. Here it is
again for the list:

On Thu, 3 Jul 2003, Werner LEMBERG wrote:

> I now looked at them and I think that the spacing is far too big
> everywhere.  Almost all glyph widths change.  Have you tried smaller
> values (e.g adding 1/8th of a pixel instead of 1/4th)?

Hi. I succeeded in improving it somewhat. Here is another simple
alternative:
      /* we now need to hint the metrics according to the change in */
      /* width/positioning that occured during the hinting process  */
      {
        FT_Pos   old_advance, old_rsb, old_lsb, new_lsb;
        AH_Edge  edge1 = outline->vert_edges;     /* leftmost edge  */
        AH_Edge  edge2 = edge1 +
                         outline->num_vedges - 1; /* rightmost edge */


        old_advance = hinter->pp2.x;
        old_rsb     = old_advance - edge2->opos;
        old_lsb     = edge1->opos;
        new_lsb     = edge1->pos;

        hinter->pp1.x = ( ( new_lsb    - old_lsb ) + 32 ) & -64;
        hinter->pp2.x = ( ( edge2->pos + old_rsb ) + 32 ) & -64;

        /* dont let non-negligible gaps close up */
        if ( old_lsb > 20 && edge1->pos - hinter->pp1.x < 4 )
          hinter->pp1.x -= 64;
        if ( old_rsb > 20 && hinter->pp2.x - edge2->pos < 4 )
          hinter->pp2.x += 64;

What the code says is this: if a previously non-negligible gap is made
negligible after hinting, add one extra pixel of space. This leaves alone
places where the glyph is naturally close to the boundary before hinting
(like italics) and only adds an extra pixel of space if an existing gap is
made really small.

-- 
Reino Ruusu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]