]> git.eshelyaron.com Git - emacs.git/commitdiff
Make GTK font chooser respect face-ignored-fonts
authorRobert Pluim <rpluim@gmail.com>
Wed, 13 Nov 2019 14:19:04 +0000 (15:19 +0100)
committerRobert Pluim <rpluim@gmail.com>
Thu, 14 Nov 2019 09:23:37 +0000 (10:23 +0100)
* src/font.c (font_delete_unmatched): Move Vface_ignored_fonts
matching to...
(font_is_ignored): ..Here.  New function.
* src/gtkutil.c (xg_font_filter): New function, uses font_is_ignored
to filter fonts.
(xg_get_font): Set GTK font chooser filter to xg_font_filter.
* src/gtkutil.h: Add prototype for font_is_ignored.

src/font.c
src/gtkutil.c
src/gtkutil.h

index 8dfbfa0fac6c61cca3821a4c2b078d3cf5b9ba27..7c8e9e30c9dd0d880e33b5c6505d6aa96749c74a 100644 (file)
@@ -2655,6 +2655,26 @@ font_clear_cache (struct frame *f, Lisp_Object cache,
 }
 \f
 
+/* Check whether NAME should be ignored based on Vface_ignored_fonts.
+   This is reused by xg_font_filter to apply the same checks to the
+   GTK font chooser.  */
+
+bool
+font_is_ignored (const char *name, ptrdiff_t namelen)
+{
+  Lisp_Object tail = Vface_ignored_fonts;
+  Lisp_Object regexp;
+
+  FOR_EACH_TAIL_SAFE (tail)
+    {
+      regexp = XCAR (tail);
+      if (STRINGP (regexp)
+          && fast_c_string_match_ignore_case (regexp, name,
+                                              namelen) >= 0)
+        return true;
+    }
+  return false;
+}
 static Lisp_Object scratch_font_spec, scratch_font_prefer;
 
 /* Check each font-entity in VEC, and return a list of font-entities
@@ -2677,22 +2697,10 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
        {
          char name[256];
          ptrdiff_t namelen;
-         Lisp_Object tail, regexp;
-
          namelen = font_unparse_xlfd (entity, 0, name, 256);
          if (namelen >= 0)
-           {
-             for (tail = Vface_ignored_fonts; CONSP (tail); tail = XCDR (tail))
-               {
-                 regexp = XCAR (tail);
-                 if (STRINGP (regexp)
-                     && fast_c_string_match_ignore_case (regexp, name,
-                                                         namelen) >= 0)
-                   break;
-               }
-             if (CONSP (tail))
-               continue;
-           }
+            if (font_is_ignored (name, namelen))
+                continue;
        }
       if (NILP (spec))
        {
index 16d765533a76453894c62f2301ee1152393403fc..c4d2ef9d80b749848c16edfd670a6d155b0d874d 100644 (file)
@@ -2228,6 +2228,21 @@ xg_get_file_name (struct frame *f,
 
 static char *x_last_font_name;
 
+#if GTK_CHECK_VERSION (3, 2, 0)
+static gboolean
+xg_font_filter (const PangoFontFamily *family,
+                const PangoFontFace *face,
+                gpointer data)
+{
+  const char *name = pango_font_family_get_name ((PangoFontFamily *)family);
+  ptrdiff_t namelen = strlen (name);
+
+  if (font_is_ignored (name, namelen))
+    return FALSE;
+  return TRUE;
+}
+#endif
+
 /* Pop up a GTK font selector and return the name of the font the user
    selects, as a C string.  The returned font name follows GTK's own
    format:
@@ -2247,6 +2262,9 @@ xg_get_font (struct frame *f, const char *default_name)
   w = gtk_font_chooser_dialog_new
     ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
 
+#if GTK_CHECK_VERSION (3, 2, 0)
+  gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (w), xg_font_filter, NULL, NULL);
+#endif
   if (default_name)
     {
       /* Convert fontconfig names to Gtk names, i.e. remove - before
index 229aa08f817f4bb8ba2f9569778bc47cb80f4b0e..a059f532197b19edd8e60989f336c6201c9c4dd6 100644 (file)
@@ -203,5 +203,10 @@ extern void xg_initialize (void);
 extern bool xg_ignore_gtk_scrollbar;
 
 extern bool xg_gtk_initialized;
+
+#if GTK_CHECK_VERSION (3, 2, 0)
+extern bool font_is_ignored (const char *, ptrdiff_t);
+#endif
+
 #endif /* USE_GTK */
 #endif /* GTKUTIL_H */