[HarfBuzz] How to perform full precision shaping (with no scaling and grid fitting)

Behdad Esfahbod behdad at behdad.org
Fri Apr 20 14:27:04 PDT 2012


On 04/20/2012 09:16 AM, Petr Filipský wrote:
> Hi,

Hi,

> I am trying to perform a shaping which is independent on a resulting device,
> so no scaling, no grid-fitting is desired.

Right.  That's the way I like my eggs too.


> In order to disable the grid-fitting and get as high precision as possible I
> thought it was sufficient to work in the font design precision - to scale the
> font to some very high value (like the /UpEm/ value), i.e. using the following
> code:
> 
> /  hb_face_t* const face( hb_ft_face_create( ft_face, NULL ) );/
> /  hb_font_t* font = hb_font_create( face );/
> /  unsigned int const upem( hb_face_get_upem (face) );/
> /  hb_font_set_scale( font, upem, upem );/
>   /hb_ft_font_set_funcs( font );/

This definitely *is* supposed to work.  But I just confirmed that it doesn't.


> But unfortunately it is not enough. The /hb_ft_get_glyph_h_kerning()/ function
> calls the /FT_Get_Kerning/ with kerning mode set to /FT_KERNING_DEFAULT/, and
> for example for /Arial font/ and /'T'/ and /'a'/ character pair (55 and 68
> glyph indices) it returns value -256 (instead of correct value -227). It if
> the scaling seems correct the function still performs some fitting. If i try
> to change the kerning mode to FT_KERNING_UNSCALED then I get the correct value
> (-227) but that is probably not a proper fix but just a hack.
> 
> Is there an elegant and efficient way to disable both scaling and fitting and
> perform a device independent full precision shaping?

I think the bug is in this line:


  FT_Set_Char_Size (ft_face,
                    font->x_scale, font->y_scale,
                    font->x_ppem * 72 * 64 / font->x_scale,
                    font->y_ppem * 72 * 64 / font->y_scale);


In this case we have (and we want) both x_ppem and y_ppem to be zero (which
mean to hinting).  However, FreeType understands the both-zero case as to mean
"default to 72dpi".  Instead we should detect these cases and fallback to
using FreeType's load flags.  Specifically FT_LOAD_NO_BITMAP |
FT_LOAD_NO_HINTING | FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_SCALE |
FT_LOAD_LINEAR_DESIGN, as well as the FT_KERNING_UNSCALED that you noted.

Maybe I add a specific constructor for this case.  Anyway, I'll try to resolve
this within a week.

behdad


> Thank you very much.
> 
> Kind regards,
> Petr
> 
> 
> 
> 
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz



More information about the HarfBuzz mailing list