aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChong Yidong2012-08-15 15:58:34 +0800
committerChong Yidong2012-08-15 15:58:34 +0800
commitf2045622a553a1f3919ccef6d94fc6e1207e38f6 (patch)
treed938f60c4ace8cd1123d6046f93890022d8f6943 /src
parente568d279c5ba2c408703653aee8f8f764b3eb897 (diff)
downloademacs-f2045622a553a1f3919ccef6d94fc6e1207e38f6.tar.gz
emacs-f2045622a553a1f3919ccef6d94fc6e1207e38f6.zip
Extract better font information from the GTK >= 3.2 font chooser.
* gtkutil.c (xg_get_font): Rename from xg_get_font_name. When using the new font chooser, use gtk_font_chooser_get_font_desc to extract the font descriptor instead of just the font name. In that case, return a font spec instead of a string. (x_last_font_name): Move to this file from xfns.c. * xfns.c (Fx_select_font): The return value can also be a font spec. Move x_last_font_name management to gtkutil.c. * xfaces.c: Make font weight and style symbols non-static. * lisp/frame.el (set-frame-font): Accept font objects.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog13
-rw-r--r--src/gtkutil.c120
-rw-r--r--src/gtkutil.h2
-rw-r--r--src/xfaces.c6
-rw-r--r--src/xfns.c40
5 files changed, 130 insertions, 51 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index adf719d7efd..dc08d002021 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12012-08-15 Chong Yidong <cyd@gnu.org>
2
3 * gtkutil.c (xg_get_font): Rename from xg_get_font_name. When
4 using the new font chooser, use gtk_font_chooser_get_font_desc to
5 extract the font descriptor instead of just the font name. In
6 that case, return a font spec instead of a string.
7 (x_last_font_name): Move to this file from xfns.c.
8
9 * xfns.c (Fx_select_font): The return value can also be a font
10 spec. Move x_last_font_name management to gtkutil.c.
11
12 * xfaces.c: Make font weight and style symbols non-static.
13
12012-08-15 Stefan Monnier <monnier@iro.umontreal.ca> 142012-08-15 Stefan Monnier <monnier@iro.umontreal.ca>
2 15
3 * minibuf.c (read_minibuf): Ignore caller's inhibit-read-only 16 * minibuf.c (read_minibuf): Ignore caller's inhibit-read-only
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 55f5639fdb7..2c9a1377dca 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -24,6 +24,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24#include <signal.h> 24#include <signal.h>
25#include <stdio.h> 25#include <stdio.h>
26#include <setjmp.h> 26#include <setjmp.h>
27#include <ctype.h>
27#include "lisp.h" 28#include "lisp.h"
28#include "xterm.h" 29#include "xterm.h"
29#include "blockinput.h" 30#include "blockinput.h"
@@ -75,16 +76,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
75#define remove_submenu(w) gtk_menu_item_remove_submenu ((w)) 76#define remove_submenu(w) gtk_menu_item_remove_submenu ((w))
76#endif 77#endif
77 78
78#if GTK_MAJOR_VERSION < 3 || \ 79#if GTK_MAJOR_VERSION > 3 || (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 2)
79 (GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION < 2) 80#define USE_NEW_GTK_FONT_CHOOSER 1
81#else
82#define USE_NEW_GTK_FONT_CHOOSER 0
80#define gtk_font_chooser_dialog_new(x, y) \ 83#define gtk_font_chooser_dialog_new(x, y) \
81 gtk_font_selection_dialog_new (x) 84 gtk_font_selection_dialog_new (x)
82#undef GTK_FONT_CHOOSER 85#undef GTK_FONT_CHOOSER
83#define GTK_FONT_CHOOSER(x) GTK_FONT_SELECTION_DIALOG (x) 86#define GTK_FONT_CHOOSER(x) GTK_FONT_SELECTION_DIALOG (x)
84#define gtk_font_chooser_set_font(x, y) \ 87#define gtk_font_chooser_set_font(x, y) \
85 gtk_font_selection_dialog_set_font_name (x, y) 88 gtk_font_selection_dialog_set_font_name (x, y)
86#define gtk_font_chooser_get_font(x) \
87 gtk_font_selection_dialog_get_font_name (x)
88#endif 89#endif
89 90
90#ifndef HAVE_GTK3 91#ifndef HAVE_GTK3
@@ -2007,7 +2008,39 @@ xg_get_file_name (FRAME_PTR f,
2007 return fn; 2008 return fn;
2008} 2009}
2009 2010
2011/***********************************************************************
2012 GTK font chooser
2013 ***********************************************************************/
2014
2010#ifdef HAVE_FREETYPE 2015#ifdef HAVE_FREETYPE
2016
2017#if USE_NEW_GTK_FONT_CHOOSER
2018
2019extern Lisp_Object Qnormal;
2020extern Lisp_Object Qextra_light, Qlight, Qsemi_light, Qsemi_bold;
2021extern Lisp_Object Qbold, Qextra_bold, Qultra_bold;
2022extern Lisp_Object Qoblique, Qitalic;
2023
2024#define XG_WEIGHT_TO_SYMBOL(w) \
2025 (w <= PANGO_WEIGHT_THIN ? Qextra_light \
2026 : w <= PANGO_WEIGHT_ULTRALIGHT ? Qlight \
2027 : w <= PANGO_WEIGHT_LIGHT ? Qsemi_light \
2028 : w < PANGO_WEIGHT_MEDIUM ? Qnormal \
2029 : w <= PANGO_WEIGHT_SEMIBOLD ? Qsemi_bold \
2030 : w <= PANGO_WEIGHT_BOLD ? Qbold \
2031 : w <= PANGO_WEIGHT_HEAVY ? Qextra_bold \
2032 : Qultra_bold)
2033
2034#define XG_STYLE_TO_SYMBOL(s) \
2035 (s == PANGO_STYLE_OBLIQUE ? Qoblique \
2036 : s == PANGO_STYLE_ITALIC ? Qitalic \
2037 : Qnormal)
2038
2039#endif /* USE_NEW_GTK_FONT_CHOOSER */
2040
2041
2042static char *x_last_font_name;
2043
2011/* Pop up a GTK font selector and return the name of the font the user 2044/* Pop up a GTK font selector and return the name of the font the user
2012 selects, as a C string. The returned font name follows GTK's own 2045 selects, as a C string. The returned font name follows GTK's own
2013 format: 2046 format:
@@ -2017,12 +2050,12 @@ xg_get_file_name (FRAME_PTR f,
2017 This can be parsed using font_parse_fcname in font.c. 2050 This can be parsed using font_parse_fcname in font.c.
2018 DEFAULT_NAME, if non-zero, is the default font name. */ 2051 DEFAULT_NAME, if non-zero, is the default font name. */
2019 2052
2020char * 2053Lisp_Object
2021xg_get_font_name (FRAME_PTR f, const char *default_name) 2054xg_get_font (FRAME_PTR f, const char *default_name)
2022{ 2055{
2023 GtkWidget *w; 2056 GtkWidget *w;
2024 char *fontname = NULL;
2025 int done = 0; 2057 int done = 0;
2058 Lisp_Object font = Qnil;
2026 2059
2027#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) 2060#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
2028 sigblock (sigmask (__SIGRTMIN)); 2061 sigblock (sigmask (__SIGRTMIN));
@@ -2031,12 +2064,26 @@ xg_get_font_name (FRAME_PTR f, const char *default_name)
2031 w = gtk_font_chooser_dialog_new 2064 w = gtk_font_chooser_dialog_new
2032 ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f))); 2065 ("Pick a font", GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f)));
2033 2066
2034 if (!default_name) 2067 if (default_name)
2035 default_name = "Monospace 10"; 2068 {
2069 /* Convert fontconfig names to Gtk names, i.e. remove - before
2070 number */
2071 char *p = strrchr (default_name, '-');
2072 if (p)
2073 {
2074 char *ep = p+1;
2075 while (isdigit (*ep))
2076 ++ep;
2077 if (*ep == '\0') *p = ' ';
2078 }
2079 }
2080 else if (x_last_font_name)
2081 default_name = x_last_font_name;
2036 2082
2037 gtk_font_chooser_set_font (GTK_FONT_CHOOSER (w), default_name); 2083 if (default_name)
2038 gtk_widget_set_name (w, "emacs-fontdialog"); 2084 gtk_font_chooser_set_font (GTK_FONT_CHOOSER (w), default_name);
2039 2085
2086 gtk_widget_set_name (w, "emacs-fontdialog");
2040 done = xg_dialog_run (f, w); 2087 done = xg_dialog_run (f, w);
2041 2088
2042#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN) 2089#if defined (HAVE_PTHREAD) && defined (__SIGRTMIN)
@@ -2044,10 +2091,55 @@ xg_get_font_name (FRAME_PTR f, const char *default_name)
2044#endif 2091#endif
2045 2092
2046 if (done == GTK_RESPONSE_OK) 2093 if (done == GTK_RESPONSE_OK)
2047 fontname = gtk_font_chooser_get_font (GTK_FONT_CHOOSER (w)); 2094 {
2095#if USE_NEW_GTK_FONT_CHOOSER
2096 /* Use the GTK3 font chooser. */
2097 PangoFontDescription *desc
2098 = gtk_font_chooser_get_font_desc (GTK_FONT_CHOOSER (w));
2099
2100 if (desc)
2101 {
2102 Lisp_Object args[8];
2103 const char *name = pango_font_description_get_family (desc);
2104 PangoWeight weight = pango_font_description_get_weight (desc);
2105 PangoStyle style = pango_font_description_get_style (desc);
2106
2107 args[0] = QCname;
2108 args[1] = build_string (name);
2109
2110 args[2] = QCsize;
2111 args[3] = make_float (((double) pango_font_description_get_size (desc))
2112 / PANGO_SCALE);
2113
2114 args[4] = QCweight;
2115 args[5] = XG_WEIGHT_TO_SYMBOL (weight);
2116
2117 args[6] = QCslant;
2118 args[7] = XG_STYLE_TO_SYMBOL (style);
2119
2120 font = Ffont_spec (8, args);
2121
2122 pango_font_description_free (desc);
2123 xfree (x_last_font_name);
2124 x_last_font_name = xstrdup (name);
2125 }
2126
2127#else /* Use old font selector, which just returns the font name. */
2128
2129 char *font_name
2130 = gtk_font_selection_dialog_get_font_name (GTK_FONT_CHOOSER (w));
2131
2132 if (font_name)
2133 {
2134 font = build_string (font_name);
2135 g_free (x_last_font_name);
2136 x_last_font_name = font_name;
2137 }
2138#endif /* USE_NEW_GTK_FONT_CHOOSER */
2139 }
2048 2140
2049 gtk_widget_destroy (w); 2141 gtk_widget_destroy (w);
2050 return fontname; 2142 return font;
2051} 2143}
2052#endif /* HAVE_FREETYPE */ 2144#endif /* HAVE_FREETYPE */
2053 2145
@@ -4928,6 +5020,8 @@ xg_initialize (void)
4928 gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK, 5020 gtk_binding_entry_add_signal (binding_set, GDK_KEY_g, GDK_CONTROL_MASK,
4929 "cancel", 0); 5021 "cancel", 0);
4930 update_theme_scrollbar_width (); 5022 update_theme_scrollbar_width ();
5023
5024 x_last_font_name = NULL;
4931} 5025}
4932 5026
4933#endif /* USE_GTK */ 5027#endif /* USE_GTK */
diff --git a/src/gtkutil.h b/src/gtkutil.h
index 94c1a1d96ad..462e879d3e7 100644
--- a/src/gtkutil.h
+++ b/src/gtkutil.h
@@ -86,7 +86,7 @@ extern char *xg_get_file_name (FRAME_PTR f,
86 int mustmatch_p, 86 int mustmatch_p,
87 int only_dir_p); 87 int only_dir_p);
88 88
89extern char *xg_get_font_name (FRAME_PTR f, const char *); 89extern Lisp_Object xg_get_font (FRAME_PTR f, const char *);
90 90
91extern GtkWidget *xg_create_widget (const char *type, 91extern GtkWidget *xg_create_widget (const char *type,
92 const char *name, 92 const char *name,
diff --git a/src/xfaces.c b/src/xfaces.c
index ea73001f758..ed372c6b419 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -319,9 +319,9 @@ static Lisp_Object QCfontset;
319Lisp_Object Qnormal; 319Lisp_Object Qnormal;
320Lisp_Object Qbold; 320Lisp_Object Qbold;
321static Lisp_Object Qline, Qwave; 321static Lisp_Object Qline, Qwave;
322static Lisp_Object Qultra_light, Qextra_light, Qlight; 322Lisp_Object Qultra_light, Qextra_light, Qlight;
323static Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold; 323Lisp_Object Qsemi_light, Qsemi_bold, Qextra_bold, Qultra_bold;
324static Lisp_Object Qoblique, Qreverse_oblique, Qreverse_italic; 324Lisp_Object Qoblique, Qreverse_oblique, Qreverse_italic;
325Lisp_Object Qitalic; 325Lisp_Object Qitalic;
326static Lisp_Object Qultra_condensed, Qextra_condensed; 326static Lisp_Object Qultra_condensed, Qextra_condensed;
327Lisp_Object Qcondensed; 327Lisp_Object Qcondensed;
diff --git a/src/xfns.c b/src/xfns.c
index 3242af937c9..2e7334b7d71 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -21,7 +21,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21#include <stdio.h> 21#include <stdio.h>
22#include <math.h> 22#include <math.h>
23#include <setjmp.h> 23#include <setjmp.h>
24#include <ctype.h>
25#include <unistd.h> 24#include <unistd.h>
26 25
27/* This makes the fields of a Display accessible, in Xlib header files. */ 26/* This makes the fields of a Display accessible, in Xlib header files. */
@@ -140,10 +139,6 @@ static ptrdiff_t image_cache_refcount;
140static int dpyinfo_refcount; 139static int dpyinfo_refcount;
141#endif 140#endif
142 141
143#if defined (USE_GTK) && defined (HAVE_FREETYPE)
144static char *x_last_font_name;
145#endif
146
147static struct x_display_info *x_display_info_for_name (Lisp_Object); 142static struct x_display_info *x_display_info_for_name (Lisp_Object);
148 143
149 144
@@ -5583,14 +5578,15 @@ Otherwise, if ONLY-DIR-P is non-nil, the user can only select directories. */)
5583#ifdef HAVE_FREETYPE 5578#ifdef HAVE_FREETYPE
5584 5579
5585DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0, 5580DEFUN ("x-select-font", Fx_select_font, Sx_select_font, 0, 2, 0,
5586 doc: /* Read a font name using a GTK font selection dialog. 5581 doc: /* Read a font using a GTK dialog.
5587Return a GTK-style font string corresponding to the selection. 5582Return either a font spec (for GTK versions >= 3.2) or a string
5583containing a GTK-style font name.
5588 5584
5589If FRAME is omitted or nil, it defaults to the selected frame. */) 5585FRAME is the frame on which to pop up the font chooser. If omitted or
5586nil, it defaults to the selected frame. */)
5590 (Lisp_Object frame, Lisp_Object ignored) 5587 (Lisp_Object frame, Lisp_Object ignored)
5591{ 5588{
5592 FRAME_PTR f = check_x_frame (frame); 5589 FRAME_PTR f = check_x_frame (frame);
5593 char *name;
5594 Lisp_Object font; 5590 Lisp_Object font;
5595 Lisp_Object font_param; 5591 Lisp_Object font_param;
5596 char *default_name = NULL; 5592 char *default_name = NULL;
@@ -5621,32 +5617,9 @@ If FRAME is omitted or nil, it defaults to the selected frame. */)
5621 default_name = xstrdup (SSDATA (font_param)); 5617 default_name = xstrdup (SSDATA (font_param));
5622 } 5618 }
5623 5619
5624 if (default_name == NULL && x_last_font_name != NULL) 5620 font = xg_get_font (f, default_name);
5625 default_name = xstrdup (x_last_font_name);
5626
5627 /* Convert fontconfig names to Gtk names, i.e. remove - before number */
5628 if (default_name)
5629 {
5630 char *p = strrchr (default_name, '-');
5631 if (p)
5632 {
5633 char *ep = p+1;
5634 while (isdigit (*ep))
5635 ++ep;
5636 if (*ep == '\0') *p = ' ';
5637 }
5638 }
5639
5640 name = xg_get_font_name (f, default_name);
5641 xfree (default_name); 5621 xfree (default_name);
5642 5622
5643 if (name)
5644 {
5645 font = build_string (name);
5646 g_free (x_last_font_name);
5647 x_last_font_name = name;
5648 }
5649
5650 UNBLOCK_INPUT; 5623 UNBLOCK_INPUT;
5651 5624
5652 if (NILP (font)) 5625 if (NILP (font))
@@ -6011,7 +5984,6 @@ When using Gtk+ tooltips, the tooltip face is not used. */);
6011 5984
6012#if defined (USE_GTK) && defined (HAVE_FREETYPE) 5985#if defined (USE_GTK) && defined (HAVE_FREETYPE)
6013 defsubr (&Sx_select_font); 5986 defsubr (&Sx_select_font);
6014 x_last_font_name = NULL;
6015#endif 5987#endif
6016} 5988}
6017 5989