freetype
[Top][All Lists]
Advanced

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

[ft] Freetype memory allocation


From: Vincenzo NZ
Subject: [ft] Freetype memory allocation
Date: Fri, 8 Sep 2017 21:21:13 +0200

Hi all,
I have a little problem with freetype memory allocation.
Basically I start from the tutorial example:

FT_GlyphSlot  slot = face->glyph;  /* a small shortcut */
int           pen_x, pen_y, n;


... initialize library ...
... create face object ...
... set character size ...

pen_x = 300;
pen_y = 200;

for ( n = 0; n < num_chars; n++ )
{
  FT_UInt  glyph_index;


  /* retrieve glyph index from character code */
  glyph_index = FT_Get_Char_Index( face, text[n] );

  /* load glyph image into the slot (erase previous one) */
  error = FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
  if ( error )
    continue;  /* ignore errors */

  /* convert to an anti-aliased bitmap */
  error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL );
  if ( error )
    continue;

  /* now, draw to our target surface */
  my_draw_bitmap( &slot->bitmap,
                  pen_x + slot->bitmap_left,
                  pen_y - slot->bitmap_top );

  /* increment pen position */
  pen_x += slot->advance.x >> 6;
  pen_y += slot->advance.y >> 6; /* not useful for now */
}

My main problem is that in my application *my_draw_bitmap* does not
immediately draw the bitmap but instead adds the operation in a sort of
queue that will be later flushed. The problem is that freetype at every new
loop deallocates the memory allocated for the bitmap invalidating the
address passed to *my_draw_bitmap*. I cannnot move the flush of the drawing
operations at the end of the for loop for performances reason of my
embedded application. Is there a clean way to avoid the automatic memory
deallocation in freetype?

Thank You
Vincenzo


reply via email to

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