When using vim-gnome (7.3), only the first font in the 'guifont' list
is ever checked. This is because pango_font_description_from_string()
does its best to return a usable font, even if it doesn't actually
find anything that even vaguely matches.

I have put together a quick patch that adds some code to check
the font family against the list of font families that Pango is
aware of. If the selected family is not found in the list, then
gui_mch_get_font() will fail by returning NULL.

With this patch applied, I get the fail through behavior described in
'guifont' documentation.

I am not sure how robust this solution is, but it has survived my
initial testing. Any feedback would be most appreciated.

-- 
Thedward Blevins <thedw...@barsoom.net>

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -cr vim73.orig/src/gui_gtk_x11.c vim73/src/gui_gtk_x11.c
*** vim73.orig/src/gui_gtk_x11.c	2010-08-15 06:52:15.000000000 -0500
--- vim73/src/gui_gtk_x11.c	2010-10-10 19:19:38.000000000 -0500
***************
*** 4458,4463 ****
--- 4458,4506 ----
      else
  	font = pango_font_description_from_string((const char *)name);
  
+      /* pango_font_description_from_string() does its best to return something,
+       * even if there isn't one that even vaguely matches. The following code
+       * does a sanity check to make sure the font family shows up in Pango's
+       * list of font families. If there isn't a match it sets the font to NULL,
+       * so the other fonts in the guifont list will be checked. */
+     if (font != NULL)
+     {
+         PangoFontFamily         **families;
+         PangoFontDescription     *font_backup;
+         const char               *font_family;
+         int                       font_count, i;
+ 
+         font_family = pango_font_description_get_family(font);
+ 
+         font_backup = font;
+ 
+         font = NULL;
+ 
+         /* Get a list of the font families Pango knows about */
+         pango_context_list_families (gui.text_context, &families, &font_count);
+ 
+         /* Cycle through the list checking for matches */
+         for (i=0; i <font_count; i++)
+         {
+             const char *context_family = pango_font_family_get_name(families[i]); 
+ 
+             /* if there is a match, set font back to its previous value */
+             if ( ! strcmp(font_family, context_family) ) 
+             {
+                 font = font_backup;
+                 break;
+             }
+ 
+         }
+ 
+         /* cleanup the font description if there was no match */
+         if ( font == NULL )
+             pango_font_description_free(font_backup);
+ 
+         /* cleanup the list of font families */
+         g_free(families);
+     }
+ 
      if (font != NULL)
      {
  	PangoFont *real_font;

Raspunde prin e-mail lui