all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: [Emacs-diffs] master 50c5d56: --with-cairo is no longer experimental
Date: Fri, 08 Nov 2019 22:40:52 +0100	[thread overview]
Message-ID: <m2ftiykpwb.fsf@gmail.com> (raw)
In-Reply-To: 83k18beh1b.fsf@gnu.org

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

>>>>> On Thu, 07 Nov 2019 19:24:16 +0200, Eli Zaretskii <eliz@gnu.org> said:

    Eli> Just making GTK font selection take face-ignored-fonts into account
    Eli> sounds like a nice improvement to me, almost a bugfix.  So if this is
    Eli> not too tricky to implement, I think we should go this way.
    >> 
    >> Itʼs not too hard, I can get to it in the next week or so.

    Eli> Thank you.

The following works for me:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-GTK-font-chooser-respect-face-ignored-fonts.patch --]
[-- Type: text/x-patch, Size: 3960 bytes --]

From bc38e74a504d0413f7a9c4a2395917601b260035 Mon Sep 17 00:00:00 2001
From: Robert Pluim <rpluim@gmail.com>
Date: Fri, 8 Nov 2019 21:07:10 +0100
Subject: [PATCH] Make GTK font chooser respect face-ignored-fonts
To: emacs-devel@gnu.org

* src/font.c (font_matches_ignored_fonts): New function, abstracts
out check for matching Vface_ignored_fonts.
(font_delete_unmatched): Use it.

* src/gtkutil.h: Add prototype for font_matches_ignored_fonts.
* src/gtkutil.c (xg_font_filter): New function, filters out fonts
from the GTK font chooser.  Uses font_matches_ignored_fonts.
(xg_get_font): Set the GTK chooser font filter to xg_font_filter.
---
 src/font.c    | 34 ++++++++++++++++++++--------------
 src/gtkutil.c | 18 ++++++++++++++++++
 src/gtkutil.h |  5 +++++
 3 files changed, 43 insertions(+), 14 deletions(-)

diff --git a/src/font.c b/src/font.c
index 8dfbfa0fac..9f92260d0c 100644
--- a/src/font.c
+++ b/src/font.c
@@ -2655,6 +2655,24 @@ 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_matches_ignored_fonts (const char *name, ptrdiff_t namelen)
+{
+  Lisp_Object tail, regexp;
+  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)
+        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 +2695,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_matches_ignored_fonts (name, namelen))
+                continue;
 	}
       if (NILP (spec))
 	{
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 16d765533a..0cda21cdd1 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -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_matches_ignored_fonts (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
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 229aa08f81..fea3271637 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -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_matches_ignored_fonts (const char *, ptrdiff_t);
+#endif
+
 #endif /* USE_GTK */
 #endif /* GTKUTIL_H */
-- 
2.23.0


  reply	other threads:[~2019-11-08 21:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20190619070851.22726.77187@vcs0.savannah.gnu.org>
     [not found] ` <20190619070853.E841E208EC@vcs0.savannah.gnu.org>
2019-11-05 10:33   ` [Emacs-diffs] master 50c5d56: --with-cairo is no longer experimental Robert Pluim
2019-11-05 18:25     ` Eli Zaretskii
2019-11-05 20:07       ` Robert Pluim
2019-11-06  3:34         ` Eli Zaretskii
2019-11-06  7:39           ` Robert Pluim
2019-11-06 16:11             ` Eli Zaretskii
2019-11-07  8:48               ` Robert Pluim
2019-11-07 14:31                 ` Eli Zaretskii
2019-11-07 16:11                   ` Robert Pluim
2019-11-07 17:24                     ` Eli Zaretskii
2019-11-08 21:40                       ` Robert Pluim [this message]
2019-11-08 22:59                         ` Paul Eggert
2019-11-12  7:47                           ` Robert Pluim
2019-11-12 13:32                             ` Stefan Monnier
2019-11-09  6:44                         ` Eli Zaretskii
2019-11-12  7:51                           ` Robert Pluim
2019-11-14  9:48                             ` Robert Pluim
2019-11-14 14:10                               ` Eli Zaretskii
2019-11-14 11:53                             ` Eli Zaretskii
2019-11-14 12:21                               ` Robert Pluim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2ftiykpwb.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.