From 801e535e947e32fea5fe2859e94c58f7b7c8af4f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 2 Feb 2009 09:01:41 +0000 Subject: [PATCH] Add Actor::create_pango_layout() Final bit of integration between ClutterActor and Pango: a simple method for creating a PangoLayout, pre-filled with text and ready to be rendered using cogl_pango_render_layout(). This should make writing new Actors rendering custom text in their paint() implementation easy and reliable. --- clutter/clutter-actor.c | 38 ++++++++++++++++++++++ clutter/clutter-actor.h | 2 ++ doc/reference/clutter/clutter-sections.txt | 1 + 3 files changed, 41 insertions(+) diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index dfc4b296e..75e927ff8 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -8095,6 +8095,44 @@ clutter_actor_create_pango_context (ClutterActor *self) return retval; } +/** + * clutter_actor_create_pango_layout: + * @self: a #ClutterActor + * @text: the text to set on the #PangoLayout, or %NULL + * + * Creates a new #PangoLayout from the same #PangoContext used + * by the #ClutterActor. The #PangoLayout is already configured + * with the font map, resolution and font options, and the + * given @text. + * + * If you want to keep around a #PangoLayout created by this + * function you will have to connect to the #ClutterBackend::font-changed + * and #ClutterBackend::resolution-changed signals, and call + * pango_layout_context_changed() in response to them. + * + * Return value: the newly created #PangoLayout. Use g_object_unref() + * when done + * + * Since: 1.0 + */ +PangoLayout * +clutter_actor_create_pango_layout (ClutterActor *self, + const gchar *text) +{ + PangoContext *context; + PangoLayout *layout; + + g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL); + + context = clutter_actor_get_pango_context (self); + layout = pango_layout_new (context); + + if (text) + pango_layout_set_text (layout, text, -1); + + return layout; +} + /* Allows overriding the parent traversed when querying an actors paint * opacity. Used by ClutterClone. */ void diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h index 571bac1f5..26167da0e 100644 --- a/clutter/clutter-actor.h +++ b/clutter/clutter-actor.h @@ -576,6 +576,8 @@ void clutter_actor_grab_key_focus (ClutterActor *self PangoContext *clutter_actor_get_pango_context (ClutterActor *self); PangoContext *clutter_actor_create_pango_context (ClutterActor *self); +PangoLayout * clutter_actor_create_pango_layout (ClutterActor *self, + const gchar *text); G_END_DECLS diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index 35b9e9c07..9c14ef275 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -451,6 +451,7 @@ clutter_actor_get_transformed_sizeu clutter_actor_grab_key_focus clutter_actor_get_pango_context clutter_actor_create_pango_context +clutter_actor_create_pango_layout CLUTTER_TYPE_GEOMETRY