[cairo] Issue with Cairo Font Cache

Jian Ye jiany at cdpcom.com
Wed Mar 18 13:44:41 PDT 2015


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);



More information about the cairo mailing list