2007-12-21 Emmanuele Bassi <ebassi@openedhand.com>

* clutter/clutter-label.c:
	(clutter_label_ensure_layout): Avoid rounding errors in the layout
	computing when switching between Clutter units and Pango units.
This commit is contained in:
Emmanuele Bassi 2007-12-21 13:18:19 +00:00
parent 06fe42dde9
commit 935e3c1b4e
2 changed files with 18 additions and 10 deletions

View File

@ -1,3 +1,9 @@
2007-12-21 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/clutter-label.c:
(clutter_label_ensure_layout): Avoid rounding errors in the layout
computing when switching between Clutter units and Pango units.
2007-12-19 Øyvind Kolås <pippin@o-hand.com> 2007-12-19 Øyvind Kolås <pippin@o-hand.com>
* clutter/clutter-texture.[ch]: (bug #675) added * clutter/clutter-texture.[ch]: (bug #675) added

View File

@ -165,12 +165,14 @@ static void
clutter_label_ensure_layout (ClutterLabel *label) clutter_label_ensure_layout (ClutterLabel *label)
{ {
ClutterLabelPrivate *priv; ClutterLabelPrivate *priv;
ClutterUnit raw_width;
gint width; gint width;
priv = label->priv; priv = label->priv;
/* use the last size requested, if any */ /* use the last size requested, if any */
width = CLUTTER_UNITS_TO_DEVICE (priv->allocation.x2 - priv->allocation.x1); raw_width = priv->allocation.x2 - priv->allocation.x1;
width = CLUTTER_UNITS_TO_DEVICE (raw_width);
if (!priv->layout) if (!priv->layout)
{ {
@ -195,15 +197,15 @@ clutter_label_ensure_layout (ClutterLabel *label)
pango_layout_set_markup (priv->layout, priv->text, -1); pango_layout_set_markup (priv->layout, priv->text, -1);
} }
if (priv->ellipsize) if (priv->ellipsize != PANGO_ELLIPSIZE_NONE)
pango_layout_set_width (priv->layout, width > 0 ? width * PANGO_SCALE pango_layout_set_width (priv->layout, width > 0 ? CLUTTER_UNITS_TO_PANGO_UNIT (raw_width)
: -1); : -1);
else if (priv->wrap) else if (priv->wrap)
{ {
pango_layout_set_wrap (priv->layout, priv->wrap_mode); pango_layout_set_wrap (priv->layout, priv->wrap_mode);
if (width > 0) if (width > 0)
pango_layout_set_width (priv->layout, width * PANGO_SCALE); pango_layout_set_width (priv->layout, CLUTTER_UNITS_TO_PANGO_UNIT (raw_width));
else else
{ {
/* this was adapted from the GtkLabel code */ /* this was adapted from the GtkLabel code */
@ -264,8 +266,8 @@ clutter_label_ensure_layout (ClutterLabel *label)
} }
} }
else else
pango_layout_set_width (priv->layout, (width > 0 ? width * PANGO_SCALE pango_layout_set_width (priv->layout, width > 0 ? CLUTTER_UNITS_FROM_PANGO_UNIT (raw_width)
: -1)); : -1);
} }
CLUTTER_NOTE (ACTOR, "Label width set to %d pixels", width); CLUTTER_NOTE (ACTOR, "Label width set to %d pixels", width);
@ -346,7 +348,7 @@ clutter_label_request_coords (ClutterActor *self,
gint width; gint width;
PangoRectangle logical; PangoRectangle logical;
width = CLUTTER_UNITS_TO_DEVICE (box->x2 - box->x1) * PANGO_SCALE; width = CLUTTER_UNITS_TO_PANGO_UNIT (box->x2 - box->x1);
pango_layout_set_width (priv->layout, -1); pango_layout_set_width (priv->layout, -1);
pango_layout_get_extents (priv->layout, NULL, &logical); pango_layout_get_extents (priv->layout, NULL, &logical);
@ -508,15 +510,15 @@ clutter_label_get_property (GObject *object,
static void static void
clutter_label_class_init (ClutterLabelClass *klass) clutter_label_class_init (ClutterLabelClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass); ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
actor_class->paint = clutter_label_paint; actor_class->paint = clutter_label_paint;
actor_class->request_coords = clutter_label_request_coords; actor_class->request_coords = clutter_label_request_coords;
actor_class->query_coords = clutter_label_query_coords; actor_class->query_coords = clutter_label_query_coords;
gobject_class->finalize = clutter_label_finalize; gobject_class->finalize = clutter_label_finalize;
gobject_class->dispose = clutter_label_dispose; gobject_class->dispose = clutter_label_dispose;
gobject_class->set_property = clutter_label_set_property; gobject_class->set_property = clutter_label_set_property;
gobject_class->get_property = clutter_label_get_property; gobject_class->get_property = clutter_label_get_property;