[cairo] custom font options and cairo_t

Owen Taylor otaylor at redhat.com
Mon Jul 25 11:17:07 PDT 2005


On Mon, 2005-07-25 at 13:37 -0400, Carl Worth wrote:

> I agree. Option number one seems correct. Something not unlike:
> 
> 	void
> 	cairo_set_font_options (cairo_t *cr,
> 				cairo_font_options_t *font_options);
> 
> This is consistent with the model that is already in place with
> cairo_set_font_face and cairo_set_font_matrix. This model simply
> requires that the gstate provides a way to set each parameter needed
> for cairo_scaled_font_create.

Here's a patch that adds cairo_{set,get}_font_options(). It's 
incredibly straightforward. Two notes:

 - I've chosen to merge the options set with set_font_options()
   with the options for the surface.

    - This is what you want when using this for the toy API
      (or a non-toy Cairo-centric font API). Turning off antialiasing
      should be possible without affecting other options.

    - It gives a natural defined value for the initial value of
      this part of the gstate: everything is DEFAULT.

 - cairo_get_font_options() gets the set font options, not the
   merged font options. I think this makes more sense: the 
   set font options are what is part of the gstate, the merged
   font options are an artifact.

This does mean that if you want to get the actual set of font options
that will be used for a cairo_t in order to create a scaled font,
then the code is rather ugly:

 cairo_font_options_t *options, *set_options;

 options = cairo_font_options_create ();
 cairo_surface_get_font_options (surface, options);

 set_options =  cairo_options_create();
 cairo_get_font_options (cr, set_options);

 cairo_font_options_merge (options, set_options);

 font = cairo_scaled_font_create (..., options);

 cairo_font_options_destroy (set_options); 
 cairo_font_options_destroy (options); 

[ 
This would look a *lot* better in something other than C:

  options = surface.get_font_options()
  options.merge (cr.get_font_options());
  font = CairoScaledFont (..., options);
]

But if you are deriving everything from a cairo_t, then 
you'd probably really want cairo_get_scaled_font() anyways; 
there's no other meaningful scaled font to create.

Regards,
						Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050725/753694a0/attachment.pgp


More information about the cairo mailing list