Re: Howto use a GdkFont in Cairo?



Sorry for disturbing again,

> GdkFont is from a very old era, predating inovations like Xft, Pango or
> cairo. Most propably you want to use
> pango_cairo_show_layout_line() and friends.

For me the lines of code that drive me crazy are below.
Maybe they return a GdkFont only because they don't want to break the ABI?

I am a bit confused about the intention of the code below:

1.) If the current private_font_desc and the public font_desc free
both and set them null?
2.) If the private font is null, load a new one / copy the existing?

Why is everything done twice for font_desc and font and why are there
public and private font/font_desc fields?

Wouldn't it be ok, to simply return private_font_desc instead of
private_font and pass that to cairo?

The code:
static GdkFont *
gtk_style_get_font_internal (GtkStyle *style)
{
  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);

  if (style->private_font && style->private_font_desc)
    {
      if (!style->font_desc ||
	  !pango_font_description_equal (style->private_font_desc, style->font_desc))
	{
	  gdk_font_unref (style->private_font);
	  style->private_font = NULL;
	
	  if (style->private_font_desc)
	    {
	      pango_font_description_free (style->private_font_desc);
	      style->private_font_desc = NULL;
	    }
	}
    }

  if (!style->private_font)
    {
      GdkDisplay *display;

      if (style->colormap)
	{
	  display = gdk_screen_get_display (gdk_colormap_get_screen (style->colormap));
	}
      else
	{
	  display = gdk_display_get_default ();
	  GTK_NOTE (MULTIHEAD,
		    g_warning ("gtk_style_get_font() should not be called on an
unattached style"));
	}

      if (style->font_desc)
	{
	  style->private_font = gdk_font_from_description_for_display
(display, style->font_desc);
	  style->private_font_desc = pango_font_description_copy (style->font_desc);
	}

      if (!style->private_font)
	style->private_font = gdk_font_load_for_display (display, "fixed");

      if (!style->private_font)
	g_error ("Unable to load \"fixed\" font");
    }

  return style->private_font;
}


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