Re: Issue with Cairo Font Cache

Jian Ye <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
No I didn't do it. I thought I could control the life time of the 
FT_Face object. And I suppose I need to control it since I need to free 
the FreeType library object when a document is closed.

Here is the simplified version of my code.

//-- 1. On document start up
FT_Init_FreeType( &c_ftLibrary );

//-- 2. Find a new font, load it
FT_New_Memory_Face(c_ftLibrary, file, nDataLen, 0, &face);
// then hold the face object in a list.

//-- 3.  Create a scalable font from a face object

     if(c_currentCairoFont)  // clear current scalable font
     {
         cairo_scaled_font_destroy(c_currentCairoFont);
     }

   cairo_font_face_t * cfont_face = 
cairo_ft_font_face_create_for_ft_face(face, 0);
   c_currentCairoFont = cairo_scaled_font_create (cfont_face, 
&font_matrix, &ctm, font_options);
   cairo_font_face_destroy (cfont_face);  //release ref count

   cairo_set_scaled_font (cr, c_currentCairoFont);


//--4. Prepare the glyphs info  and use the current font

   unsigned long   glyph_id = FT_Get_Char_Index(face, charCode);
..
    cairo_show_glyphs(cr, &vGlyphs[0], glyph_count);
...


//--5.  on document shut down
     cairo_scaled_font_destroy(c_currentCairoFont);

     for(it=c_fonts.begin(); it!=c_fonts.end(); ++it)
     {
         FT_Face& face = it->second->c_ft_font;
         FT_Done_Face(face);
     }
    FT_Done_FreeType(c_ftLibrary);

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.