From 42143acda9a3993f383cf1c9688831cba8200d10 Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 20 Mar 2013 13:56:19 +0400 Subject: [PATCH] * frame.h (struct frame): Drop resx and resy because the same data is available from window system-specific output context. Adjust users. (default_pixesls_per_inch_x, default_pixesls_per_inch_y): New functions to provide defaults when no window system available. (FRAME_RES_X, FRAME_RES_Y): New macros. (NUMVAL): Moved from xdisp.c. * font.c (font_pixel_size, font_find_for_lface, font_open_for_lface) (Ffont_face_attributes, Fopen_font): * image.c (gs_load): * w32font.c (fill_in_logfont): * xdisp.c (calc_pixel_width_or_height): * xfaces.c (Fx_family_fonts, set_lface_from_font): Use them. * xsettings.c (apply_xft_settings): Drop frame loop and adjust comment. --- src/ChangeLog | 16 +++++++++++++++ src/font.c | 13 ++++++------ src/frame.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++--- src/image.c | 4 ++-- src/nsfns.m | 3 --- src/w32fns.c | 6 ------ src/w32font.c | 2 +- src/xdisp.c | 24 +++------------------- src/xfaces.c | 4 ++-- src/xfns.c | 6 ------ src/xsettings.c | 9 ++------- 11 files changed, 84 insertions(+), 57 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 2779e5a6ea8..01fa73d8273 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,19 @@ +2013-03-20 Dmitry Antipov + + * frame.h (struct frame): Drop resx and resy because the same data is + available from window system-specific output context. Adjust users. + (default_pixesls_per_inch_x, default_pixesls_per_inch_y): New + functions to provide defaults when no window system available. + (FRAME_RES_X, FRAME_RES_Y): New macros. + (NUMVAL): Moved from xdisp.c. + * font.c (font_pixel_size, font_find_for_lface, font_open_for_lface) + (Ffont_face_attributes, Fopen_font): + * image.c (gs_load): + * w32font.c (fill_in_logfont): + * xdisp.c (calc_pixel_width_or_height): + * xfaces.c (Fx_family_fonts, set_lface_from_font): Use them. + * xsettings.c (apply_xft_settings): Drop frame loop and adjust comment. + 2013-03-20 Kenichi Handa * coding.c (syms_of_coding): Initialize disable_ascii_optimization diff --git a/src/font.c b/src/font.c index db7bf352c94..ba98d19afa0 100644 --- a/src/font.c +++ b/src/font.c @@ -287,7 +287,7 @@ font_pixel_size (FRAME_PTR f, Lisp_Object spec) if (INTEGERP (val)) dpi = XINT (val); else - dpi = f->resy; + dpi = FRAME_RES_Y (f); pixel_size = POINT_TO_PIXEL (point_size, dpi); return pixel_size; #else @@ -3117,7 +3117,7 @@ font_find_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec, int c) { double pt = XINT (attrs[LFACE_HEIGHT_INDEX]); - pixel_size = POINT_TO_PIXEL (pt / 10, f->resy); + pixel_size = POINT_TO_PIXEL (pt / 10, FRAME_RES_Y (f)); } ASET (work, FONT_SIZE_INDEX, Qnil); foundry[0] = AREF (work, FONT_FOUNDRY_INDEX); @@ -3247,12 +3247,13 @@ font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_O } pt /= 10; - size = POINT_TO_PIXEL (pt, f->resy); + size = POINT_TO_PIXEL (pt, FRAME_RES_Y (f)); #ifdef HAVE_NS if (size == 0) { Lisp_Object ffsize = get_frame_param (f, Qfontsize); - size = NUMBERP (ffsize) ? POINT_TO_PIXEL (XINT (ffsize), f->resy) : 0; + size = (NUMBERP (ffsize) + ? POINT_TO_PIXEL (XINT (ffsize), FRAME_RES_Y (f)) : 0); } #endif } @@ -4021,7 +4022,7 @@ are to be displayed on. If omitted, the selected frame is used. */) if (INTEGERP (val)) { Lisp_Object font_dpi = AREF (font, FONT_DPI_INDEX); - int dpi = INTEGERP (font_dpi) ? XINT (font_dpi) : f->resy; + int dpi = INTEGERP (font_dpi) ? XINT (font_dpi) : FRAME_RES_Y (f); plist[n++] = QCheight; plist[n++] = make_number (PIXEL_TO_POINT (XINT (val) * 10, dpi)); } @@ -4532,7 +4533,7 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0, { CHECK_NUMBER_OR_FLOAT (size); if (FLOATP (size)) - isize = POINT_TO_PIXEL (XFLOAT_DATA (size), f->resy); + isize = POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f)); else isize = XINT (size); if (! (INT_MIN <= isize && isize <= INT_MAX)) diff --git a/src/frame.h b/src/frame.h index c18b7662079..7a4943327eb 100644 --- a/src/frame.h +++ b/src/frame.h @@ -276,9 +276,6 @@ struct frame /* Size of the frame window in pixels. */ int pixel_height, pixel_width; - /* Dots per inch of the screen the frame is on. */ - double resx, resy; - /* These many pixels are the difference between the outer window (i.e. the left and top of the window manager decoration) and FRAME_X_WINDOW. */ int x_pixels_diff, y_pixels_diff; @@ -569,6 +566,26 @@ fset_tool_bar_window (struct frame *f, Lisp_Object val) f->tool_bar_window = val; } +#define NUMVAL(X) ((INTEGERP (X) || FLOATP (X)) ? XFLOATINT (X) : -1) + +FRAME_INLINE double +default_pixels_per_inch_x (void) +{ + Lisp_Object v = (CONSP (Vdisplay_pixels_per_inch) + ? XCAR (Vdisplay_pixels_per_inch) + : Vdisplay_pixels_per_inch); + return NUMVAL (v) > 0 ? NUMVAL (v) : 72.0; +} + +FRAME_INLINE double +default_pixels_per_inch_y (void) +{ + Lisp_Object v = (CONSP (Vdisplay_pixels_per_inch) + ? XCDR (Vdisplay_pixels_per_inch) + : Vdisplay_pixels_per_inch); + return NUMVAL (v) > 0 ? NUMVAL (v) : 72.0; +} + #define FRAME_KBOARD(f) ((f)->terminal->kboard) /* Return a pointer to the image cache of frame F. */ @@ -602,6 +619,37 @@ typedef struct frame *FRAME_PTR; #else #define FRAME_NS_P(f) ((f)->output_method == output_ns) #endif + +/* Dots per inch of the screen the frame F is on. */ + +#ifdef HAVE_X_WINDOWS +#define FRAME_RES_X(f) \ + (eassert (FRAME_X_P (f)), FRAME_X_DISPLAY_INFO (f)->resx) +#define FRAME_RES_Y(f) \ + (eassert (FRAME_X_P (f)), FRAME_X_DISPLAY_INFO (f)->resy) +#endif + +#ifdef HAVE_NTGUI +#define FRAME_RES_X(f) \ + (eassert (FRAME_W32_P (f)), FRAME_W32_DISPLAY_INFO (f)->resx) +#define FRAME_RES_Y(f) \ + (eassert (FRAME_W32_P (f)), FRAME_W32_DISPLAY_INFO (f)->resy) +#endif + +#ifdef HAVE_NS +#define FRAME_RES_X(f) \ + (eassert (FRAME_NS_P (f)), FRAME_NS_DISPLAY_INFO (f)->resx) +#define FRAME_RES_Y(f) \ + (eassert (FRAME_NS_P (f)), FRAME_NS_DISPLAY_INFO (f)->resy) +#endif + +/* Defaults when no window system available. */ + +#ifndef FRAME_RES_X +#define FRAME_RES_X(f) default_pixels_per_inch_x () +#define FRAME_RES_Y(f) default_pixels_per_inch_y () +#endif + /* FRAME_WINDOW_P tests whether the frame is a window, and is defined to be the predicate for the window system being used. */ diff --git a/src/image.c b/src/image.c index 2c0f6e3b8c1..3eec8b6c13d 100644 --- a/src/image.c +++ b/src/image.c @@ -8554,10 +8554,10 @@ gs_load (struct frame *f, struct image *img) info. */ pt_width = image_spec_value (img->spec, QCpt_width, NULL); in_width = INTEGERP (pt_width) ? XFASTINT (pt_width) / 72.0 : 0; - in_width *= FRAME_X_DISPLAY_INFO (f)->resx; + in_width *= FRAME_RES_X (f); pt_height = image_spec_value (img->spec, QCpt_height, NULL); in_height = INTEGERP (pt_height) ? XFASTINT (pt_height) / 72.0 : 0; - in_height *= FRAME_X_DISPLAY_INFO (f)->resy; + in_height *= FRAME_RES_Y (f); if (! (in_width <= INT_MAX && in_height <= INT_MAX && check_image_size (f, in_width, in_height))) diff --git a/src/nsfns.m b/src/nsfns.m index ef18acaa045..9c3051a8c6a 100644 --- a/src/nsfns.m +++ b/src/nsfns.m @@ -1243,9 +1243,6 @@ This function is an internal primitive--use `make-frame' instead. */) specbind (Qx_resource_name, name); } - f->resx = dpyinfo->resx; - f->resy = dpyinfo->resy; - block_input (); register_font_driver (&nsfont_driver, f); x_default_parameter (f, parms, Qfont_backend, Qnil, diff --git a/src/w32fns.c b/src/w32fns.c index cef2009d7a1..83b52d73596 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -4353,9 +4353,6 @@ This function is an internal primitive--use `make-frame' instead. */) specbind (Qx_resource_name, name); } - f->resx = dpyinfo->resx; - f->resy = dpyinfo->resy; - if (uniscribe_available) register_font_driver (&uniscribe_font_driver, f); register_font_driver (&w32font_driver, f); @@ -5420,9 +5417,6 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, specbind (Qx_resource_name, name); } - f->resx = dpyinfo->resx; - f->resy = dpyinfo->resy; - if (uniscribe_available) register_font_driver (&uniscribe_font_driver, f); register_font_driver (&w32font_driver, f); diff --git a/src/w32font.c b/src/w32font.c index 5c5a15cc340..fb52376b9e1 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -1967,7 +1967,7 @@ static void fill_in_logfont (FRAME_PTR f, LOGFONT *logfont, Lisp_Object font_spec) { Lisp_Object tmp, extra; - int dpi = FRAME_W32_DISPLAY_INFO (f)->resy; + int dpi = FRAME_RES_Y (f); tmp = AREF (font_spec, FONT_DPI_INDEX); if (INTEGERP (tmp)) diff --git a/src/xdisp.c b/src/xdisp.c index a5bba1a81cd..667597b93c3 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -22082,11 +22082,6 @@ else if the text is replaced by an ellipsis. */) */ -#define NUMVAL(X) \ - ((INTEGERP (X) || FLOATP (X)) \ - ? XFLOATINT (X) \ - : - 1) - static int calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop, struct font *font, int width_p, int *align_to) @@ -22117,24 +22112,11 @@ calc_pixel_width_or_height (double *res, struct it *it, Lisp_Object prop, pixels = 0; if (pixels > 0) { - double ppi; -#ifdef HAVE_WINDOW_SYSTEM - if (FRAME_WINDOW_P (it->f) - && (ppi = (width_p - ? FRAME_X_DISPLAY_INFO (it->f)->resx - : FRAME_X_DISPLAY_INFO (it->f)->resy), - ppi > 0)) - return OK_PIXELS (ppi / pixels); -#endif + double ppi = (width_p ? FRAME_RES_X (it->f) + : FRAME_RES_Y (it->f)); - if ((ppi = NUMVAL (Vdisplay_pixels_per_inch), ppi > 0) - || (CONSP (Vdisplay_pixels_per_inch) - && (ppi = (width_p - ? NUMVAL (XCAR (Vdisplay_pixels_per_inch)) - : NUMVAL (XCDR (Vdisplay_pixels_per_inch))), - ppi > 0))) + if (ppi > 0) return OK_PIXELS (ppi / pixels); - return 0; } } diff --git a/src/xfaces.c b/src/xfaces.c index 28bccd392dc..eb33a38a491 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -1592,7 +1592,7 @@ the face font sort order. */) ASET (v, 0, AREF (font, FONT_FAMILY_INDEX)); ASET (v, 1, FONT_WIDTH_SYMBOLIC (font)); point = PIXEL_TO_POINT (XINT (AREF (font, FONT_SIZE_INDEX)) * 10, - XFRAME (frame)->resy); + FRAME_RES_Y (XFRAME (frame))); ASET (v, 2, make_number (point)); ASET (v, 3, FONT_WEIGHT_SYMBOLIC (font)); ASET (v, 4, FONT_SLANT_SYMBOLIC (font)); @@ -2118,7 +2118,7 @@ set_lface_from_font (struct frame *f, Lisp_Object lface, if (force_p || UNSPECIFIEDP (LFACE_HEIGHT (lface))) { - int pt = PIXEL_TO_POINT (font->pixel_size * 10, f->resy); + int pt = PIXEL_TO_POINT (font->pixel_size * 10, FRAME_RES_Y (f)); eassert (pt > 0); ASET (lface, LFACE_HEIGHT_INDEX, make_number (pt)); diff --git a/src/xfns.c b/src/xfns.c index 100fd81a155..385c5914d91 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -3182,9 +3182,6 @@ This function is an internal primitive--use `make-frame' instead. */) specbind (Qx_resource_name, name); } - f->resx = dpyinfo->resx; - f->resy = dpyinfo->resy; - #ifdef HAVE_FREETYPE #ifdef HAVE_XFT register_font_driver (&xftfont_driver, f); @@ -4631,9 +4628,6 @@ x_create_tip_frame (struct x_display_info *dpyinfo, specbind (Qx_resource_name, name); } - f->resx = dpyinfo->resx; - f->resy = dpyinfo->resy; - register_font_driver (&xfont_driver, f); #ifdef HAVE_FREETYPE #ifdef HAVE_XFT diff --git a/src/xsettings.c b/src/xsettings.c index 576a5032eac..f48c49dbafe 100644 --- a/src/xsettings.c +++ b/src/xsettings.c @@ -673,19 +673,14 @@ apply_xft_settings (struct x_display_info *dpyinfo, if ((settings->seen & SEEN_DPI) != 0 && oldsettings.dpi != settings->dpi && settings->dpi > 0) { - Lisp_Object frame, tail; - FcPatternDel (pat, FC_DPI); FcPatternAddDouble (pat, FC_DPI, settings->dpi); ++changed; oldsettings.dpi = settings->dpi; - /* Change the DPI on this display and all frames on the display. */ + /* Changing the DPI on this display affects all frames on it. + Check FRAME_RES_X and FRAME_RES_Y in frame.h to see how. */ dpyinfo->resy = dpyinfo->resx = settings->dpi; - FOR_EACH_FRAME (tail, frame) - if (FRAME_X_P (XFRAME (frame)) - && FRAME_X_DISPLAY_INFO (XFRAME (frame)) == dpyinfo) - XFRAME (frame)->resy = XFRAME (frame)->resx = settings->dpi; } if (changed) -- 2.39.2