[backend] Constify font options

The font options accessors in ClutterBackend only deal with const
cairo_font_options_t values, since:

  - set_font_options() will copy the font options
  - get_font_options() will return a pointer to the internal
    font options

Not using const in these cases makes the API confusing and might lead
to erroneous calls to cairo_font_options_destroy().
This commit is contained in:
Emmanuele Bassi 2009-02-26 15:32:48 +00:00
parent 8354295986
commit b39223d8cb
3 changed files with 39 additions and 31 deletions

View File

@ -533,9 +533,12 @@ clutter_backend_get_resolution (ClutterBackend *backend)
* @backend: a #ClutterBackend
* @options: Cairo font options for the backend, or %NULL
*
* Sets the new font options for @backend. If @options is %NULL,
* the first following call to clutter_backend_get_font_options()
* will return the default font options for @backend.
* Sets the new font options for @backend. The #ClutterBackend will
* copy the #cairo_font_options_t.
*
* If @options is %NULL, the first following call to
* clutter_backend_get_font_options() will return the default font
* options for @backend.
*
* This function is intended for actors creating a Pango layout
* using the PangoCairo API.
@ -544,7 +547,7 @@ clutter_backend_get_resolution (ClutterBackend *backend)
*/
void
clutter_backend_set_font_options (ClutterBackend *backend,
cairo_font_options_t *options)
const cairo_font_options_t *options)
{
ClutterBackendPrivate *priv;
@ -572,11 +575,13 @@ clutter_backend_set_font_options (ClutterBackend *backend,
*
* Retrieves the font options for @backend.
*
* Return value: (transfer none): the font options of the #ClutterBackend
* Return value: (transfer none): the font options of the #ClutterBackend.
* The returned #cairo_font_options_t is owned by the backend and should
* not be modified or freed
*
* Since: 0.8
*/
cairo_font_options_t *
const cairo_font_options_t *
clutter_backend_get_font_options (ClutterBackend *backend)
{
ClutterBackendPrivate *priv;

View File

@ -89,21 +89,21 @@ GType clutter_backend_get_type (void) G_GNUC_CONST;
ClutterBackend *clutter_get_default_backend (void);
void clutter_backend_set_resolution (ClutterBackend *backend,
gdouble dpi);
gdouble clutter_backend_get_resolution (ClutterBackend *backend);
void clutter_backend_set_double_click_time (ClutterBackend *backend,
guint msec);
guint clutter_backend_get_double_click_time (ClutterBackend *backend);
void clutter_backend_set_double_click_distance (ClutterBackend *backend,
guint distance);
guint clutter_backend_get_double_click_distance (ClutterBackend *backend);
void clutter_backend_set_font_options (ClutterBackend *backend,
cairo_font_options_t *options);
cairo_font_options_t *clutter_backend_get_font_options (ClutterBackend *backend);
void clutter_backend_set_font_name (ClutterBackend *backend,
const gchar *font_name);
G_CONST_RETURN gchar *clutter_backend_get_font_name (ClutterBackend *backend);
void clutter_backend_set_resolution (ClutterBackend *backend,
gdouble dpi);
gdouble clutter_backend_get_resolution (ClutterBackend *backend);
void clutter_backend_set_double_click_time (ClutterBackend *backend,
guint msec);
guint clutter_backend_get_double_click_time (ClutterBackend *backend);
void clutter_backend_set_double_click_distance (ClutterBackend *backend,
guint distance);
guint clutter_backend_get_double_click_distance (ClutterBackend *backend);
void clutter_backend_set_font_options (ClutterBackend *backend,
const cairo_font_options_t *options);
const cairo_font_options_t *clutter_backend_get_font_options (ClutterBackend *backend);
void clutter_backend_set_font_name (ClutterBackend *backend,
const gchar *font_name);
G_CONST_RETURN gchar * clutter_backend_get_font_name (ClutterBackend *backend);
G_END_DECLS

View File

@ -447,7 +447,7 @@ update_pango_context (ClutterBackend *backend,
PangoContext *context)
{
PangoFontDescription *font_desc;
cairo_font_options_t *font_options;
const cairo_font_options_t *font_options;
const gchar *font_name;
gdouble resolution;
@ -2671,7 +2671,11 @@ void
clutter_set_font_flags (ClutterFontFlags flags)
{
ClutterFontFlags old_flags, changed_flags;
cairo_font_options_t *font_options;
const cairo_font_options_t *font_options;
cairo_font_options_t *new_font_options;
ClutterBackend *backend;
backend = clutter_get_default_backend ();
if (CLUTTER_CONTEXT ()->font_map)
cogl_pango_font_map_set_use_mipmapping (CLUTTER_CONTEXT ()->font_map,
@ -2680,26 +2684,25 @@ clutter_set_font_flags (ClutterFontFlags flags)
old_flags = clutter_get_font_flags ();
font_options = clutter_backend_get_font_options (CLUTTER_CONTEXT ()->backend);
font_options = cairo_font_options_copy (font_options);
font_options = clutter_backend_get_font_options (backend);
new_font_options = cairo_font_options_copy (font_options);
/* Only set the font options that have actually changed so we don't
override a detailed setting from the backend */
changed_flags = old_flags ^ flags;
if ((changed_flags & CLUTTER_FONT_HINTING))
cairo_font_options_set_hint_style (font_options,
cairo_font_options_set_hint_style (new_font_options,
(flags & CLUTTER_FONT_HINTING)
? CAIRO_HINT_STYLE_FULL
: CAIRO_HINT_STYLE_NONE);
clutter_backend_set_font_options (CLUTTER_CONTEXT ()->backend, font_options);
clutter_backend_set_font_options (backend, new_font_options);
cairo_font_options_destroy (font_options);
cairo_font_options_destroy (new_font_options);
if (CLUTTER_CONTEXT ()->pango_context)
update_pango_context (CLUTTER_CONTEXT ()->backend,
CLUTTER_CONTEXT ()->pango_context);
update_pango_context (backend, CLUTTER_CONTEXT ()->pango_context);
}
/**
@ -2717,7 +2720,7 @@ clutter_get_font_flags (void)
{
ClutterMainContext *ctxt = CLUTTER_CONTEXT ();
CoglPangoFontMap *font_map = NULL;
cairo_font_options_t *font_options;
const cairo_font_options_t *font_options;
ClutterFontFlags flags = 0;
font_map = CLUTTER_CONTEXT ()->font_map;