freetype
[Top][All Lists]
Advanced

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

Re: [Freetype] manual anti-aliasing


From: David Turner
Subject: Re: [Freetype] manual anti-aliasing
Date: Tue, 14 May 2002 23:48:42 +0200

Hello Jeff,

Jeff Chow a écrit :
> 
> Hi Everyone,
> 
> I haven't posted to this list in a while so here goes:
> We're experimenting with doing a manual antialias on all the glyphs that we
> rasterize. Instead of
> rendering a glyph at some pixel size in ft_render_mode_normal mode, we're
> quadrupling the pixel size, rendering it in ft_render_mode_mono mode, and
> manually downsampling the 1-bit output down to the right glyph size. We'd
> like the final rasterized sizes to the as similar as possible, and here's
> where the problem happens:
> 
> Suppose I specify 17 in my FT_Set_Pixel_Sizes() call and it yields a glyph
> that's 10 rows tall for the 'B' character. That's fine but when I specify 68
> (17*4) in FT_Set_Pixel_Sizes, I get back a glyph that's 36 rows tall. 36 / 4
> is 9, and *not* the 10 that we'd expect. At first I thought that rastering
> monochrome glyphs may yield smaller bitmaps, but I verified that behaviour
> with a number of different characters and pixel sizes and it seems like the
> same size glyph is always generated.
> 
> So why would rastering a large pixel size yield a disproportionately smaller
> glyph? Does anyone out there in Freetype land know what's going on? Even if
> I round up the division (36 + 3)/4 I still get a value that's 1 off from the
> real size.
>

That's because the hinting process distorts the outlines in a non-linear
(and unpredictable) way to optimize the outlines to the pixel grid at
every specific character size.

To get what you really want, you'll need to do the following:

- specify a character size corresponding to your _final_ text size
  (i.e. after filtering). For example, to generate a manually
  anti-aliased bitmaps for a character size of 12 pixels, do
  "FT_Set_Pixel_Sizes( face, 0, 12 )"
 
- also specify an additional _scaling_ transform through
  "FT_Set_Transform". You should use a scaling factor corresponding
  to the magnification level you need _before_ your filtering.

  this transform is applied to glyph outlines after they're loaded,
  but before they're scan-converted to bitmaps (either monochrome
  or anti-aliased ones by the way)

- call "FT_Load_Glyph", using the flags FT_LOAD_NO_BITMAP, FT_LOAD_RENDER,
  FT_LOAD_MONOCHROME. This ensures that you'll end up with scaled monochrome
  bitmaps of the glyphs you're interested in.

- filter the resulting bitmap correctly. Don't forget that "bitmap_left"
  and "bitmap_top" must be used to "position" the bitmap returned by
  FT_Load_Glyph into your filter space.

As far as I know, that the same technique than the one used by
XFree86's LCD-optimised rendering (it simply use a 3X scaling transform
in the horizontal direction, render to an anti-aliased bitmap, slightly
filter to reduce color fringes, and voila..., and RGB mask for each glyph)


Hope this helps,


Best Regards,

- David Turner
- The FreeType Project  (www.freetype.org)



reply via email to

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