changeset 106201:01190029e5d3

Set Xft defaults if no XSETTING is found, better default for Gtk+ font dialog. * xfns.c (Fx_select_font): Try to convert Fontconfig name to Gtk name because that is what Gtk+ font dialog understands. * font.c (font_make_object, Fcopy_font_spec): Use Fcopy_alist instead of Fcopy_sequence. (font_open_by_name): Put name given into QCname for font-object returned. * frame.c (x_set_font): Save original font name as frame parameter font-parameter. * xsettings.c (set_default_xft_settings): New function. (init_xfd_settings): Call set_default_xft_settings if no XSETTINGS window is found.
author Jan Djärv <jan.h.d@swipnet.se>
date Mon, 23 Nov 2009 08:55:08 +0000
parents 34a3dd721f80
children 6a5f884264d9
files src/ChangeLog src/font.c src/frame.c src/xfns.c src/xsettings.c
diffstat 5 files changed, 80 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Mon Nov 23 05:37:34 2009 +0000
+++ b/src/ChangeLog	Mon Nov 23 08:55:08 2009 +0000
@@ -1,3 +1,19 @@
+2009-11-23  Jan Djärv  <jan.h.d@swipnet.se>
+
+	* xfns.c (Fx_select_font): Try to convert Fontconfig name to Gtk name
+	because that is what Gtk+ font dialog understands.
+
+	* font.c (font_make_object, Fcopy_font_spec): Use Fcopy_alist instead
+	of Fcopy_sequence.
+	(font_open_by_name): Put name given into QCname for font-object returned.
+
+	* frame.c (x_set_font): Save original font name as frame parameter
+	font-parameter.
+
+	* xsettings.c (set_default_xft_settings): New function.
+	(init_xfd_settings): Call set_default_xft_settings if no XSETTINGS window
+	is found.
+
 2009-11-22  Andreas Schwab  <schwab@linux-m68k.org>
 
 	* search.c (simple_search): Avoid CHAR_TO_BYTE in inner loop when
--- a/src/font.c	Mon Nov 23 05:37:34 2009 +0000
+++ b/src/font.c	Mon Nov 23 08:55:08 2009 +0000
@@ -218,7 +218,7 @@
 	font->props[i] = AREF (entity, i);
       if (! NILP (AREF (entity, FONT_EXTRA_INDEX)))
 	font->props[FONT_EXTRA_INDEX]
-	  = Fcopy_sequence (AREF (entity, FONT_EXTRA_INDEX));
+	  = Fcopy_alist (AREF (entity, FONT_EXTRA_INDEX));
     }
   if (size > 0)
     font->props[FONT_SIZE_INDEX] = make_number (pixelsize);
@@ -721,10 +721,12 @@
       while (CONSP (extra)
 	     && NILP (Fstring_lessp (prop, XCAR (XCAR (extra)))))
 	prev = extra, extra = XCDR (extra);
-      if (NILP (prev))
-	ASET (font, FONT_EXTRA_INDEX, Fcons (Fcons (prop, val), extra));
-      else
-	XSETCDR (prev, Fcons (Fcons (prop, val), extra));
+
+      if (NILP (prev)) 
+        ASET (font, FONT_EXTRA_INDEX, Fcons (Fcons (prop, val), extra));
+      else 
+        XSETCDR (prev, Fcons (Fcons (prop, val), extra));
+      
       return val;
     }
   XSETCDR (slot, val);
@@ -3600,12 +3602,16 @@
      char *name;
 {
   Lisp_Object args[2];
-  Lisp_Object spec;
+  Lisp_Object spec, ret;
 
   args[0] = QCname;
   args[1] = make_unibyte_string (name, strlen (name));
   spec = Ffont_spec (2, args);
-  return font_open_by_spec (f, spec);
+  ret = font_open_by_spec (f, spec);
+  /* Do not loose name originally put in.  */
+  font_put_extra (ret, QCname, args[1]);
+
+  return ret;
 }
 
 
@@ -4137,7 +4143,7 @@
   new_spec = font_make_spec ();
   for (i = 1; i < FONT_EXTRA_INDEX; i++)
     ASET (new_spec, i, AREF (font, i));
-  extra = Fcopy_sequence (AREF (font, FONT_EXTRA_INDEX));
+  extra = Fcopy_alist (AREF (font, FONT_EXTRA_INDEX));
   /* We must remove :font-entity property.  */
   for (prev = Qnil, tail = extra; CONSP (tail); prev = tail, tail = XCDR (tail))
     if (EQ (XCAR (XCAR (tail)), QCfont_entity))
--- a/src/frame.c	Mon Nov 23 05:37:34 2009 +0000
+++ b/src/frame.c	Mon Nov 23 08:55:08 2009 +0000
@@ -205,6 +205,8 @@
 extern Lisp_Object Fhandle_switch_frame ();
 extern Lisp_Object Fredirect_frame_focus ();
 extern Lisp_Object x_get_focus_frame ();
