freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] Fetching bitmap strike size from GlyphSlot


From: Behdad Esfahbod
Subject: Re: [ft-devel] Fetching bitmap strike size from GlyphSlot
Date: Fri, 21 Dec 2012 14:59:31 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0

On 12-12-21 03:29 AM, Werner LEMBERG wrote:
> 
>> I like to make cairo resize bitmap strikes when the requested and
>> returned size are drastically different.  Think about it this way:
>> You request a glyph at size 80ppem, and FreeType returns an image at
>> 16ppem because that's the biggest size the font had and the font is
>> not scalable.  I like to detect that and make cairo resize the
>> image.  So far, I have found no way in to detect that easily, short
>> of finding this out myself before asking FreeType to render the
>> glyphs.
> 
> FreeType doesn't return a 16ppem glyph image at 80ppem for a bitmap
> font; this rather causes an error.

Really?  Even with SFNT-based bitmap-only fonts?  That's definitely not what
I'm observing.

> Perhaps something like this untested code?

Right.  That's what I was afraid of.  It's so hard planting that logic into a
code otherwise using FreeType to load glyphs.  To contrast, all I need is a
function to return the chosen strike.  Maybe I implement that instead.

Thanks,

behdad

>   FT_Int my_strike_index;
> 
>   FT_Int min_x_ppem_index = -1;
>   FT_Int min_y_ppem_index = -1;
> 
>   FT_Pos min_x_ppem_delta = 0xFFFF << 6;
>   FT_Pos min_y_ppem_delta = 0xFFFF << 6;
> 
> 
>   if (FT_HAS_FIXED_SIZES(face))
>   {
>     for (FT_Int i = 0; i < face->num_fixed_sizes; i++)
>     {
>       FT_Bitmap_Size* bsize = face->available_sizes + i;
> 
>       FT_Pos x_ppem_delta = abs(bsize->x_ppem - my_x_ppem);
>       FT_Pos y_ppem_delta = abs(bsize->y_ppem - my_y_ppem);
> 
> 
>       if (x_ppem_delta < min_x_ppem_delta)
>       {
>         min_x_ppem_delta = x_ppem_delta;
>         min_x_ppem_index = i;
>       }
> 
>       if (y_ppem_delta < min_y_ppem_delta)
>       {
>         min_y_ppem_delta = y_ppem_delta;
>         min_y_ppem_index = i;
>       }
>     }
>   }
> 
>   my_strike_index = (x_ppem_delta < y_ppem_delta)
>                       ? min_x_ppem_index
>                       : min_y_ppem_index;
>   my_strike_x_ppem = face->available_sizes[my_strike_index].x_ppem;
>   my_strike_y_ppem = face->available_sizes[my_strike_index].y_ppem;
> 
> The next step is trying to load the glyph.  If this causes an error
> because the glyph isn't available in the strike, repeat the above
> process (omitting the just rejected strike) until you get a hit.
> 
> 
>      Werner
> 

-- 
behdad
http://behdad.org/



reply via email to

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