Add a per-actor PangoContext

Rendering text inside an actor is pretty much impossible without
using internal API to create the various pieces like the PangoContext
and the font map.

Each actor should have the ability to create a PangoContext, which
is the only object needed to generate layouts and change the various
Pango settings.

This commit adds a clutter_actor_get_pango_context() function that
creates a PangoContext inside the ClutterActor private data and allows
the creation of PangoLayouts when needed. If the actor already
has a PangoContext, the same instance is returned.

The PangoContext is created only on demand.
This commit is contained in:
Emmanuele Bassi 2008-12-23 14:06:55 +00:00
parent b8b8b155c4
commit 78628edf2f
2 changed files with 27 additions and 2 deletions

View File

@ -221,7 +221,9 @@ struct _ClutterActorPrivate
/* cached allocation is invalid (request has changed, probably) */
guint needs_allocation : 1;
guint has_clip : 1;
guint show_on_set_parent : 1;
guint has_clip : 1;
ClutterUnit clip[4];
/* Rotation angles */
@ -260,7 +262,7 @@ struct _ClutterActorPrivate
ShaderData *shader_data;
gboolean show_on_set_parent;
PangoContext *pango_context;
};
enum
@ -7589,3 +7591,22 @@ clutter_actor_grab_key_focus (ClutterActor *self)
if (parent && CLUTTER_IS_STAGE (parent))
clutter_stage_set_key_focus (CLUTTER_STAGE (parent), self);
}
PangoContext *
clutter_actor_get_pango_context (ClutterActor *self)
{
ClutterActorPrivate *priv;
ClutterMainContext *ctx;
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
priv = self->priv;
if (priv->pango_context)
return priv->pango_context;
ctx = CLUTTER_CONTEXT ();
priv->pango_context = _clutter_context_create_pango_context (ctx);
return priv->pango_context;
}

View File

@ -31,6 +31,8 @@
/* clutter-actor.h */
#include <glib-object.h>
#include <pango/pango.h>
#include <clutter/clutter-color.h>
#include <clutter/clutter-fixed.h>
#include <clutter/clutter-types.h>
@ -563,6 +565,8 @@ gboolean clutter_actor_get_paint_visibility (ClutterActor *self);
void clutter_actor_grab_key_focus (ClutterActor *self);
PangoContext *clutter_actor_get_pango_context (ClutterActor *self);
G_END_DECLS
#endif /* _HAVE_CLUTTER_ACTOR_H */