aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2009-11-23 08:55:08 +0000
committerJan Djärv2009-11-23 08:55:08 +0000
commit581e51e8918b3ba9b58e67768a1de39ce5f1cbd3 (patch)
treeb210e82974c9e4ab1d3cc1c0a9e86348a425526b /src
parent0f202d5d8fa1f0dea9c1e5e52e6ad66e4848aa75 (diff)
downloademacs-581e51e8918b3ba9b58e67768a1de39ce5f1cbd3.tar.gz
emacs-581e51e8918b3ba9b58e67768a1de39ce5f1cbd3.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog16
-rw-r--r--src/font.c22
-rw-r--r--src/frame.c10
-rw-r--r--src/xfns.c25
-rw-r--r--src/xsettings.c21
5 files changed, 80 insertions, 14 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 1ac89ec8561..21acdae775e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
12009-11-23 Jan Djärv <jan.h.d@swipnet.se>
2
3 * xfns.c (Fx_select_font): Try to convert Fontconfig name to Gtk name
4 because that is what Gtk+ font dialog understands.
5
6 * font.c (font_make_object, Fcopy_font_spec): Use Fcopy_alist instead
7 of Fcopy_sequence.
8 (font_open_by_name): Put name given into QCname for font-object returned.
9
10 * frame.c (x_set_font): Save original font name as frame parameter
11 font-parameter.
12
13 * xsettings.c (set_default_xft_settings): New function.
14 (init_xfd_settings): Call set_default_xft_settings if no XSETTINGS window
15 is found.
16
12009-11-22 Andreas Schwab <schwab@linux-m68k.org> 172009-11-22 Andreas Schwab <schwab@linux-m68k.org>
2 18
3 * search.c (simple_search): Avoid CHAR_TO_BYTE in inner loop when 19 * search.c (simple_search): Avoid CHAR_TO_BYTE in inner loop when
diff --git a/src/font.c b/src/font.c
index aa07c7805d1..5aa14ca4211 100644
--- a/src/font.c
+++ b/src/font.c
@@ -218,7 +218,7 @@ font_make_object (size, entity, pixelsize)
218 font->props[i] = AREF (entity, i); 218 font->props[i] = AREF (entity, i);
219 if (! NILP (AREF (entity, FONT_EXTRA_INDEX))) 219 if (! NILP (AREF (entity, FONT_EXTRA_INDEX)))
220 font->props[FONT_EXTRA_INDEX] 220 font->props[FONT_EXTRA_INDEX]
221 = Fcopy_sequence (AREF (entity, FONT_EXTRA_INDEX)); 221 = Fcopy_alist (AREF (entity, FONT_EXTRA_INDEX));
222 } 222 }
223 if (size > 0) 223 if (size > 0)
224 font->props[FONT_SIZE_INDEX] = make_number (pixelsize); 224 font->props[FONT_SIZE_INDEX] = make_number (pixelsize);
@@ -721,10 +721,12 @@ font_put_extra (font, prop, val)
721 while (CONSP (extra) 721 while (CONSP (extra)
722 && NILP (Fstring_lessp (prop, XCAR (XCAR (extra))))) 722 && NILP (Fstring_lessp (prop, XCAR (XCAR (extra)))))
723 prev = extra, extra = XCDR (extra); 723 prev = extra, extra = XCDR (extra);
724 if (NILP (prev)) 724
725 ASET (font, FONT_EXTRA_INDEX, Fcons (Fcons (prop, val), extra)); 725 if (NILP (prev))
726 else 726 ASET (font, FONT_EXTRA_INDEX, Fcons (Fcons (prop, val), extra));
727 XSETCDR (prev, Fcons (Fcons (prop, val), extra)); 727 else
728 XSETCDR (prev, Fcons (Fcons (prop, val), extra));
729
728 return val; 730 return val;
729 } 731 }
730 XSETCDR (slot, val); 732 XSETCDR (slot, val);
@@ -3600,12 +3602,16 @@ font_open_by_name (f, name)
3600 char *name; 3602 char *name;
3601{ 3603{
3602 Lisp_Object args[2]; 3604 Lisp_Object args[2];
3603 Lisp_Object spec; 3605 Lisp_Object spec, ret;
3604 3606
3605 args[0] = QCname; 3607 args[0] = QCname;
3606 args[1] = make_unibyte_string (name, strlen (name)); 3608 args[1] = make_unibyte_string (name, strlen (name));
3607 spec = Ffont_spec (2, args); 3609 spec = Ffont_spec (2, args);
3608 return font_open_by_spec (f, spec); 3610 ret = font_open_by_spec (f, spec);
3611 /* Do not loose name originally put in. */
3612 font_put_extra (ret, QCname, args[1]);
3613
3614 return ret;
3609} 3615}
3610 3616
3611 3617
@@ -4137,7 +4143,7 @@ DEFUN ("copy-font-spec", Fcopy_font_spec, Scopy_font_spec, 1, 1, 0,
4137 new_spec = font_make_spec (); 4143 new_spec = font_make_spec ();
4138 for (i = 1; i < FONT_EXTRA_INDEX; i++) 4144 for (i = 1; i < FONT_EXTRA_INDEX; i++)
4139 ASET (new_spec, i, AREF (font, i)); 4145 ASET (new_spec, i, AREF (font, i));
4140 extra = Fcopy_sequence (AREF (font, FONT_EXTRA_INDEX)); 4146 extra = Fcopy_alist (AREF (font, FONT_EXTRA_INDEX));
4141 /* We must remove :font-entity property. */ 4147 /* We must remove :font-entity property. */
4142 for (prev = Qnil, tail = extra; CONSP (tail); prev = tail, tail = XCDR (tail)) 4148 for (prev = Qnil, tail = extra; CONSP (tail); prev = tail, tail = XCDR (tail))
4143 if (EQ (XCAR (XCAR (tail)), QCfont_entity)) 4149 if (EQ (XCAR (XCAR (tail)), QCfont_entity))
diff --git a/src/frame.c b/src/frame.c
index 323bfc1c37d..2a72e43cd40 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -205,6 +205,8 @@ extern Lisp_Object get_minibuffer ();
205extern Lisp_Object Fhandle_switch_frame (); 205extern Lisp_Object Fhandle_switch_frame ();
206extern Lisp_Object Fredirect_frame_focus (); 206extern Lisp_Object Fredirect_frame_focus ();
207extern Lisp_Object x_get_focus_frame (); 207extern Lisp_Object x_get_focus_frame ();
208extern Lisp_Object QCname, Qfont_param;
209
208 210
209DEFUN ("framep", Fframep, Sframep, 1, 1, 0, 211DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
210 doc: /* Return non-nil if OBJECT is a frame. 212 doc: /* Return non-nil if OBJECT is a frame.
@@ -3359,7 +3361,7 @@ x_set_font (f, arg, oldval)
3359 struct frame *f; 3361 struct frame *f;
3360 Lisp_Object arg, oldval; 3362 Lisp_Object arg, oldval;
3361{ 3363{
3362 Lisp_Object frame, font_object; 3364 Lisp_Object frame, font_object, font_param = Qnil;
3363 int fontset = -1; 3365 int fontset = -1;
3364 3366
3365 /* Set the frame parameter back to the old value because we may 3367 /* Set the frame parameter back to the old value because we may
@@ -3371,6 +3373,7 @@ x_set_font (f, arg, oldval)
3371 never fail. */ 3373 never fail. */
3372 if (STRINGP (arg)) 3374 if (STRINGP (arg))
3373 { 3375 {
3376 font_param = arg;
3374 fontset = fs_query_fontset (arg, 0); 3377 fontset = fs_query_fontset (arg, 0);
3375 if (fontset < 0) 3378 if (fontset < 0)
3376 { 3379 {
@@ -3401,10 +3404,12 @@ x_set_font (f, arg, oldval)
3401 error ("Unknown fontset: %s", SDATA (XCAR (arg))); 3404 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3402 font_object = XCDR (arg); 3405 font_object = XCDR (arg);
3403 arg = AREF (font_object, FONT_NAME_INDEX); 3406 arg = AREF (font_object, FONT_NAME_INDEX);
3407 font_param = Ffont_get (font_object, QCname);
3404 } 3408 }
3405 else if (FONT_OBJECT_P (arg)) 3409 else if (FONT_OBJECT_P (arg))
3406 { 3410 {
3407 font_object = arg; 3411 font_object = arg;
3412 font_param = Ffont_get (font_object, QCname);
3408 /* This is to store the XLFD font name in the frame parameter for 3413 /* This is to store the XLFD font name in the frame parameter for
3409 backward compatibility. We should store the font-object 3414 backward compatibility. We should store the font-object
3410 itself in the future. */ 3415 itself in the future. */
@@ -3429,6 +3434,9 @@ x_set_font (f, arg, oldval)
3429 3434
3430 x_new_font (f, font_object, fontset); 3435 x_new_font (f, font_object, fontset);
3431 store_frame_param (f, Qfont, arg); 3436 store_frame_param (f, Qfont, arg);
3437#ifdef HAVE_X_WINDOWS
3438 store_frame_param (f, Qfont_param, font_param);
3439#endif
3432 /* Recalculate toolbar height. */ 3440 /* Recalculate toolbar height. */
3433 f->n_tool_bar_rows = 0; 3441 f->n_tool_bar_rows = 0;
3434 /* Ensure we redraw it. */ 3442 /* Ensure we redraw it. */
diff --git a/src/xfns.c b/src/xfns.c
index 0ae6f95b30b..27d0b025a24 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22#include <stdio.h> 22#include <stdio.h>
23#include <math.h> 23#include <math.h>
24#include <setjmp.h> 24#include <setjmp.h>
25#include <ctype.h>
25 26
26#ifdef HAVE_UNISTD_H 27#ifdef HAVE_UNISTD_H
27#include <unistd.h> 28#include <unistd.h>
@@ -196,7 +197,7 @@ Lisp_Object Qnone;
196Lisp_Object Qsuppress_icon; 197Lisp_Object Qsuppress_icon;
197Lisp_Object Qundefined_color; 198Lisp_Object Qundefined_color;
198Lisp_Object Qcompound_text, Qcancel_timer; 199Lisp_Object Qcompound_text, Qcancel_timer;
199static Lisp_Object Qfont_param; 200Lisp_Object Qfont_param;
200 201
201/* In dispnew.c */ 202/* In dispnew.c */
202 203
@@ -5607,20 +5608,34 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
5607 GCPRO2(font_param, font); 5608 GCPRO2(font_param, font);
5608 5609
5609 XSETFONT (font, FRAME_FONT (f)); 5610 XSETFONT (font, FRAME_FONT (f));
5610 font_param = Ffont_get (font, intern_c_string (":name")); 5611 font_param = Ffont_get (font, intern (":name"));
5611 if (STRINGP (font_param)) 5612 if (STRINGP (font_param))
5612 default_name = SDATA (font_param); 5613 default_name = xstrdup (SDATA (font_param));
5613 else 5614 else
5614 { 5615 {
5615 font_param = Fframe_parameter (frame, Qfont_param); 5616 font_param = Fframe_parameter (frame, Qfont_param);
5616 if (STRINGP (font_param)) 5617 if (STRINGP (font_param))
5617 default_name = SDATA (font_param); 5618 default_name = xstrdup (SDATA (font_param));
5618 } 5619 }
5619 5620
5620 if (default_name == NULL && x_last_font_name != NULL) 5621 if (default_name == NULL && x_last_font_name != NULL)
5621 default_name = x_last_font_name; 5622 default_name = xstrdup (x_last_font_name);
5623
5624 /* Convert fontconfig names to Gtk names, i.e. remove - before number */
5625 if (default_name)
5626 {
5627 char *p = strrchr (default_name, '-');
5628 if (p)
5629 {
5630 char *ep = p+1;
5631 while (isdigit (*ep))
5632 ++ep;
5633 if (*ep == '\0') *p = ' ';
5634 }
5635 }
5622 5636
5623 name = xg_get_font_name (f, default_name); 5637 name = xg_get_font_name (f, default_name);
5638 xfree (default_name);
5624 5639
5625 if (name) 5640 if (name)
5626 { 5641 {
diff --git a/src/xsettings.c b/src/xsettings.c
index 0dabc060b9a..68c1e0c4eeb 100644
--- a/src/xsettings.c
+++ b/src/xsettings.c
@@ -368,6 +368,25 @@ read_xft_settings (dpyinfo, settings)
368} 368}
369 369
370static void 370static void
371set_default_xft_settings (dpyinfo)
372 struct x_display_info *dpyinfo;
373{
374 FcPattern *pat;
375 pat = FcPatternCreate ();
376 XftDefaultSubstitute (dpyinfo->display,
377 XScreenNumberOfScreen (dpyinfo->screen),
378 pat);
379
380 FcPatternDel (pat, FC_ANTIALIAS);
381 FcPatternAddBool (pat, FC_ANTIALIAS, FcTrue);
382 FcPatternDel (pat, FC_HINTING);
383 FcPatternAddBool (pat, FC_HINTING, FcTrue);
384 FcPatternDel (pat, FC_HINT_STYLE);
385 FcPatternAddInteger (pat, FC_HINT_STYLE,FC_HINT_MEDIUM);
386 XftDefaultSet (dpyinfo->display, pat);
387}
388
389static void
371apply_xft_settings (dpyinfo, send_event_p) 390apply_xft_settings (dpyinfo, send_event_p)
372 struct x_display_info *dpyinfo; 391 struct x_display_info *dpyinfo;
373 int send_event_p; 392 int send_event_p;
@@ -546,6 +565,8 @@ init_xfd_settings (dpyinfo)
546 get_prop_window (dpyinfo); 565 get_prop_window (dpyinfo);
547 if (dpyinfo->xsettings_window != None) 566 if (dpyinfo->xsettings_window != None)
548 apply_xft_settings (dpyinfo, False); 567 apply_xft_settings (dpyinfo, False);
568 else
569 set_default_xft_settings (dpyinfo);
549 570
550 UNBLOCK_INPUT; 571 UNBLOCK_INPUT;
551 572