[cairo] Font-related question...

Philip Schneider philip at pixologic.com
Thu Mar 21 16:23:46 PDT 2013


OK, I think I understand part of this now. What I was doing was this:

	FT_Library  library;
	FT_Face     face;
        
 	int error = FT_Init_FreeType(&library);
	error = FT_New_Memory_Face(library,
 				   (const FT_Byte*)buffer.getData(),
				   498124,
				   0,
				   &face);
        
	cairo_font_face_t   *testFace = 0;
	cairo_scaled_font_t *testFont = 0;

        testFace = cairo_ft_font_face_create_for_ft_face(face, 0);
        
        cairo_matrix_t font_matrix;
        cairo_matrix_init_identity(&font_matrix);
        cairo_matrix_scale(&font_matrix, 19, 19);
        
        cairo_matrix_t ctm;
        cairo_matrix_init_identity(&ctm);
        
        cairo_font_options_t *options = cairo_font_options_create();
        
        testFont =  cairo_scaled_font_create(testFace,
                                             &font_matrix,
                                             &ctm,
                                             options);

But it seems you might be suggesting that this be used instead:

	FT_Library  library;
	FT_Face     face;
        
 	int error = FT_Init_FreeType(&library);
	error = FT_New_Memory_Face(library,
 				   (const FT_Byte*)buffer.getData(),
				   498124,
				   0,
				   &face);
        
	cairo_font_face_t   *testFace = 0;
	cairo_scaled_font_t *testFont = 0;

	testFace = cairo_ft_font_face_create_for_ft_face(face, 0);

	cairo_set_font_face(cr, testFace);

	cairo_set_font_size(cr, 19);

	// Can get the font pointer, if need be..
	testFont = cairo_get_scaled_font(cr);
        

OK…but while this second alternative may be effectively equivalent, my concern is more with memory footprint and performance…The docs say "A cairo_scaled_font_t is a font scaled to a particular size and device resolution. A cairo_scaled_font_t is most useful for low-level font usage where a library or application wants to cache a reference to a scaled font to speed up the computation of metrics."  This suggests to me that I could create my three different fonts at their three different sizes, and perhaps see improved performance for querying font metrics. I suppose the trade-off might be that maintaining three separate fonts would use up more memory…this is basically the motivation for my question… :-) I guess the time-vs-space tradeoff is something I'd have to measure myself...

-- Philip

On Mar 21, 2013, at 1:33 PM, Behdad Esfahbod <behdad at behdad.org> wrote:

> On 13-03-21 04:20 PM, Philip Schneider wrote:
>> Greetings -
>> 
>> The doc for cairo_scaled_font_create() suggests that the font_matrix can be
>> used to set the point size N (by making the matrix contain a scale of N). But
>> there's also cairo_set_font_size, which seems to act to replace the matrix one
>> has set in the creation call. If my application makes use of the same face,
>> but at say 3 font sizes (10, 16, 24), would it be better to create and retain
>> three separate instances (each at one of the three desired sizes), or just
>> create a single instance and use cairo_set_font_size() whenever I need to
>> switch between sizes?
> 
> Normally you shouldn't need to use cairo_scaled_font_create().  Cairo does
> that automatically for you.  cairo_set_font_size() is a convenience wrapper
> for cairo_set_font_matrix().
> 
> -- 
> behdad
> http://behdad.org/
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cairographics.org/archives/cairo/attachments/20130321/29f0b50f/attachment-0001.html>


More information about the cairo mailing list