Commit 99852628 authored by Jan Djärv's avatar Jan Djärv

Lucid menus can now use Xft for fonts.

* xsettings.c (current_font, SYSTEM_FONT, XSETTINGS_FONT_NAME): New.
(parse_xft_settings): Also check for XSETTINGS_FONT_NAME and save that
in current_font.
(init_gconf): Read value of SYSTEM_FONT and save it in current_font.
(Ffont_get_system_normal_font, xsettings_get_system_normal_font): New
functions.
(syms_of_xsettings): Initialize current_font. defsubr
Sfont_get_system_normal_font.

* xsettings.h (Ffont_get_system_normal_font,
xsettings_get_system_normal_font): Declare.

* xfns.c (extern xlwmenu_default_font): Remove.
(Fx_create_frame): Remove setting of xlwmenu_default_font, moved
to xlwmenu.c.

* menu.c (digest_single_submenu): If USE_LUCID and HAVE_XFT, encode
menu items in UTF-8.

* xmenu.c: include xsettings.h and xlwmenu.h if USE_LUCID.
(apply_systemfont_to_menu): New function.
(set_frame_menubar, create_and_show_popup_menu): Call
apply_systemfont_to_menu.

* xlwmenu.c (xlwmenu_default_font): Make static.
(xlwMenuResources): Add XtNfaceName and XtNdefaultFace.
(string_width): Use XftTextExtentsUtf8 if HAVE_XFT.
(MENU_FONT_HEIGHT, MENU_FONT_ASCENT): Add versions for
HAVE_XFT.
(size_menu): Set max_rest_width in window_state structure.
(display_menu_item): If HAVE_XFT and xft_draw is set, use
XftDrawRect and XftDrawStringUtf8 to draw text.
(make_windows_if_needed): Set max_rest_width and xft_draw
in windows[i].
(openXftFont): New.
(XlwMenuInitialize): Call openXftFont if HAVE_XFT. If mw->menu.font
is not set, load font fixed and save it in xlwmenu_default_font.
(XlwMenuInitialize): Set max_rest_width and xft_draw in windows[0].
(XlwMenuClassInitialize): Initialize xlwmenu_default_font.
(XlwMenuRealize): Set xft_fg, xft_bg, xft_disabled_fg and
windows[0].xft_draw if xft_font is set.
(XlwMenuDestroy): Destroy all xft_draw and close xft_font.
(facename_changed): New.
(XlwMenuSetValues): Call facename_changed. If face name did change,
close old fonts and destroy xft_draw:s.  Then create new ones.

* xlwmenu.h (XtNfaceName, XtCFaceName, XtNdefaultFace,
XtCDefaultFace): New.

* xlwmenuP.h (_window_state): Add max_rest_width and xft_draw.
(_XlwMenu_part): Add faceName,xft_fg, xft_bg, xft_disabled_fg and
xft_font.

