]> git.eshelyaron.com Git - emacs.git/commitdiff
Set Xft defaults if no XSETTING is found, better default for Gtk+ font dialog.
authorJan Djärv <jan.h.d@swipnet.se>
Mon, 23 Nov 2009 08:55:08 +0000 (08:55 +0000)
committerJan Djärv <jan.h.d@swipnet.se>
Mon, 23 Nov 2009 08:55:08 +0000 (08:55 +0000)
* 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.

src/ChangeLog
src/font.c
src/frame.c
src/xfns.c
src/xsettings.c

index 1ac89ec8561e3ac47f4dcc28f8a2275dd15a4b82..21acdae775e65b77a57fb0c9e89f97ba9eef8c21 100644 (file)
@@ -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
index aa07c7805d163d37586c613061f0513f5f9ff289..5aa14ca4211f2ac89a7f7141ba1b52e692532063 100644 (file)
@@ -218,7 +218,7 @@ font_make_object (size, entity, pixelsize)
        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 @@ font_put_extra (font, prop, val)
       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 @@ font_open_by_name (f, name)
      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 @@ DEFUN ("copy-font-spec", Fcopy_font_spec, Scopy_font_spec, 1, 1, 0,
   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))
index 323bfc1c37d26c331fe394a4c3bc1ad879f723a4..2a72e43cd40bed4fca655c5ea1878a97277158c4 100644 (file)
@@ -205,6 +205,8 @@ extern Lisp_Object get_minibuffer ();
 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;
+
 \f
 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
        doc: /* Return non-nil if OBJECT is a frame.
@@ -3359,7 +3361,7 @@ x_set_font (f, arg, oldval)
      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 @@ x_set_font (f, arg, oldval)
      never fail.  */
   if (STRINGP (arg))
     {
+      font_param = arg;
       fontset = fs_query_fontset (arg, 0);
       if (fontset < 0)
        {
@@ -3401,10 +3404,12 @@ x_set_font (f, arg, oldval)
        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_set_font (f, arg, oldval)
 
   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.  */
index 0ae6f95b30bef4b67ba8bbe1cbfcb1a2cd918e90..27d0b025a248f7228e442128c0df141f0065f987 100644 (file)
@@ -22,6 +22,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #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 Qnone;
 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 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
   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)
     {
index 0dabc060b9a1c4252b81ee206d950c0735e6e85f..68c1e0c4eeb3536bba81a7aa4ec54aea3eb47254 100644 (file)
@@ -367,6 +367,25 @@ read_xft_settings (dpyinfo, settings)
   return rc == Success;
 }
 
+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;
@@ -546,6 +565,8 @@ init_xfd_settings (dpyinfo)
   get_prop_window (dpyinfo);
   if (dpyinfo->xsettings_window != None)
     apply_xft_settings (dpyinfo, False);
+  else
+    set_default_xft_settings (dpyinfo);
 
   UNBLOCK_INPUT;