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: Werner LEMBERG
Subject: Re: [ft-devel] Fetching bitmap strike size from GlyphSlot
Date: Fri, 21 Dec 2012 09:29:15 +0100 (CET)

> 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.

Perhaps something like this untested code?

  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



reply via email to

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