freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] autohinting and spacing


From: David Turner
Subject: Re: [ft-devel] autohinting and spacing
Date: Wed, 08 Aug 2007 17:07:10 +0200

Hello Graham,

this is normal, the auto-hinter basically rounds the advance widths, and also
alters the left/right bearing of a typical glyphs. this explains the spacing 
issues
you're seeing now.

fortunately, the auto-hinter also returns information about the bearing 
displacements
it makes, and it is possible to compensate this distortion by using the 
"lsb_delta" and
"rsb_delta" fields of a FT_GlyphSlot.

the algorithm to implement this is rather simple and is described in the 
documentation
for FT_GlyphSlotRec, here it is:

  /*    Here a small pseudo code fragment which shows how to use           */
  /*    `lsb_delta' and `rsb_delta':                                       */
  /*                                                                       */
  /*    {                                                                  */
  /*      FT_Pos  origin_x       = 0;                                      */
  /*      FT_Pos  prev_rsb_delta = 0;                                      */
  /*                                                                       */
  /*                                                                       */
  /*      for all glyphs do                                                */
  /*        <compute kern between current and previous glyph and add it to */
  /*         `origin_x'>                                                   */
  /*                                                                       */
  /*        <load glyph with `FT_Load_Glyph'>                              */
  /*                                                                       */
  /*        if ( prev_rsb_delta - face->glyph->lsb_delta >= 32 )           */
  /*          origin_x -= 64;                                              */
  /*        else if ( prev_rsb_delta - face->glyph->lsb_delta < -32 )      */
  /*          origin_x += 64;                                              */
  /*                                                                       */
  /*        prev_rsb_delta = face->glyph->rsb_delta;                       */
  /*                                                                       */
  /*        <save glyph image, or render glyph, or ...>                    */
  /*                                                                       */
  /*        origin_x += face->glyph->advance.x;                            */
  /*      endfor                                                           */
  /*    }                                                                  */
  /*                                                                       */

the idea is that it is possible to measure the spacing distortion between two
auto-hinted glyphs, and adjust their position accordingly. this minimizes the
error to less than 1/2 pixel and improves things dramatically.

this feature is usually called "auto-kerning", and the "ftdiff" demo program
implements it. Simply Press "d" (like "deltas") to toggle it on/off in a given
text column. You'll see that this makes a large difference in overall quality.

Sadly, this scheme is not implemented in typical Linux desktop libraries yet.

Hope this helps,

- David




On Wed, 8 Aug 2007 11:43:15 +0100, "Graham Asher" <address@hidden> said:
> Hi everybody - here is a problem that I am trying to solve myself, but
> which
> may very well have been solved already, or at least someone might have an
> idea about it.
> 
> Autohinting seems to make the space between letters wrong in many cases.
> I
> attach a small picture showing the letters "mp" in DejaVu Serif Bold at
> 16
> ppem, rendered using the grey-scale rasterizer, with no hinting above and
> auto-hinted below. The spacing is clearly wrong in the autohinted
> version.
> 
> This is very probably caused by bugs in the part of af_loader_load_g() in
> afloader.c that adjusts side bearings after auto-hinting has been done.
> 
> Suggestions welcome.
> 
> Best regards,
> 
> Graham Asher
> 




reply via email to

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