text: Add :font-description

High level toolkits might wish to construct a PangoFontDescription and
then set it directly on a ClutterText actor proxy or sub-class.
ClutterText should have a :font-description property to set (and get)
the PangoFontDescription.

http://bugzilla.openedhand.com/show_bug.cgi?id=1960
This commit is contained in:
Emmanuele Bassi 2010-02-03 14:35:45 +00:00
parent 74c0170ccc
commit cb52581a24
3 changed files with 228 additions and 118 deletions

View File

@ -192,6 +192,7 @@ enum
PROP_0,
PROP_FONT_NAME,
PROP_FONT_DESCRIPTION,
PROP_TEXT,
PROP_COLOR,
PROP_USE_MARKUP,
@ -965,6 +966,10 @@ clutter_text_set_property (GObject *gobject,
clutter_text_set_font_name (self, g_value_get_string (value));
break;
case PROP_FONT_DESCRIPTION:
clutter_text_set_font_description (self, g_value_get_boxed (value));
break;
case PROP_USE_MARKUP:
clutter_text_set_use_markup (self, g_value_get_boolean (value));
break;
@ -1064,6 +1069,10 @@ clutter_text_get_property (GObject *gobject,
g_value_set_string (value, priv->font_name);
break;
case PROP_FONT_DESCRIPTION:
g_value_set_boxed (value, priv->font_desc);
break;
case PROP_USE_MARKUP:
g_value_set_boolean (value, priv->use_markup);
break;
@ -2274,6 +2283,25 @@ clutter_text_class_init (ClutterTextClass *klass)
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class, PROP_FONT_NAME, pspec);
/**
* ClutterText:font-description:
*
* The #PangoFontDescription that should be used by the #ClutterText
*
* If you have a string describing the font then you should look at
* #ClutterText:font-name instead
*
* Since: 1.2
*/
pspec = g_param_spec_boxed ("font-description",
"Font Description",
"The font description to be used",
PANGO_TYPE_FONT_DESCRIPTION,
CLUTTER_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_FONT_DESCRIPTION,
pspec);
/**
* ClutterText:text:
*
@ -2839,7 +2867,10 @@ clutter_text_init (ClutterText *self)
priv->cursor_color = default_cursor_color;
priv->selection_color = default_selection_color;
/* get the default font name from the context */
/* get the default font name from the context; we don't use
* set_font_description() here because we are initializing
* the Text and we don't need notifications and sanity checks
*/
font_name = clutter_backend_get_font_name (clutter_get_default_backend ());
priv->font_name = g_strdup (font_name);
priv->font_desc = pango_font_description_from_string (font_name);
@ -3456,6 +3487,90 @@ clutter_text_get_selection_color (ClutterText *self,
*color = priv->selection_color;
}
/*
* clutter_text_set_font_description_internal:
* @self: a #ClutterText
* @desc: a #PangoFontDescription
*
* Sets @desc as the font description to be used by the #ClutterText
* actor. The font description ownership is transferred to @self so
* the #PangoFontDescription must not be freed after this function
*
* This function will also set the :font-name field as a side-effect
*
* This function will evict the layout cache, and queue a relayout if
* the #ClutterText actor has contents.
*/
static inline void
clutter_text_set_font_description_internal (ClutterText *self,
PangoFontDescription *desc)
{
ClutterTextPrivate *priv = self->priv;
if (priv->font_desc == desc)
return;
if (priv->font_desc != NULL)
pango_font_description_free (priv->font_desc);
priv->font_desc = desc;
/* update the font name string we use */
g_free (priv->font_name);
priv->font_name = pango_font_description_to_string (priv->font_desc);
clutter_text_dirty_cache (self);
if (priv->text && priv->text[0] != '\0')
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
g_object_notify (G_OBJECT (self), "font-description");
}
/**
* clutter_text_set_font_description:
* @self: a #ClutterText
* @font_desc: a #PangoFontDescription
*
* Sets @font_desc as the font description for a #ClutterText
*
* The #PangoFontDescription is copied by the #ClutterText actor
* so you can safely call pango_font_description_free() on it after
* calling this function.
*
* Since: 1.2
*/
void
clutter_text_set_font_description (ClutterText *self,
PangoFontDescription *font_desc)
{
PangoFontDescription *copy;
g_return_if_fail (CLUTTER_IS_TEXT (self));
copy = pango_font_description_copy (font_desc);
clutter_text_set_font_description_internal (self, copy);
}
/**
* clutter_text_get_font_description:
* @self: a #ClutterText
*
* Retrieves the #PangoFontDescription used by @self
*
* Return value: a #PangoFontDescription. The returned value is owned
* by the #ClutterText actor and it should not be modified or freed
*
* Since: 1.2
*/
PangoFontDescription *
clutter_text_get_font_description (ClutterText *self)
{
g_return_val_if_fail (CLUTTER_IS_TEXT (self), NULL);
return self->priv->font_desc;
}
/**
* clutter_text_get_font_name:
* @self: a #ClutterText
@ -3522,18 +3637,8 @@ clutter_text_set_font_name (ClutterText *self,
return;
}
g_free (priv->font_name);
priv->font_name = g_strdup (font_name);
if (priv->font_desc)
pango_font_description_free (priv->font_desc);
priv->font_desc = desc;
clutter_text_dirty_cache (self);
if (priv->text && priv->text[0] != '\0')
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
/* this will set the font_name field as well */
clutter_text_set_font_description_internal (self, desc);
g_object_notify (G_OBJECT (self), "font-name");
}