* xresources.texi (Lucid Resources): Mention faceName to set Xft fonts.
parent 9a15cc5a
2010-04-08 Jan Djärv <jan.h.d@swipnet.se>
* xresources.texi (Lucid Resources): Mention faceName to set Xft fonts.
2010-03-30 Eli Zaretskii <eliz@gnu.org>
* mule.texi (Input Methods): Mention "C-x 8 RET" and add a
......
......@@ -415,7 +415,7 @@ Emacs.pane.menubar.@var{resource}: @var{value}
@end example
@noindent
For example, to specify the font @samp{8x16} for the menu-bar items,
For example, to specify the font @samp{Courier-12} for the menu-bar items,
write this:
@end ifnottex
@iftex
......@@ -423,32 +423,35 @@ write this:
with the Lucid menu widgets, then the menu bar is a separate widget
and has its own resources. The resource specifications start with
@samp{Emacs.pane.menubar}---for instance, to specify the font
@samp{8x16} for the menu-bar items, write this:
@samp{Courier-12} for the menu-bar items, write this:
@end iftex
@example
Emacs.pane.menubar.font: 8x16
Emacs.pane.menubar.faceName: Courier-12
@end example
@noindent
Resources for @emph{non-menubar} toolkit pop-up menus have
@samp{menu*} instead of @samp{pane.menubar}. For example, to specify
the font @samp{8x16} for the pop-up menu items, write this:
To specify a font, use fontconfig font names as values to the @code{faceName}
resource.
If Emacs is not built with the Xft library, Lucid menus can only display
old style fonts. If Emacs is built with Xft and you prefer the old fonts,
you have to specify @samp{none} to @code{faceName}:
@example
Emacs.menu*.font: 8x16
Emacs.pane.menubar.faceName: none
@end example
@noindent
For dialog boxes, use @samp{dialog*}:
To specify a non-Xft font, use @code{font}. For example:
@example
Emacs.dialog*.font: 8x16
Emacs.pane.menubar.font: lucidasanstypewriter-10
@end example
@noindent
The Lucid menus can display multilingual text in your locale. For
more information about fontsets see the man page for
The Lucid menus can display multilingual text in your locale with old style
fonts. For more information about fontsets see the man page for
@code{XCreateFontSet}. To enable multilingual menu text you specify a
@code{fontSet} resource instead of the font resource. If both
@code{font} and @code{fontSet} resources are specified, the
......@@ -461,6 +464,22 @@ for both the popup and menu bar menus, write this:
Emacs*menu*fontSet: -*-helvetica-medium-r-*--*-120-*-*-*-*-*-*,*
@end example
@noindent
Resources for @emph{non-menubar} toolkit pop-up menus have
@samp{menu*} instead of @samp{pane.menubar}. For example, to specify
the font @samp{8x16} for the pop-up menu items, write this:
@example
Emacs.menu*.font: 8x16
@end example
@noindent
For dialog boxes, use @samp{dialog*}:
@example
Emacs.dialog*.font: 8x16
@end example
@noindent
The @samp{*menu*} as a wildcard matches @samp{pane.menubar} and
@samp{menu@dots{}}.
......@@ -473,6 +492,8 @@ approach should work on both kinds of systems.
Here is a list of the specific resources for menu bars and pop-up menus:
@table @code
@item faceName
Xft font for menu item text.
@item font
Font for menu item text.
@item fontSet
......
......@@ -65,6 +65,8 @@ Algorithm.
** GTK scroll-bars are now placed on the right by default.
Use `set-scroll-bar-mode' to change this.
** Lucid menus can display antialiased fonts if Emacs is build with Xft.
** New scrolling commands `scroll-up-command' and `scroll-down-command'
(bound to [next] and [prior]) does not signal errors at top/bottom
of buffer at first key-press (instead moves to top/bottom of buffer).
......
2010-04-08 Jan Djärv <jan.h.d@swipnet.se>
* xlwmenu.c (xlwmenu_default_font): Make static.
(xlwMenuResources): Add XtNfaceName and XtNdefaultFace.
(string_width): Use XftTextExtentsUtf8 if HAVE_XFT.
(MENU_FONT_HEIGHT, MENU_FONT_ASCENT): Add versions for
HAVE_XFT.
(size_menu): Set max_rest_width in window_state structure.
(display_menu_item): If HAVE_XFT and xft_draw is set, use
XftDrawRect and XftDrawStringUtf8 to draw text.
(make_windows_if_needed): Set max_rest_width and xft_draw
in windows[i].
(openXftFont): New.
(XlwMenuInitialize): Call openXftFont if HAVE_XFT. If mw->menu.font
is not set, load font fixed and save it in xlwmenu_default_font.
(XlwMenuInitialize): Set max_rest_width and xft_draw in windows[0].
(XlwMenuClassInitialize): Initialize xlwmenu_default_font.
(XlwMenuRealize): Set xft_fg, xft_bg, xft_disabled_fg and
windows[0].xft_draw if xft_font is set.
(XlwMenuDestroy): Destroy all xft_draw and close xft_font.
(facename_changed): New.
(XlwMenuSetValues): Call facename_changed. If face name did change,
close old fonts and destroy xft_draw:s. Then create new ones.
* xlwmenu.h (XtNfaceName, XtCFaceName, XtNdefaultFace,
XtCDefaultFace): New.
* xlwmenuP.h (_window_state): Add max_rest_width and xft_draw.
(_XlwMenu_part): Add faceName,xft_fg, xft_bg, xft_disabled_fg and
xft_font.
2010-03-10 Chong Yidong <cyd@stupidchicken.com>
* Branch for 23.2.
......
This diff is collapsed.
......@@ -58,6 +58,10 @@ Boston, MA 02110-1301, USA. */
#define XtCResizeToPreferred "ResizeToPreferred"
#define XtNallowResize "allowResize"
#define XtCAllowResize "AllowResize"
#define XtNfaceName "faceName"
#define XtCFaceName "FaceName"
#define XtNdefaultFace "defaultFace"
#define XtCDefaultFace "DefaultFace"
/* Motif-compatible resource names */
#define XmNshadowThickness "shadowThickness"
......
......@@ -25,6 +25,9 @@ Boston, MA 02110-1301, USA. */
#include "xlwmenu.h"
#include <X11/CoreP.h>
#ifdef HAVE_XFT
#include <X11/Xft/Xft.h>
#endif
/* Elements in the stack arrays. */
typedef struct _window_state
......@@ -35,9 +38,13 @@ typedef struct _window_state
Dimension width;
Dimension height;
Dimension label_width;
int max_rest_width;
/* Width of toggle buttons or radio buttons. */
Dimension button_width;
#ifdef HAVE_XFT
XftDraw* xft_draw;
#endif
} window_state;
......@@ -48,6 +55,12 @@ typedef struct _XlwMenu_part
#ifdef HAVE_X_I18N
XFontSet fontSet;
XFontSetExtents *font_extents;
#endif
#ifdef HAVE_XFT
String faceName;
int default_face;
XftFont* xft_font;
XftColor xft_fg, xft_bg, xft_disabled_fg;
#endif
XFontStruct* font;
Pixel foreground;
......
2010-04-08 Jan Djärv <jan.h.d@swipnet.se>
* xsettings.c (current_font, SYSTEM_FONT, XSETTINGS_FONT_NAME): New.
(parse_xft_settings): Also check for XSETTINGS_FONT_NAME and save that
in current_font.
(init_gconf): Read value of SYSTEM_FONT and save it in current_font.
(Ffont_get_system_normal_font, xsettings_get_system_normal_font): New
functions.
(syms_of_xsettings): Initialize current_font. defsubr
Sfont_get_system_normal_font.
* xsettings.h (Ffont_get_system_normal_font,
xsettings_get_system_normal_font): Declare.
* xfns.c (extern xlwmenu_default_font): Remove.
(Fx_create_frame): Remove setting of xlwmenu_default_font, moved
to xlwmenu.c.
* menu.c (digest_single_submenu): If USE_LUCID and HAVE_XFT, encode
menu items in UTF-8.
* xmenu.c: include xsettings.h and xlwmenu.h if USE_LUCID.
(apply_systemfont_to_menu): New function.
(set_frame_menubar, create_and_show_popup_menu): Call
apply_systemfont_to_menu.
2010-04-07 Jan Djärv <jan.h.d@swipnet.se>
* frame.h (FRAME_TEXT_LINES_TO_PIXEL_HEIGHT): Don't use
......
......@@ -697,6 +697,12 @@ digest_single_submenu (start, end, top_level_items)
ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
}
#elif defined (USE_LUCID) && defined (HAVE_XFT)
if (STRINGP (pane_name))
{
pane_name = ENCODE_UTF_8 (pane_name);
ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
}
#elif !defined (HAVE_MULTILINGUAL_MENU)
if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
{
......@@ -770,6 +776,18 @@ digest_single_submenu (start, end, top_level_items)
descrip = ENCODE_SYSTEM (descrip);
ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
}
#elif USE_LUCID
if (STRINGP (item_name))
{
item_name = ENCODE_UTF_8 (item_name);
ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
}
if (STRINGP (descrip))
{
descrip = ENCODE_UTF_8 (descrip);
ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
}
#elif !defined (HAVE_MULTILINGUAL_MENU)
if (STRING_MULTIBYTE (item_name))
{
......
......@@ -110,11 +110,6 @@ extern void _XEditResCheckMessages ();
extern LWLIB_ID widget_id_tick;
#ifdef USE_LUCID
/* This is part of a kludge--see lwlib/xlwmenu.c. */
extern XFontStruct *xlwmenu_default_font;
#endif
extern void free_frame_menubar ();
extern double atof ();
......@@ -3379,14 +3374,6 @@ This function is an internal primitive--use `make-frame' instead. */)
error ("Invalid frame font");
}
#ifdef USE_LUCID
/* Prevent lwlib/xlwmenu.c from crashing because of a bug
whereby it fails to get any font. */
BLOCK_INPUT;
xlwmenu_default_font = XLoadQueryFont (FRAME_X_DISPLAY (f), "fixed");
UNBLOCK_INPUT;
#endif
/* Frame contents get displaced if an embedded X window has a border. */
if (! FRAME_X_EMBEDDED_P (f))
x_default_parameter (f, parms, Qborder_width, make_number (2),
......
......@@ -81,6 +81,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <X11/StringDefs.h>
#include <X11/Shell.h>
#ifdef USE_LUCID
#include "xsettings.h"
#include "../lwlib/xlwmenu.h"
#ifdef HAVE_XAW3D
#include <X11/Xaw3d/Paned.h>
#else /* !HAVE_XAW3D */
......@@ -950,6 +952,36 @@ update_frame_menubar (f)
return 1;
}
#ifdef USE_LUCID
static void
apply_systemfont_to_menu (w)
Widget w;
{
const char *fn = xsettings_get_system_normal_font ();
int defflt;
if (!fn) return;
if (XtIsShell (w)) /* popup menu */
{
Widget *childs[1];
int num = 0;
XtVaGetValues (w, XtNnumChildren, &num, NULL);
if (num != 1) return; /* Should only be one. */
childs[0] = 0;
XtVaGetValues (w, XtNchildren, childs, NULL);
if (childs[0] && *childs[0]) w = *childs[0];
}
/* Only use system font if the default is used for the menu. */
XtVaGetValues (w, XtNdefaultFace, &defflt, NULL);
if (defflt)
XtVaSetValues (w, XtNfaceName, fn, NULL);
}
#endif
/* Set the contents of the menubar widgets of frame F.
The argument FIRST_TIME is currently ignored;
it is set the first time this is called, from initialize_frame_menubar. */
......@@ -1262,6 +1294,7 @@ set_frame_menubar (f, first_time, deep_p)
/* Make menu pop down on C-g. */
XtOverrideTranslations (menubar_widget, override);
apply_systemfont_to_menu (menubar_widget);
}
{
......@@ -1608,6 +1641,8 @@ create_and_show_popup_menu (f, first_wv, x, y, for_click, timestamp)
popup_deactivate_callback,
menu_highlight_callback);
apply_systemfont_to_menu (menu);
dummy.type = ButtonPress;
dummy.serial = 0;
dummy.send_event = 0;
......
......@@ -39,6 +39,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#endif
static char *current_mono_font;
static char *current_font;
static struct x_display_info *first_dpyinfo;
static Lisp_Object Qfont_name, Qfont_render;
static int use_system_font;
......@@ -65,7 +66,9 @@ store_font_changed_event (arg, display_name)
#ifdef HAVE_GCONF
#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
#define SYSTEM_MONO_FONT "/desktop/gnome/interface/monospace_font_name"
#define SYSTEM_FONT "/desktop/gnome/interface/font_name"
#define XSETTINGS_FONT_NAME "Gtk/FontName"
/* Callback called when something changed in GConf that we care about,
that is SYSTEM_MONO_FONT. */
......@@ -235,7 +238,7 @@ parse_xft_settings (prop, bytes, settings)
memset (settings, 0, sizeof (*settings));
while (bytes_parsed+4 < bytes && settings_seen < 6
while (bytes_parsed+4 < bytes && settings_seen < 7
&& i < n_settings)
{
int type = prop[bytes_parsed++];
......@@ -243,7 +246,7 @@ parse_xft_settings (prop, bytes, settings)
CARD32 vlen, ival = 0;
char name[128]; /* The names we are looking for are not this long. */
char sval[128]; /* The values we are looking for are not this long. */
int is_xft;
int want_this;
int to_cpy;
sval[0] = '\0';
......@@ -264,13 +267,14 @@ parse_xft_settings (prop, bytes, settings)
bytes_parsed += 4; /* Skip serial for this value */
if (bytes_parsed > bytes) return BadLength;
is_xft = nlen > 6 && strncmp (name, "Xft/", 4) == 0;
want_this = (nlen > 6 && strncmp (name, "Xft/", 4) == 0)
|| (strcmp (XSETTINGS_FONT_NAME, name) == 0);
switch (type)
{
case 0: /* Integer */
if (bytes_parsed+4 > bytes) return BadLength;
if (is_xft)
if (want_this)
{
memcpy (&ival, prop+bytes_parsed, 4);
if (my_bo != that_bo) ival = SWAP32 (ival);
......@@ -283,7 +287,7 @@ parse_xft_settings (prop, bytes, settings)
memcpy (&vlen, prop+bytes_parsed, 4);
bytes_parsed += 4;
if (my_bo != that_bo) vlen = SWAP32 (vlen);
if (is_xft)
if (want_this)
{
to_cpy = vlen > 127 ? 127 : vlen;
memcpy (sval, prop+bytes_parsed, to_cpy);
......@@ -303,7 +307,7 @@ parse_xft_settings (prop, bytes, settings)
return BadValue;
}
if (is_xft)
if (want_this)
{
++settings_seen;
if (strcmp (name, "Xft/Antialias") == 0)
......@@ -361,6 +365,11 @@ parse_xft_settings (prop, bytes, settings)
else
settings->seen &= ~SEEN_LCDFILTER;
}
else if (strcmp (name, XSETTINGS_FONT_NAME) == 0)
{
free (current_font);
current_font = xstrdup (sval);
}
}
}
......@@ -571,6 +580,12 @@ init_gconf ()
current_mono_font = xstrdup (s);
g_free (s);
}
s = gconf_client_get_string (gconf_client, SYSTEM_FONT, NULL);
if (s)
{
current_font = xstrdup (s);
g_free (s);
}
gconf_client_set_error_handling (gconf_client, GCONF_CLIENT_HANDLE_NONE);
gconf_client_add_dir (gconf_client,
SYSTEM_MONO_FONT,
......@@ -635,6 +650,23 @@ xsettings_get_system_font ()
return current_mono_font;
}
const char *
xsettings_get_system_normal_font ()
{
return current_font;
}
DEFUN ("font-get-system-normal-font", Ffont_get_system_normal_font,
Sfont_get_system_normal_font,
0, 0, 0,
doc: /* Get the system default font. */)
()
{
return current_font && use_system_font
? make_string (current_font, strlen (current_font))
: Qnil;
}
DEFUN ("font-get-system-font", Ffont_get_system_font, Sfont_get_system_font,
0, 0, 0,
doc: /* Get the system default monospaced font. */)
......@@ -649,6 +681,7 @@ void
syms_of_xsettings ()
{
current_mono_font = NULL;
current_font = NULL;
first_dpyinfo = NULL;
#ifdef HAVE_GCONF
gconf_client = NULL;
......@@ -659,6 +692,7 @@ syms_of_xsettings ()
Qfont_render = intern_c_string ("font-render");
staticpro (&Qfont_render);
defsubr (&Sfont_get_system_font);
defsubr (&Sfont_get_system_normal_font);
DEFVAR_BOOL ("font-use-system-font", &use_system_font,
doc: /* *Non-nil means to use the system defined font. */);
......
......@@ -21,10 +21,13 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define XSETTINGS_H
EXFUN (Ffont_get_system_font, 0);
EXFUN (Ffont_get_system_normal_font, 0);
extern void xsettings_initialize P_ ((struct x_display_info *dpyinfo));
extern void xft_settings_event P_ ((struct x_display_info *dpyinfo,
XEvent *));
extern const char *xsettings_get_system_font P_ ((void));
extern const char *xsettings_get_system_normal_font P_ ((void));
#endif /* XSETTINGS_H */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment