freetype
[Top][All Lists]
Advanced

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

Re: [Freetype] (no subject)


From: David Turner
Subject: Re: [Freetype] (no subject)
Date: Tue, 19 Jun 2001 18:15:06 +0200

Hello Michael,

> 
> Hello
> 
> I am replacing the Type 1 and FreeType 1.x renderer in BePDF (a pdf viewer 
> for the
> Be Operating System, based on xpdf) with FreeType 2.x.
> It already works find but needs some fine tuning. I just want to ensure that 
> it
> is implemented as efficient as possible and contains no memory leaks.
> The relevant portion of the source code follows below.
> 
> Could someone please have a look at it?
> 
> Any help is appreciated, thanks,
> Michael
> 
> PS: Sorry for my broken English.
> 
> Notes to the source code:
> - class FontFile holds one font face.
> - FT2Font uses a face from a FontFile with a given size and rotation and 
> caches glyphes converted to bitmaps
>   (there can be several FT2Font objects that all use one face but have 
> different sizes and rotations).
>

OK, first of all, having a FT_Face per FT2Font object is probably a bad idea.
That's because a FT_Face can be a very large object in memory, depending on
the font format and other internal information that cannot be provided to
client applications for various good reasons.

This means that you should always try to minimize the number of opened
FT_Face (and FT_Size) objects in your program. A good way to do that is
to use the cache manager, that allows you to do, simply just that :-) !!
 
(note that you can cache FT_Face and FT_Size object within the cache
 manager, while using your own cache for glyph images/bitmaps, these
 two schemes are not incompatible)

Second, the FT_BitmapGlyph data type is by far not the smallest possible
one (it's designed to be convenient to use, and a descendant of the
FT_Glyph type). You'll probably benefit from not using it but design,
instead, a specific glyph node for your bitmap cache.

If you're only interested in bitmaps, you could simplify your code
with something like:

  load_flags = fontFile->engine->aa
             ? FT_LOAD_RENDER
             : ( FT_LOAD_RENDER | FT_LOAD_MONOCHROME ) ;

  error = FT_Load_Glyph( fontFile->face, glyph_index, load_flags );

  /* here, the glyph bitmap is in "face->glyph->bitmap", you could */
  /* _copy_ its content to your own cache node structure..         */

  .....

  this prevents the use of FT_BitmapGlyph types..

Hope this helps,

- David



> FT_Matrix matrix; // transformation matirx (rotation only)
> float size; // font size
> FT_Face   fontFile->face; // the current face
> FT_BitmapGlyph   bitmapGlyph; // the current bitmap glyph
> bool fontFile->engine->aa; // anti-alias or monochrome bitmap
> 
> GBool FT2Font::getGlyphPixmap(Gushort c) {
>   int i, j, k;
> 
>   // check the cache (pseudo code)
>   if (inCache(c)) {
>     bitmapGlyph = cached_bitmap_glyph(c);
>     return gTrue;
>   }
>   FT_UInt   glyph_index;
>   FT_Glyph  glyph;
>   FT_Vector vec;
>   int error;
>   FT_Set_Char_Size(fontFile->face, 0, size * 64, 72, 72);
>   // retrieve glyph index from character code
>   glyph_index = fontFile->decode(c);
>   // load glyph image into the slot (erase previous one)
>   error = FT_Load_Glyph( fontFile->face, glyph_index, FT_LOAD_DEFAULT );
>   if (error) return gFalse;
>   error = FT_Get_Glyph( fontFile->face->glyph, &glyph );
>   if (error) return gFalse;
>   // convert to an anti-aliased/monochrome bitmap
>   FT_Glyph_Transform(glyph, &matrix, NULL);
>   error = FT_Glyph_To_Bitmap(&glyph, fontFile->engine->aa ? 
> ft_render_mode_normal : ft_render_mode_mono, NULL, 0);
>   if (error) return gFalse;
>   bitmapGlyph = (FT_BitmapGlyph)glyph;
> 
>   // store glyph pixmap in cache (pseudo code)
>   store_in_bitmap_cache(bitmapGlyph); // frees old glyphs if cache is full 
> with FT_Done_Glyph()
>   return gTrue;
> }
> 
> _______________________________________________
> Freetype mailing list
> address@hidden
> http://www.freetype.org/mailman/listinfo/freetype




reply via email to

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