From 5f4e8e2e088de9fb76cb631077c6eddd3219f594 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Mitsuharu Date: Wed, 24 Apr 2019 12:31:37 +0900 Subject: [PATCH] Don't link libXft when using cairo * configure.ac: Check cairo early. Don't try Xft if cairo is used. * lwlib/lwlib-utils.h [USE_CAIRO]: Include cairo.h and fontconfig.h. (XftFont, XftDraw, XftColor, XGlyphInfo) [USE_CAIRO]: New typedefs. (XftFontOpenName, XftFontClose, XftDrawCreate, XftDrawDestroy) (XftDrawRect, XftDrawStringUtf8, XftTextExtentsUtf8) [USE_CAIRO]: New macros. (crxft_font_open_name, crxft_font_close, crxft_draw_create) (crxft_draw_rect, crxft_draw_string, crxft_text_extents) [USE_CAIRO]: New externs. * lwlib/lwlib-utils.c [USE_CAIRO]: Include math.h, cairo-ft.h, and cairo-xlib.h. (crxft_font_open_name, crxft_font_close, crxft_draw_create) (crxft_set_source_color, crxft_draw_rect, crxft_draw_string) (crxft_text_extents) [USE_CAIRO]: New Xft compatibility functions. * lwlib/xlwmenuP.h [USE_CAIRO]: Include lwlib-utils.h. * lwlib/xlwmenu.c (display_menu_item) [USE_CAIRO]: Call cairo_surface_mark_dirty and cairo_surface_flush. * lwlib/lwlib-Xaw.c [USE_CAIRO]: Include stdlib.h and lwlib-utils.h. (draw_text) [USE_CAIRO]: Call cairo_surface_flush. * src/xsettings.c [USE_CAIRO]: Include fontconfig.h (apply_xft_settings) [!HAVE_XFT]: Don't call XftDefaultSubstitute or XftDefaultSet. * lwlib/lwlib-Xaw.c: * lwlib/lwlib-int.h: * lwlib/xlwmenu.c: * lwlib/xlwmenuP.h: * src/xrdb.c: * src/xsettings.c: * src/xterm.c: Replace all #ifdef HAVE_XFT with #if defined USE_CAIRO || defined HAVE_XFT. * src/xfns.c (x_default_font_parameter): Replace #ifdef HAVE_XFT with #if defined USE_CAIRO || defined HAVE_XFT. --- configure.ac | 52 ++++++++++------ lwlib/lwlib-Xaw.c | 28 +++++---- lwlib/lwlib-int.h | 2 +- lwlib/lwlib-utils.c | 140 ++++++++++++++++++++++++++++++++++++++++++++ lwlib/lwlib-utils.h | 45 ++++++++++++++ lwlib/xlwmenu.c | 43 ++++++++------ lwlib/xlwmenuP.h | 10 +++- src/menu.c | 2 +- src/xfns.c | 2 +- src/xrdb.c | 4 +- src/xsettings.c | 58 ++++++++++-------- src/xterm.c | 2 +- 12 files changed, 307 insertions(+), 81 deletions(-) diff --git a/configure.ac b/configure.ac index 8b363c7fca6..810c3219e4f 100644 --- a/configure.ac +++ b/configure.ac @@ -3312,12 +3312,44 @@ if test "${HAVE_X11}" = "yes"; then fi fi +HAVE_CAIRO=no +if test "${HAVE_X11}" = "yes"; then + if test "${with_cairo}" != "no"; then + CAIRO_REQUIRED=1.12.0 + CAIRO_MODULE="cairo >= $CAIRO_REQUIRED" + EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE) + if test $HAVE_CAIRO = yes; then + AC_DEFINE(USE_CAIRO, 1, [Define to 1 if using cairo.]) + else + AC_MSG_ERROR([cairo requested but not found.]) + fi + + CFLAGS="$CFLAGS $CAIRO_CFLAGS" + LIBS="$LIBS $CAIRO_LIBS" + AC_SUBST(CAIRO_CFLAGS) + AC_SUBST(CAIRO_LIBS) + fi +fi + ### Start of font-backend (under any platform) section. # (nothing here yet -- this is a placeholder) ### End of font-backend (under any platform) section. ### Start of font-backend (under X11) section. if test "${HAVE_X11}" = "yes"; then + if test $HAVE_CAIRO = yes; then + dnl Strict linkers fail with + dnl ftfont.o: undefined reference to symbol 'FT_New_Face' + dnl if -lfreetype is not specified. + dnl The following is needed to set FREETYPE_LIBS. + EMACS_CHECK_MODULES([FREETYPE], [freetype2]) + + test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR(cairo requires libfreetype) + + EMACS_CHECK_MODULES([FONTCONFIG], [fontconfig >= 2.2.0]) + + test "$HAVE_FONTCONFIG" = "no" && AC_MSG_ERROR(cairo requires libfontconfig) + else ## Use -lXft if available, unless '--with-xft=no'. HAVE_XFT=maybe if test "x${with_x}" = "xno"; then @@ -3374,6 +3406,7 @@ if test "${HAVE_X11}" = "yes"; then test "$HAVE_FREETYPE" = "no" && AC_MSG_ERROR(libxft requires libfreetype) fi + fi # $HAVE_CAIRO != yes HAVE_LIBOTF=no if test "${HAVE_FREETYPE}" = "yes"; then @@ -3427,25 +3460,6 @@ AC_SUBST(LIBOTF_LIBS) AC_SUBST(M17N_FLT_CFLAGS) AC_SUBST(M17N_FLT_LIBS) -HAVE_CAIRO=no -if test "${HAVE_X11}" = "yes"; then - if test "${with_cairo}" != "no"; then - CAIRO_REQUIRED=1.12.0 - CAIRO_MODULE="cairo >= $CAIRO_REQUIRED" - EMACS_CHECK_MODULES(CAIRO, $CAIRO_MODULE) - if test $HAVE_CAIRO = yes; then - AC_DEFINE(USE_CAIRO, 1, [Define to 1 if using cairo.]) - else - AC_MSG_ERROR([cairo requested but not found.]) - fi - - CFLAGS="$CFLAGS $CAIRO_CFLAGS" - LIBS="$LIBS $CAIRO_LIBS" - AC_SUBST(CAIRO_CFLAGS) - AC_SUBST(CAIRO_LIBS) - fi -fi - if test "${HAVE_X11}" = "yes"; then AC_CHECK_HEADER(X11/Xlib-xcb.h, AC_CHECK_LIB(xcb, xcb_translate_coordinates, HAVE_XCB=yes)) diff --git a/lwlib/lwlib-Xaw.c b/lwlib/lwlib-Xaw.c index a00f8aa73f9..0801c944008 100644 --- a/lwlib/lwlib-Xaw.c +++ b/lwlib/lwlib-Xaw.c @@ -50,8 +50,13 @@ along with GNU Emacs. If not, see . */ #include -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT +#ifdef USE_CAIRO +#include +#include "lwlib-utils.h" +#else /* HAVE_XFT */ #include +#endif struct widget_xft_data { @@ -79,7 +84,7 @@ lw_xaw_widget_p (Widget widget) } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static void fill_xft_data (struct widget_xft_data *data, Widget widget, XftFont *font) { @@ -210,6 +215,9 @@ draw_text (struct widget_xft_data *data, char *lbl, int inverse) /* 1.2 gives reasonable line spacing. */ y += data->xft_font->height * 1.2; } +#ifdef USE_CAIRO + cairo_surface_flush (cairo_get_target (data->xft_draw)); +#endif } @@ -307,7 +315,7 @@ xaw_update_one_widget (widget_instance *instance, if (XtIsSubclass (widget, dialogWidgetClass)) { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (instance->xft_data && instance->xft_data[0].xft_font) { set_text (&instance->xft_data[0], instance->parent, @@ -339,7 +347,7 @@ xaw_update_one_widget (widget_instance *instance, XtSetArg (al[ac], XtNlabel, val->value);ac++; /* Force centered button text. Se above. */ XtSetArg (al[ac], XtNjustify, XtJustifyCenter);ac++; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (instance->xft_data && instance->xft_data[0].xft_font) { int th; @@ -473,7 +481,7 @@ static XtActionsRec xaw_actions [] = { }; static Boolean actions_initted = False; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static XtActionsRec button_actions[] = { { "my_reset", command_reset }, @@ -506,7 +514,7 @@ make_dialog (char* name, Widget dialog; Widget button; XtTranslations override; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XftFont *xft_font = 0; XtTranslations button_override; #endif @@ -521,7 +529,7 @@ make_dialog (char* name, XtAppContext app = XtWidgetToApplicationContext (parent); XtAppAddActions (app, xaw_actions, sizeof (xaw_actions) / sizeof (xaw_actions[0])); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XtAppAddActions (app, button_actions, sizeof (button_actions) / sizeof (button_actions[0])); #endif @@ -546,7 +554,7 @@ make_dialog (char* name, override = XtParseTranslationTable (dialogOverride); XtOverrideTranslations (dialog, override); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT { int num; Widget *ch = NULL; @@ -618,7 +626,7 @@ make_dialog (char* name, sprintf (button_name, "button%d", ++bc); button = XtCreateManagedWidget (button_name, commandWidgetClass, dialog, av, ac); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (xft_font) { fill_xft_data (&instance->xft_data[bc], button, xft_font); @@ -651,7 +659,7 @@ make_dialog (char* name, sprintf (button_name, "button%d", ++bc); button = XtCreateManagedWidget (button_name, commandWidgetClass, dialog, av, ac); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (xft_font) { fill_xft_data (&instance->xft_data[bc], button, xft_font); diff --git a/lwlib/lwlib-int.h b/lwlib/lwlib-int.h index 28b1fb9508d..9f788e7c0c2 100644 --- a/lwlib/lwlib-int.h +++ b/lwlib/lwlib-int.h @@ -30,7 +30,7 @@ typedef struct _widget_instance Widget widget; Widget parent; Boolean pop_up_p; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT struct widget_xft_data *xft_data; #endif struct _widget_info* info; diff --git a/lwlib/lwlib-utils.c b/lwlib/lwlib-utils.c index 7c60bdb056d..2c0a931f9cb 100644 --- a/lwlib/lwlib-utils.c +++ b/lwlib/lwlib-utils.c @@ -137,3 +137,143 @@ XtWidgetBeingDestroyedP (Widget widget) { return widget->core.being_destroyed; } + +#ifdef USE_CAIRO +/* Xft emulation on cairo. */ +#include +#include +#include + +XftFont * +crxft_font_open_name (Display *dpy, int screen, const char *name) +{ + XftFont *pub = NULL; + FcPattern *pattern = FcNameParse ((FcChar8 *) name); + if (pattern) + { + FcConfigSubstitute (NULL, pattern, FcMatchPattern); + double dpi; + if (FcPatternGetDouble (pattern, FC_DPI, 0, &dpi) == FcResultNoMatch) + { + char *v = XGetDefault (dpy, "Xft", FC_DPI); + if (v == NULL || sscanf (v, "%lf", &dpi) != 1) + dpi = ((DisplayHeight (dpy, screen) * 25.4) + / DisplayHeightMM (dpy, screen)); + FcPatternAddDouble (pattern, FC_DPI, dpi); + } + FcDefaultSubstitute (pattern); + cairo_font_face_t *font_face + = cairo_ft_font_face_create_for_pattern (pattern); + if (font_face) + { + double pixel_size; + if ((FcPatternGetDouble (pattern, FC_PIXEL_SIZE, 0, &pixel_size) + != FcResultMatch) + || pixel_size < 1) + pixel_size = 10; + + pub = xmalloc (sizeof (*pub)); + cairo_matrix_t font_matrix, ctm; + cairo_matrix_init_scale (&font_matrix, pixel_size, pixel_size); + cairo_matrix_init_identity (&ctm); + cairo_font_options_t *options = cairo_font_options_create (); + cairo_ft_font_options_substitute (options, pattern); + pub->scaled_font = cairo_scaled_font_create (font_face, &font_matrix, + &ctm, options); + cairo_font_face_destroy (font_face); + cairo_font_options_destroy (options); + + cairo_font_extents_t extents; + cairo_scaled_font_extents (pub->scaled_font, &extents); + pub->ascent = lround (extents.ascent); + pub->descent = lround (extents.descent); + pub->height = lround (extents.height); + pub->max_advance_width = lround (extents.max_x_advance); + } + FcPatternDestroy (pattern); + } + return pub; +} + +void +crxft_font_close (XftFont *pub) +{ + cairo_scaled_font_destroy (pub->scaled_font); + xfree (pub); +} + +cairo_t * +crxft_draw_create (Display *dpy, Drawable drawable, Visual *visual) +{ + cairo_t *cr = NULL; + Window root; + int x, y; + unsigned int width, height, border_width, depth; + + if (!XGetGeometry (dpy, drawable, &root, &x, &y, &width, &height, + &border_width, &depth)) + return NULL; + + cairo_surface_t *surface = cairo_xlib_surface_create (dpy, drawable, visual, + width, height); + if (surface) + { + cr = cairo_create (surface); + cairo_surface_destroy (surface); + } + + return cr; +} + +static void +crxft_set_source_color (cairo_t *cr, const XftColor *color) +{ + cairo_set_source_rgba (cr, color->color.red / 65535.0, + color->color.green / 65535.0, + color->color.blue / 65535.0, + color->color.alpha / 65535.0); +} + +void +crxft_draw_rect (cairo_t *cr, const XftColor *color, int x, int y, + unsigned int width, unsigned int height) +{ + crxft_set_source_color (cr, color); + cairo_rectangle (cr, x, y, width, height); + cairo_fill (cr); +} + +void +crxft_draw_string (cairo_t *cr, const XftColor *color, XftFont *pub, + int x, int y, const FcChar8 *string, int len) +{ + char *buf = xmalloc (len + 1); + memcpy (buf, string, len); + buf[len] = '\0'; + crxft_set_source_color (cr, color); + cairo_set_scaled_font (cr, pub->scaled_font); + cairo_move_to (cr, x, y); + cairo_show_text (cr, buf); + xfree (buf); +} + +void +crxft_text_extents (XftFont *pub, const FcChar8 *string, int len, + XGlyphInfo *extents) +{ + char *buf = xmalloc (len + 1); + memcpy (buf, string, len); + buf[len] = '\0'; + cairo_text_extents_t text_extents; + cairo_scaled_font_text_extents (pub->scaled_font, buf, &text_extents); + xfree (buf); + extents->x = ceil (- text_extents.x_bearing); + extents->y = ceil (- text_extents.y_bearing); + extents->width = (ceil (text_extents.x_bearing + text_extents.width) + + extents->x); + extents->height = (ceil (text_extents.y_bearing + text_extents.height) + + extents->y); + extents->xOff = lround (text_extents.x_advance); + extents->yOff = lround (text_extents.y_advance); +} +#endif /* USE_CAIRO */ diff --git a/lwlib/lwlib-utils.h b/lwlib/lwlib-utils.h index ec3daab94ef..64372f19ad2 100644 --- a/lwlib/lwlib-utils.h +++ b/lwlib/lwlib-utils.h @@ -15,4 +15,49 @@ Widget *XtCompositeChildren (Widget, unsigned int *); Boolean XtWidgetBeingDestroyedP (Widget widget); +#ifdef USE_CAIRO + +#include +#include + +typedef struct { + cairo_scaled_font_t *scaled_font; + int ascent, descent, height, max_advance_width; +} XftFont; + +typedef cairo_t XftDraw; + +typedef struct { + unsigned long pixel; + struct {unsigned short red, green, blue, alpha;} color; +} XftColor; + +#ifdef HAVE_XRENDER +#include +#else +typedef struct { + unsigned short width, height; + short x, y, xOff, yOff; +} XGlyphInfo; +#endif + +#define XftFontOpenName crxft_font_open_name +extern XftFont *crxft_font_open_name (Display *, int, const char *); +#define XftFontClose(dpy, pub) crxft_font_close (pub) +extern void crxft_font_close (XftFont *); +#define XftDrawCreate(dpy, drawable, visual, colormap) \ + crxft_draw_create (dpy, drawable, visual) +extern cairo_t *crxft_draw_create (Display *, Drawable, Visual *); +#define XftDrawDestroy cairo_destroy +#define XftDrawRect crxft_draw_rect +extern void crxft_draw_rect (cairo_t *, const XftColor *, int, int, + unsigned int, unsigned int); +#define XftDrawStringUtf8 crxft_draw_string +extern void crxft_draw_string (cairo_t *, const XftColor *, XftFont *, + int, int, const FcChar8 *, int); +#define XftTextExtentsUtf8(dpy, pub, string, len, extents) \ + crxft_text_extents (pub, string, len, extents) +extern void crxft_text_extents (XftFont *, const FcChar8 *, int, XGlyphInfo *); + +#endif /* USE_CAIRO */ #endif /* _LWLIB_UTILS_H_ */ diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c index a5704cbfb53..6292c840f5d 100644 --- a/lwlib/xlwmenu.c +++ b/lwlib/xlwmenu.c @@ -107,7 +107,7 @@ xlwMenuResources[] = {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet), offset(menu.fontSet), XtRFontSet, NULL}, #endif -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT #define DEFAULT_FONTNAME "Sans-10" #else #define DEFAULT_FONTNAME "XtDefaultFont" @@ -325,7 +325,7 @@ string_width (XlwMenuWidget mw, char *s) { XCharStruct xcs; int drop; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (mw->menu.xft_font) { XGlyphInfo gi; @@ -349,7 +349,7 @@ string_width (XlwMenuWidget mw, char *s) } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT #define MENU_FONT_HEIGHT(mw) \ ((mw)->menu.xft_font != NULL \ ? (mw)->menu.xft_font->height \ @@ -965,7 +965,7 @@ display_menu_item (XlwMenuWidget mw, int width; enum menu_separator separator; int separator_p = lw_separator_p (val->name, &separator, 0); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XftColor *xftfg; #endif @@ -1005,7 +1005,7 @@ display_menu_item (XlwMenuWidget mw, else text_gc = mw->menu.disabled_gc; deco_gc = mw->menu.foreground_gc; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT xftfg = val->enabled ? &mw->menu.xft_fg : &mw->menu.xft_disabled_fg; #endif @@ -1032,10 +1032,13 @@ display_menu_item (XlwMenuWidget mw, x_offset += ws->button_width; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (ws->xft_draw) { int draw_y = y + v_spacing + shadow; +#ifdef USE_CAIRO + cairo_surface_mark_dirty (cairo_get_target (ws->xft_draw)); +#endif XftDrawStringUtf8 (ws->xft_draw, xftfg, mw->menu.xft_font, x_offset, draw_y + font_ascent, @@ -1078,7 +1081,7 @@ display_menu_item (XlwMenuWidget mw, } else if (val->key) { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (ws->xft_draw) { int draw_x = ws->width - ws->max_rest_width @@ -1119,6 +1122,10 @@ display_menu_item (XlwMenuWidget mw, draw_shadow_rectangle (mw, ws->pixmap, x, y, width, height, True, False); } +#ifdef USE_CAIRO + if (ws->xft_draw) + cairo_surface_flush (cairo_get_target (ws->xft_draw)); +#endif if (highlighted_p) draw_shadow_rectangle (mw, ws->pixmap, x, y, width, height, False, @@ -1320,7 +1327,7 @@ make_windows_if_needed (XlwMenuWidget mw, int n) XtAddEventHandler (windows [i].w, ExposureMask, False, expose_cb, mw); windows [i].window = XtWindow (windows [i].w); windows [i].pixmap = None; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT windows [i].xft_draw = 0; #endif set_window_type (windows [i].w, mw); @@ -1411,7 +1418,7 @@ create_pixmap_for_menu (window_state* ws, XlwMenuWidget mw) ws->pixmap = XCreatePixmap (XtDisplay (ws->w), ws->window, ws->width, ws->height, DefaultDepthOfScreen (XtScreen (ws->w))); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (ws->xft_draw) XftDrawDestroy (ws->xft_draw); if (mw->menu.xft_font) @@ -1831,7 +1838,7 @@ release_shadow_gcs (XlwMenuWidget mw) XtReleaseGC ((Widget) mw, mw->menu.shadow_bottom_gc); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static XftFont * getDefaultXftFont (XlwMenuWidget mw) { @@ -1887,7 +1894,7 @@ XlwMenuInitialize (Widget request, Widget w, ArgList args, Cardinal *num_args) gray_width, gray_height, (unsigned long)1, (unsigned long)0, 1); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (openXftFont (mw)) ; else @@ -1933,7 +1940,7 @@ XlwMenuInitialize (Widget request, Widget w, ArgList args, Cardinal *num_args) mw->menu.windows [0].height = 0; mw->menu.windows [0].max_rest_width = 0; mw->menu.windows [0].pixmap = None; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT mw->menu.windows [0].xft_draw = 0; #endif size_menu (mw, 0); @@ -1981,7 +1988,7 @@ XlwMenuRealize (Widget w, Mask *valueMask, XSetWindowAttributes *attributes) set_window_type (mw->menu.windows [0].w, mw); create_pixmap_for_menu (&mw->menu.windows [0], mw); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (mw->menu.xft_font) { XColor colors[3]; @@ -2078,7 +2085,7 @@ XlwMenuDestroy (Widget w) if (mw->menu.font) XFreeFont (XtDisplay (mw), mw->menu.font); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (mw->menu.windows [0].xft_draw) XftDrawDestroy (mw->menu.windows [0].xft_draw); if (mw->menu.xft_font) @@ -2092,7 +2099,7 @@ XlwMenuDestroy (Widget w) { if (mw->menu.windows [i].pixmap != None) XFreePixmap (XtDisplay (mw), mw->menu.windows [i].pixmap); -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (mw->menu.windows [i].xft_draw) XftDrawDestroy (mw->menu.windows [i].xft_draw); #endif @@ -2102,7 +2109,7 @@ XlwMenuDestroy (Widget w) XtFree ((char *) mw->menu.windows); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static int fontname_changed (XlwMenuWidget newmw, XlwMenuWidget oldmw) @@ -2134,7 +2141,7 @@ XlwMenuSetValues (Widget current, Widget request, Widget new, if (newmw->core.background_pixel != oldmw->core.background_pixel || newmw->menu.foreground != oldmw->menu.foreground -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT || fontname_changed (newmw, oldmw) #endif #ifdef HAVE_X_I18N @@ -2170,7 +2177,7 @@ XlwMenuSetValues (Widget current, Widget request, Widget new, } } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (fontname_changed (newmw, oldmw)) { int i; diff --git a/lwlib/xlwmenuP.h b/lwlib/xlwmenuP.h index 610f83afe45..2a05d993541 100644 --- a/lwlib/xlwmenuP.h +++ b/lwlib/xlwmenuP.h @@ -23,9 +23,13 @@ along with GNU Emacs. If not, see . */ #include "xlwmenu.h" #include -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT +#ifdef USE_CAIRO +#include "lwlib-utils.h" +#else /* HAVE_XFT */ #include #endif +#endif /* Elements in the stack arrays. */ typedef struct _window_state @@ -42,7 +46,7 @@ typedef struct _window_state /* Width of toggle buttons or radio buttons. */ Dimension button_width; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT XftDraw* xft_draw; #endif } window_state; @@ -56,7 +60,7 @@ typedef struct _XlwMenu_part XFontSet fontSet; XFontSetExtents *font_extents; #endif -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT int default_face; XftFont* xft_font; XftColor xft_fg, xft_bg, xft_disabled_fg; diff --git a/src/menu.c b/src/menu.c index 7f46e68e73e..e82c8570595 100644 --- a/src/menu.c +++ b/src/menu.c @@ -687,7 +687,7 @@ digest_single_submenu (int start, int end, bool top_level_items) ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name); } -#elif defined (USE_LUCID) && defined (HAVE_XFT) +#elif defined (USE_LUCID) && (defined USE_CAIRO || defined HAVE_XFT) if (STRINGP (pane_name)) { pane_name = ENCODE_UTF_8 (pane_name); diff --git a/src/xfns.c b/src/xfns.c index dbc5e10c415..9075491e978 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -3487,7 +3487,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms) { const char *names[] = { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT /* This will find the normal Xft font. */ "monospace-10", #endif diff --git a/src/xrdb.c b/src/xrdb.c index 35de446cb7a..0950b706699 100644 --- a/src/xrdb.c +++ b/src/xrdb.c @@ -383,7 +383,7 @@ x_load_resources (Display *display, const char *xrm_string, XrmDatabase db; char line[256]; -#if defined USE_MOTIF || !defined HAVE_XFT || !defined USE_LUCID +#if defined USE_MOTIF || !(defined USE_CAIRO || defined HAVE_XFT) || !defined USE_LUCID const char *helv = "-*-helvetica-medium-r-*--*-120-*-*-*-*-iso8859-1"; #endif @@ -456,7 +456,7 @@ x_load_resources (Display *display, const char *xrm_string, sprintf (line, "Emacs.dialog*.background: grey75"); XrmPutLineResource (&rdb, line); -#if !defined (HAVE_XFT) || !defined (USE_LUCID) +#if !(defined USE_CAIRO || defined HAVE_XFT) || !defined (USE_LUCID) sprintf (line, "Emacs.dialog*.font: %s", helv); XrmPutLineResource (&rdb, line); sprintf (line, "*XlwMenu*font: %s", helv); diff --git a/src/xsettings.c b/src/xsettings.c index 947d5cfb7b6..3e9012e3ab1 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -45,9 +45,13 @@ along with GNU Emacs. If not, see . */ #include #endif -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT +#ifdef USE_CAIRO +#include +#else /* HAVE_XFT */ #include #endif +#endif static char *current_mono_font; static char *current_font; @@ -83,7 +87,7 @@ dpyinfo_valid (struct x_display_info *dpyinfo) /* Store a monospace font change event if the monospaced font changed. */ -#if defined HAVE_XFT && (defined HAVE_GSETTINGS || defined HAVE_GCONF) +#if (defined USE_CAIRO || defined HAVE_XFT) && (defined HAVE_GSETTINGS || defined HAVE_GCONF) static void store_monospaced_changed (const char *newfont) { @@ -102,7 +106,7 @@ store_monospaced_changed (const char *newfont) /* Store a font name change event if the font name changed. */ -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT static void store_font_name_changed (const char *newfont) { @@ -117,7 +121,7 @@ store_font_name_changed (const char *newfont) XCAR (first_dpyinfo->name_list_element)); } } -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ /* Map TOOL_BAR_STYLE from a string to its corresponding Lisp value. Return Qnil if TOOL_BAR_STYLE is not known. */ @@ -157,7 +161,7 @@ store_tool_bar_style_changed (const char *newstyle, XCAR (dpyinfo->name_list_element)); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT #define XSETTINGS_FONT_NAME "Gtk/FontName" #endif #define XSETTINGS_TOOL_BAR_STYLE "Gtk/ToolbarStyle" @@ -174,7 +178,7 @@ enum { }; struct xsettings { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT FcBool aa, hinting; int rgba, lcdfilter, hintstyle; double dpi; @@ -191,7 +195,7 @@ struct xsettings #define GSETTINGS_SCHEMA "org.gnome.desktop.interface" #define GSETTINGS_TOOL_BAR_STYLE "toolbar-style" -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT #define GSETTINGS_MONO_FONT "monospace-font-name" #define GSETTINGS_FONT_NAME "font-name" #endif @@ -224,7 +228,7 @@ something_changed_gsettingsCB (GSettings *settings, g_variant_unref (val); } } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT else if (strcmp (key, GSETTINGS_MONO_FONT) == 0) { val = g_settings_get_value (settings, GSETTINGS_MONO_FONT); @@ -253,14 +257,14 @@ something_changed_gsettingsCB (GSettings *settings, g_variant_unref (val); } } -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ } #endif /* HAVE_GSETTINGS */ #ifdef HAVE_GCONF #define GCONF_TOOL_BAR_STYLE "/desktop/gnome/interface/toolbar_style" -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT #define GCONF_MONO_FONT "/desktop/gnome/interface/monospace_font_name" #define GCONF_FONT_NAME "/desktop/gnome/interface/font_name" #endif @@ -286,7 +290,7 @@ something_changed_gconfCB (GConfClient *client, const char *value = gconf_value_get_string (v); store_tool_bar_style_changed (value, first_dpyinfo); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT else if (strcmp (key, GCONF_MONO_FONT) == 0) { const char *value = gconf_value_get_string (v); @@ -297,12 +301,12 @@ something_changed_gconfCB (GConfClient *client, const char *value = gconf_value_get_string (v); store_font_name_changed (value); } -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ } #endif /* HAVE_GCONF */ -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT /* Older fontconfig versions don't have FC_LCD_*. */ #ifndef FC_LCD_NONE @@ -315,7 +319,7 @@ something_changed_gconfCB (GConfClient *client, #define FC_LCD_FILTER "lcdfilter" #endif -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ /* Find the window that contains the XSETTINGS property values. */ @@ -440,7 +444,7 @@ parse_settings (unsigned char *prop, if (bytes_parsed > bytes) return settings_seen; want_this = strcmp (XSETTINGS_TOOL_BAR_STYLE, name) == 0; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if ((nlen > 6 && memcmp (name, "Xft/", 4) == 0) || strcmp (XSETTINGS_FONT_NAME, name) == 0) want_this = true; @@ -490,7 +494,7 @@ parse_settings (unsigned char *prop, dupstring (&settings->tb_style, sval); settings->seen |= SEEN_TB_STYLE; } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT else if (strcmp (name, XSETTINGS_FONT_NAME) == 0) { dupstring (&settings->font, sval); @@ -553,7 +557,7 @@ parse_settings (unsigned char *prop, else settings->seen &= ~SEEN_LCDFILTER; } -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ else want_this = false; settings_seen += want_this; @@ -604,16 +608,18 @@ static void apply_xft_settings (struct x_display_info *dpyinfo, struct xsettings *settings) { -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT FcPattern *pat; struct xsettings oldsettings; bool changed = false; memset (&oldsettings, 0, sizeof (oldsettings)); pat = FcPatternCreate (); +#ifdef HAVE_XFT XftDefaultSubstitute (dpyinfo->display, XScreenNumberOfScreen (dpyinfo->screen), pat); +#endif FcPatternGetBool (pat, FC_ANTIALIAS, 0, &oldsettings.aa); FcPatternGetBool (pat, FC_HINTING, 0, &oldsettings.hinting); #ifdef FC_HINT_STYLE @@ -713,7 +719,9 @@ apply_xft_settings (struct x_display_info *dpyinfo, }; char buf[sizeof format + d_formats * d_growth + lf_formats * lf_growth]; +#ifdef HAVE_XFT XftDefaultSet (dpyinfo->display, pat); +#endif store_config_changed_event (Qfont_render, XCAR (dpyinfo->name_list_element)); Vxft_settings @@ -725,7 +733,7 @@ apply_xft_settings (struct x_display_info *dpyinfo, } else FcPatternDestroy (pat); -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ } /* Read XSettings from the display for DPYINFO. @@ -748,7 +756,7 @@ read_and_apply_settings (struct x_display_info *dpyinfo, bool send_event_p) current_tool_bar_style = map_tool_bar_style (settings.tb_style); xfree (settings.tb_style); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT if (settings.seen & SEEN_FONT) { if (send_event_p) @@ -850,7 +858,7 @@ init_gsettings (void) g_variant_unref (val); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT val = g_settings_get_value (gsettings_client, GSETTINGS_MONO_FONT); if (val) { @@ -868,7 +876,7 @@ init_gsettings (void) dupstring (¤t_font, g_variant_get_string (val, NULL)); g_variant_unref (val); } -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ #endif /* HAVE_GSETTINGS */ } @@ -903,7 +911,7 @@ init_gconf (void) g_free (s); } -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT s = gconf_client_get_string (gconf_client, GCONF_MONO_FONT, NULL); if (s) { @@ -932,7 +940,7 @@ init_gconf (void) GCONF_FONT_NAME, something_changed_gconfCB, NULL, NULL, NULL); -#endif /* HAVE_XFT */ +#endif /* USE_CAIRO || HAVE_XFT */ #endif /* HAVE_GCONF */ } @@ -1055,7 +1063,7 @@ If this variable is nil, Emacs ignores system font changes. */); doc: /* Font settings applied to Xft. */); Vxft_settings = empty_unibyte_string; -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT Fprovide (intern_c_string ("font-render-setting"), Qnil); #if defined (HAVE_GCONF) || defined (HAVE_GSETTINGS) Fprovide (intern_c_string ("system-font-setting"), Qnil); diff --git a/src/xterm.c b/src/xterm.c index 0b83263a0e6..e85e8e35d44 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -12733,7 +12733,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) dpyinfo->supports_xdbe = true; #endif -#ifdef HAVE_XFT +#if defined USE_CAIRO || defined HAVE_XFT { /* If we are using Xft, the following precautions should be made: -- 2.39.2