[Top][All Lists]

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

RE: [ft-devel] autohinting and spacing

From: Graham Asher
Subject: RE: [ft-devel] autohinting and spacing
Date: Wed, 8 Aug 2007 16:22:43 +0100


I saw this comment and don't really understand it or indeed (forgive me)
agree with its implications; the autohinter's effects, like those of the
standard TrueType hinter, should be transparent and not require

I understand that the auto-hinter rounds advance widths; so too do many text
rendering systems including the one I am working on; glyph metrics and
advances have to be integral pixels, which I know is not ideal, but it is
what we often have to live with.

Further, the adjustment of the advance performed by the auto-hinter is
visually wrong in some circumstances; I have a tentative fix but I need to
do some more testing.

That is because it tries to ensure that the advance preserves the same side
bearings, defined as distances from edges, neglecting serifs. Two effects
make this undesirable; rounding effects and prominent serifs. Sorry I
haven't time to go into this further but I am under great pressure. (And
unfortunately I might have to drop this investigation.)

Best regards,


-----Original Message-----
From: David Turner [mailto:address@hidden 
Sent: 08 August 2007 16:07
To: Graham Asher; address@hidden
Subject: Re: [ft-devel] autohinting and spacing

Hello Graham,

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

fortunately, the auto-hinter also returns information about the bearing
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
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
auto-hinted glyphs, and adjust their position accordingly. this minimizes
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
text column. You'll see that this makes a large difference in overall

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

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]