freetype-devel
[Top][All Lists]
Advanced

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

AW: AW: [Devel] Leaking FT_Glyph_To_Bitmap


From: Patrick Hoffmann
Subject: AW: AW: [Devel] Leaking FT_Glyph_To_Bitmap
Date: Thu, 23 Jan 2003 00:56:20 +0100

Hi David,

Thanx for your help. The idea you have now fits my problem exactly ;)

I got my code from the Tutorial II/4b "Centering". There this code is
included:

      // compute string dimensions in integer pixels
      string_width  = (string_bbox.xMax - string_bbox.xMin);
      string_height = (string_bbox.yMax - string_bbox.yMin);

      // compute start pen position in 26.6 cartesian pixels
      start_x = (( my_target_width  - string_width )/2)*64;
      start_y = (( my_target_height - string_height)/2)*64;

      for ( n = 0; n < num_glyphs; n++ )
      {
        FT_Glyph  image;
        FT_Vector pen;

        image = glyphs[n];

        pen.x = start_x + pos[n].x;
        pen.y = start_y + pos[n].y;

        error = FT_Glyph_To_Bitmap( image, ft_render_mode_normal, &pen,
0 );
        if (!error)
        {
          FT_BitmapGlyph  bit = (FT_BitmapGlyph)image;

          my_draw_bitmap( bit->bitmap,
                          bit->left,
                          my_target_height - bit->top );

          FT_Done_Glyph( image );
        }
      }

I think someone (how's responsible for it) should change the code in
this tutorial to avoid misunderstanding in future because this code
leaks. 

Keep on freetyping! I love your library - it works very fine on an
embeeded linux system with a minimum of available resources! 

By the way: I've made a very easy and short integration of basic
freetype capabilities into the svgalib library. If I'll get time to do
so and if someone may be interested in, I should publish this code,
because the only integration I've found in the net is very complicated.

> -----Ursprüngliche Nachricht-----
> Von: address@hidden
> [mailto:address@hidden Im Auftrag von David Turner
> Gesendet: Donnerstag, 23. Januar 2003 00:04
> An: address@hidden
> Betreff: Re: AW: [Devel] Leaking FT_Glyph_To_Bitmap
>
>
> Hello Patrick,
>
>    I believe that what is really confusing is that the function
>    FT_Glyph_To_Bitmap creates a new FT_Glyph and overwrites the
>    source's handle to point to it in case of success (in case of
>    failure, the original pointer is left untouched)
>
>    we'd probably provide a better way to perform the same thing,
>    what about:
>
>    FT_EXPORT( FT_Error )
>    FT_Get_Glyph_Bitmap( FT_Glyph         source,
>                         FT_Render_Mode   render_mode,
>                         FT_Vector*       origin,
>                         FT_BitmapGlyph  *aglyph );
>
>    with this function, the code for FT_Get_Glyph_Bitmap really
>    becomes:
>
>    FT_Error
>    FT_Glyph_To_Bitmap( FT_Glyph       *the_glyph,
>                        FT_Render_Mode  render_mode,
>                        FT_Vector*      origin,
>                        FT_Bool         destroy )
>    {
>      FT_Error         error;
>      FT_BitmapGlyph   result;
>
>      error = FT_Get_Glyph_Bitmap( *the_glyph, render_mode,
>                                   origin, &result );
>      if ( !error )
>      {
>        if ( destroy )
>          FT_Done_Glyph( *the_glyph );
>
>        *the_glyph = (FT_Glyph) result;
>      }
>      return  error;
>    }
>
>    Hope this helps,
>
> - David Turner
> - The FreeType Project  (www.freetype.org)
>
>
>
> Patrick Hoffmann wrote:
> > I do call FT_Done_Glyph() (later in my code) and it works
> mostly fine.
> > Except the struct created by FT_Glyph_To_Bitmap! I have to
> delete it
> > manually before calling FT_Done_Glyph().
> >
> > -----Ursprüngliche Nachricht-----
> > Von: address@hidden [mailto:address@hidden Im
> > Auftrag von David Turner
> > Gesendet: Freitag, 17. Januar 2003 16:32
> > An: address@hidden
> > Betreff: Re: [Devel] Leaking FT_Glyph_To_Bitmap
> >
> >
> > Hello Patrick,
> >
> > Patrick Hoffmann wrote:
> >
> >>Hi freetype folx...
> >>
> >>I found a leak (or a misktake of myself ;) in FreeType 2.
> >>
> >>When I user FT_Glyph_To_Bitmap() I need to delete the bitmap buffer
> >>and the bitmap it self by my own. I didn't found any hint
> about that
> >>in the documentation, so I think this might be a memory leak bug.
> >>
> >>Any ideas?
> >>
> >
> > FT_Glyph objects are not monitored by the library, you need
> to destroy
> > them yourself (unlike FT_Size/FT_GlyphSlot/FT_CharMap objects which
> > are automatically destroyed when FT_Done_Face or
> FT_Done_FreeType are
> > called)
> >
> > When FT_Glyph_To_Bitmap is called, it really creates a new FT_Glyph
> > object and changes your "image" handle to point to it. you
> should call
> > FT_Done_Glyph to destroy it when you don't need it anymore..
> >
> > I don't think this is a memory leak, just normal behaviour for the
> > library...
> >
> > Hope this helps,
> >
> > - David Turner
> > - The FreeType Project  (www.freetype.org)
> >
> >
> >
> >>Here is the code...
> >>
> >>    FT_Glyph        image = it->m_ftglyph;
> >>
> >>    e = FT_Glyph_To_Bitmap( &image, ft_render_mode_normal, &pen, 0
> >>);
> >>    if( !e )
> >>    {
> >>            FT_BitmapGlyph  bit = (FT_BitmapGlyph)image;
> >>
> >>            Driver_Display_Bitmap( ... );
> >>
> >>            // Undocumented: must delete these both...
> >>            delete [] bit->bitmap.buffer;
> >>            delete bit;
> >>    }
> >>
> >>
> >>_______________________________________________
> >>Devel mailing list
> >>address@hidden http://www.freetype.org/mailman/listinfo/devel
> >>
> >
> >
> >
> >
> > _______________________________________________
> > Devel mailing list
> > address@hidden http://www.freetype.org/mailman/listinfo/devel
> >
> >
> > _______________________________________________
> > Devel mailing list
> > address@hidden http://www.freetype.org/mailman/listinfo/devel
> >
>
>
>
> _______________________________________________
> Devel mailing list
> address@hidden http://www.freetype.org/mailman/listinfo/devel
> 




reply via email to

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