From: Jan Djärv Date: Mon, 23 Nov 2009 08:55:08 +0000 (+0000) Subject: Set Xft defaults if no XSETTING is found, better default for Gtk+ font dialog. X-Git-Tag: emacs-pretest-23.1.90~266 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=581e51e8918b3ba9b58e67768a1de39ce5f1cbd3;p=emacs.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 1ac89ec8561..21acdae775e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2009-11-23 Jan Djärv + + * 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 * 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) 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)) 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 (); 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 @@ 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. */ 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 . */ #include #include #include +#include #ifdef HAVE_UNISTD_H #include @@ -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) { diff --git a/src/xsettings.c b/src/xsettings.c index 0dabc060b9a..68c1e0c4eeb 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -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;