Re: GnomeCanvasText properties (was: Re: The future of GdkFont declarations)

ERDI Gergo <cactus cactus rulez org> writes:
> I could cut&paste the GtkCellRendererText code blindly, but I would like
> to understand the plan instead. So, could you help me?

If you look at the set_font_description() function appended to this
mail, from GtkCellRendererText, setting the font description is
exactly the same as setting all 6 "font attributes" (family, style,
variant, etc.) at the same time. Thus any previous
font-attribute-setting gets overridden. But subsequent
font-attribute-setting will override the font. You don't need to store
the font itself, just its decomposition into the 6 attributes.

> Looking at the GtkCellRendererText code, it looks like this is what's
> happening there. However, I don't see why this couldn't be done by
> getting/modifying/setting the current FontDescription -- OK I can imagine
> very weird multi-thread cases where the actual FontDescription of the
> canvas item could change after you get it but before you re-apply the
> modified entry, but I think this is a case the app developer should care
> about.

The case where get/modify/set fails is the following:

 - default font is widget->style->font_desc
 - you get/modify/set
 - theme changes, default font is now widget->style->font_desc
 - you have overridden all six attributes of font_desc, so new default
   font is ignored; you only wanted to override one attribute,
   e.g. the size, while taking other attributes (e.g. Serif) from 
   the theme

i.e. the problem with get/modify/set is that you have to set all 6
attributes, you can't set only one of them.

Note that "scale" is a special way to set the size attribute that sets
the size relative to the default size. This allows you to avoid
implicitly depending on the current default font by doing something
 set (object, "size", widget->style->font_desc->size * 1.5, NULL);
instead you do this:
 set (object, "scale", PANGO_SCALE_X_LARGE, NULL);

To make this all work you need the extra "foo_set" flags to go with
"foo", where if foo_set == FALSE, you use the field from
widget->style->font_desc, otherwise you use the field from the canvas
item itself.


static void
set_font_description (GtkCellRendererText  *celltext,
                      PangoFontDescription *font_desc)
  if (font_desc != NULL)
      /* pango_font_description_from_string() will sometimes return
       * a NULL family or -1 size, so handle those cases.
      if (font_desc->family_name)
        g_object_set (G_OBJECT (celltext),
                      "family", font_desc->family_name,
      if (font_desc->size >= 0)
        g_object_set (G_OBJECT (celltext),
                      "size", font_desc->size,
      g_object_set (G_OBJECT (celltext),
                    "style", font_desc->style,
                    "variant", font_desc->variant,
                    "weight", font_desc->weight,
                    "stretch", font_desc->stretch,
      if (celltext->family_set)
          celltext->family_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "family_set");
      if (celltext->style_set)
          celltext->style_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "style_set");
      if (celltext->variant_set)
          celltext->variant_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "variant_set");
      if (celltext->weight_set)
          celltext->weight_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "weight_set");
      if (celltext->stretch_set)
          celltext->stretch_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "stretch_set");
      if (celltext->size_set)
          celltext->size_set = FALSE;
          g_object_notify (G_OBJECT (celltext), "size_set");

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]