View File

@ -97,117 +97,120 @@ struct _ClutterTextClass
GType clutter_text_get_type (void) G_GNUC_CONST;
ClutterActor * clutter_text_new (void);
ClutterActor * clutter_text_new_full (const gchar *font_name,
const gchar *text,
const ClutterColor *color);
ClutterActor * clutter_text_new_with_text (const gchar *font_name,
const gchar *text);
ClutterActor * clutter_text_new_full (const gchar *font_name,
const gchar *text,
const ClutterColor *color);
ClutterActor * clutter_text_new_with_text (const gchar *font_name,
const gchar *text);
G_CONST_RETURN gchar *clutter_text_get_text (ClutterText *self);
void clutter_text_set_text (ClutterText *self,
const gchar *text);
void clutter_text_set_markup (ClutterText *self,
const gchar *markup);
void clutter_text_set_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_color (ClutterText *self,
ClutterColor *color);
void clutter_text_set_font_name (ClutterText *self,
const gchar *font_name);
G_CONST_RETURN gchar *clutter_text_get_font_name (ClutterText *self);
G_CONST_RETURN gchar *clutter_text_get_text (ClutterText *self);
void clutter_text_set_text (ClutterText *self,
const gchar *text);
void clutter_text_set_markup (ClutterText *self,
const gchar *markup);
void clutter_text_set_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_color (ClutterText *self,
ClutterColor *color);
void clutter_text_set_font_name (ClutterText *self,
const gchar *font_name);
G_CONST_RETURN gchar *clutter_text_get_font_name (ClutterText *self);
void clutter_text_set_font_description (ClutterText *self,
PangoFontDescription *font_desc);
PangoFontDescription *clutter_text_get_font_description (ClutterText *self);
void clutter_text_set_ellipsize (ClutterText *self,
PangoEllipsizeMode mode);
PangoEllipsizeMode clutter_text_get_ellipsize (ClutterText *self);
void clutter_text_set_line_wrap (ClutterText *self,
gboolean line_wrap);
gboolean clutter_text_get_line_wrap (ClutterText *self);
void clutter_text_set_line_wrap_mode (ClutterText *self,
PangoWrapMode wrap_mode);
PangoWrapMode clutter_text_get_line_wrap_mode (ClutterText *self);
PangoLayout * clutter_text_get_layout (ClutterText *self);
void clutter_text_set_attributes (ClutterText *self,
PangoAttrList *attrs);
PangoAttrList * clutter_text_get_attributes (ClutterText *self);
void clutter_text_set_use_markup (ClutterText *self,
gboolean setting);
gboolean clutter_text_get_use_markup (ClutterText *self);
void clutter_text_set_line_alignment (ClutterText *self,
PangoAlignment alignment);
PangoAlignment clutter_text_get_line_alignment (ClutterText *self);
void clutter_text_set_justify (ClutterText *self,
gboolean justify);
gboolean clutter_text_get_justify (ClutterText *self);
void clutter_text_set_ellipsize (ClutterText *self,
PangoEllipsizeMode mode);
PangoEllipsizeMode clutter_text_get_ellipsize (ClutterText *self);
void clutter_text_set_line_wrap (ClutterText *self,
gboolean line_wrap);
gboolean clutter_text_get_line_wrap (ClutterText *self);
void clutter_text_set_line_wrap_mode (ClutterText *self,
PangoWrapMode wrap_mode);
PangoWrapMode clutter_text_get_line_wrap_mode (ClutterText *self);
PangoLayout * clutter_text_get_layout (ClutterText *self);
void clutter_text_set_attributes (ClutterText *self,
PangoAttrList *attrs);
PangoAttrList * clutter_text_get_attributes (ClutterText *self);
void clutter_text_set_use_markup (ClutterText *self,
gboolean setting);
gboolean clutter_text_get_use_markup (ClutterText *self);
void clutter_text_set_line_alignment (ClutterText *self,
PangoAlignment alignment);
PangoAlignment clutter_text_get_line_alignment (ClutterText *self);
void clutter_text_set_justify (ClutterText *self,
gboolean justify);
gboolean clutter_text_get_justify (ClutterText *self);
void clutter_text_insert_unichar (ClutterText *self,
gunichar wc);
void clutter_text_delete_chars (ClutterText *self,
guint n_chars);
void clutter_text_insert_text (ClutterText *self,
const gchar *text,
gssize position);
void clutter_text_delete_text (ClutterText *self,
gssize start_pos,
gssize end_pos);
gchar * clutter_text_get_chars (ClutterText *self,
gssize start_pos,
gssize end_pos);
void clutter_text_set_editable (ClutterText *self,
gboolean editable);
gboolean clutter_text_get_editable (ClutterText *self);
void clutter_text_set_activatable (ClutterText *self,
gboolean activatable);
gboolean clutter_text_get_activatable (ClutterText *self);
void clutter_text_insert_unichar (ClutterText *self,
gunichar wc);
void clutter_text_delete_chars (ClutterText *self,
guint n_chars);
void clutter_text_insert_text (ClutterText *self,
const gchar *text,
gssize position);
void clutter_text_delete_text (ClutterText *self,
gssize start_pos,
gssize end_pos);
gchar * clutter_text_get_chars (ClutterText *self,
gssize start_pos,
gssize end_pos);
void clutter_text_set_editable (ClutterText *self,
gboolean editable);
gboolean clutter_text_get_editable (ClutterText *self);
void clutter_text_set_activatable (ClutterText *self,
gboolean activatable);
gboolean clutter_text_get_activatable (ClutterText *self);
gint clutter_text_get_cursor_position (ClutterText *self);
void clutter_text_set_cursor_position (ClutterText *self,
gint position);
void clutter_text_set_cursor_visible (ClutterText *self,
gboolean cursor_visible);
gboolean clutter_text_get_cursor_visible (ClutterText *self);
void clutter_text_set_cursor_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_cursor_color (ClutterText *self,
ClutterColor *color);
void clutter_text_set_cursor_size (ClutterText *self,
gint size);
guint clutter_text_get_cursor_size (ClutterText *self);
void clutter_text_set_selectable (ClutterText *self,
gboolean selectable);
gboolean clutter_text_get_selectable (ClutterText *self);
void clutter_text_set_selection_bound (ClutterText *self,
gint selection_bound);
gint clutter_text_get_selection_bound (ClutterText *self);
void clutter_text_set_selection (ClutterText *self,
gssize start_pos,
gssize end_pos);
gchar * clutter_text_get_selection (ClutterText *self);
void clutter_text_set_selection_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_selection_color (ClutterText *self,
ClutterColor *color);
gboolean clutter_text_delete_selection (ClutterText *self);
void clutter_text_set_password_char (ClutterText *self,
gunichar wc);
gunichar clutter_text_get_password_char (ClutterText *self);
void clutter_text_set_max_length (ClutterText *self,
gint max);
gint clutter_text_get_max_length (ClutterText *self);
void clutter_text_set_single_line_mode (ClutterText *self,
gboolean single_line);
gboolean clutter_text_get_single_line_mode (ClutterText *self);
gint clutter_text_get_cursor_position (ClutterText *self);
void clutter_text_set_cursor_position (ClutterText *self,
gint position);
void clutter_text_set_cursor_visible (ClutterText *self,
gboolean cursor_visible);
gboolean clutter_text_get_cursor_visible (ClutterText *self);
void clutter_text_set_cursor_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_cursor_color (ClutterText *self,
ClutterColor *color);
void clutter_text_set_cursor_size (ClutterText *self,
gint size);
guint clutter_text_get_cursor_size (ClutterText *self);
void clutter_text_set_selectable (ClutterText *self,
gboolean selectable);
gboolean clutter_text_get_selectable (ClutterText *self);
void clutter_text_set_selection_bound (ClutterText *self,
gint selection_bound);
gint clutter_text_get_selection_bound (ClutterText *self);
void clutter_text_set_selection (ClutterText *self,
gssize start_pos,
gssize end_pos);
gchar * clutter_text_get_selection (ClutterText *self);
void clutter_text_set_selection_color (ClutterText *self,
const ClutterColor *color);
void clutter_text_get_selection_color (ClutterText *self,
ClutterColor *color);
gboolean clutter_text_delete_selection (ClutterText *self);
void clutter_text_set_password_char (ClutterText *self,
gunichar wc);
gunichar clutter_text_get_password_char (ClutterText *self);
void clutter_text_set_max_length (ClutterText *self,
gint max);
gint clutter_text_get_max_length (ClutterText *self);
void clutter_text_set_single_line_mode (ClutterText *self,
gboolean single_line);
gboolean clutter_text_get_single_line_mode (ClutterText *self);
gboolean clutter_text_activate (ClutterText *self);
gboolean clutter_text_position_to_coords (ClutterText *self,
gint position,
gfloat *x,
gfloat *y,
gfloat *line_height);
gboolean clutter_text_activate (ClutterText *self);
gboolean clutter_text_position_to_coords (ClutterText *self,
gint position,
gfloat *x,
gfloat *y,
gfloat *line_height);
void clutter_text_set_preedit_string (ClutterText *self,
const gchar *preedit_str,
PangoAttrList *preedit_attrs,
guint cursor_pos);
void clutter_text_set_preedit_string (ClutterText *self,
const gchar *preedit_str,
PangoAttrList *preedit_attrs,
guint cursor_pos);
G_END_DECLS

View File

@ -1629,6 +1629,8 @@ clutter_text_set_ellipsize
clutter_text_get_ellipsize
clutter_text_set_font_name
clutter_text_get_font_name
clutter_text_set_font_description
clutter_text_get_font_description
clutter_text_set_password_char
clutter_text_get_password_char
clutter_text_set_justify