+extern Lisp_Object QCname, Qfont_param;
+
 
 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
        doc: /* Return non-nil if OBJECT is a frame.
@@ -3359,7 +3361,7 @@
      struct frame *f;
      Lisp_Object arg, oldval;
 {
-  Lisp_Object frame, font_object;
+  Lisp_Object frame, font_object, font_param = Qnil;
   int fontset = -1;
 
   /* Set the frame parameter back to the old value because we may
@@ -3371,6 +3373,7 @@
      never fail.  */
   if (STRINGP (arg))
     {
+      font_param = arg;
       fontset = fs_query_fontset (arg, 0);
       if (fontset < 0)
 	{
@@ -3401,10 +3404,12 @@
 	error ("Unknown fontset: %s", SDATA (XCAR (arg)));
       font_object = XCDR (arg);
       arg = AREF (font_object, FONT_NAME_INDEX);
+      font_param = Ffont_get (font_object, QCname);
     }
   else if (FONT_OBJECT_P (arg))
     {
       font_object = arg;
+      font_param = Ffont_get (font_object, QCname);
       /* This is to store the XLFD font name in the frame parameter for
 	 backward compatibility.  We should store the font-object
 	 itself in the future.  */
@@ -3429,6 +3434,9 @@
 
   x_new_font (f, font_object, fontset);
   store_frame_param (f, Qfont, arg);
+#ifdef HAVE_X_WINDOWS
+  store_frame_param (f, Qfont_param, font_param);
+#endif
   /* Recalculate toolbar height.  */
   f->n_tool_bar_rows = 0;
   /* Ensure we redraw it.  */
--- a/src/xfns.c	Mon Nov 23 05:37:34 2009 +0000
+++ b/src/xfns.c	Mon Nov 23 08:55:08 2009 +0000
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <math.h>
 #include <setjmp.h>
+#include <ctype.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -196,7 +197,7 @@
 Lisp_Object Qsuppress_icon;
 Lisp_Object Qundefined_color;
 Lisp_Object Qcompound_text, Qcancel_timer;
-static Lisp_Object Qfont_param;
+Lisp_Object Qfont_param;
 
 /* In dispnew.c */
 
@@ -5607,20 +5608,34 @@
   GCPRO2(font_param, font);
 
   XSETFONT (font, FRAME_FONT (f));
-  font_param = Ffont_get (font, intern_c_string (":name"));
+  font_param = Ffont_get (font, intern (":name"));
   if (STRINGP (font_param))
-    default_name = SDATA (font_param);
+    default_name = xstrdup (SDATA (font_param));
   else 
     {
       font_param = Fframe_parameter (frame, Qfont_param);
       if (STRINGP (font_param))
-        default_name = SDATA (font_param);
+        default_name = xstrdup (SDATA (font_param));
     }
 
   if (default_name == NULL && x_last_font_name != NULL)
-    default_name = x_last_font_name;
+    default_name = xstrdup (x_last_font_name);
+
+  /* Convert fontconfig names to Gtk names, i.e. remove - before number */
+  if (default_name) 
+    {
+      char *p = strrchr (default_name, '-');
+      if (p)
+        {
+          char *ep = p+1;
+          while (isdigit (*ep))
+            ++ep;
+          if (*ep == '\0') *p = ' ';
+        }
+    }
 
   name = xg_get_font_name (f, default_name);
+  xfree (default_name);
 
   if (name)
     {
--- a/src/xsettings.c	Mon Nov 23 05:37:34 2009 +0000
+++ b/src/xsettings.c	Mon Nov 23 08:55:08 2009 +0000
@@ -368,6 +368,25 @@
 }
 
 static void
+set_default_xft_settings (dpyinfo)
+     struct x_display_info *dpyinfo;
+{
+  FcPattern *pat;
+  pat = FcPatternCreate ();
+  XftDefaultSubstitute (dpyinfo->display,
+                        XScreenNumberOfScreen (dpyinfo->screen),
+                        pat);
+
+  FcPatternDel (pat, FC_ANTIALIAS);
+  FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);
+  FcPatternDel (pat, FC_HINTING);
+  FcPatternAddBool (pat, FC_HINTING, FcTrue);
+  FcPatternDel (pat, FC_HINT_STYLE);
+  FcPatternAddInteger (pat, FC_HINT_STYLE,FC_HINT_MEDIUM);
+  XftDefaultSet (dpyinfo->display, pat);
+}
+
+static void
 apply_xft_settings (dpyinfo, send_event_p)
      struct x_display_info *dpyinfo;
      int send_event_p;
@@ -546,6 +565,8 @@
   get_prop_window (dpyinfo);
   if (dpyinfo->xsettings_window != None)
     apply_xft_settings (dpyinfo, False);
+  else
+    set_default_xft_settings (dpyinfo);
 
   UNBLOCK_INPUT;