diff src/frame.c @ 269:b2472a1930f2 r20-5b33

Import from CVS: tag r20-5b33
author cvs
date Mon, 13 Aug 2007 10:27:19 +0200
parents 966663fcf606
children c5d627a313b1
line wrap: on
line diff
--- a/src/frame.c	Mon Aug 13 10:26:31 2007 +0200
+++ b/src/frame.c	Mon Aug 13 10:27:19 2007 +0200
@@ -2297,6 +2297,7 @@
        (frame, property, default_))
 {
   struct frame *f = decode_frame (frame);
+  int width, height;
 
   XSETFRAME (frame, f);
 
@@ -2309,8 +2310,20 @@
 } while (0)
 
   FROB (Qname, f->name);
-  FROB (Qheight, make_int (FRAME_HEIGHT (f)));
-  FROB (Qwidth,  make_int (FRAME_WIDTH  (f)));
+
+  if (window_system_pixelated_geometry (frame))
+    {
+      pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
+			       &width, &height);
+    }
+  else
+    {
+      height = FRAME_HEIGHT (f);
+      width = FRAME_WIDTH (f);
+    }
+  FROB (Qheight, make_int (height));
+  FROB (Qwidth,  make_int (width));
+
   /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
      This is over-the-top bogosity, because it's inconsistent with
      the semantics of `minibuffer' when passed to `make-frame'.
@@ -2365,9 +2378,12 @@
   struct frame *f = decode_frame (frame);
   Lisp_Object result = Qnil;
   struct gcpro gcpro1;
+  int width, height;
 
   GCPRO1 (result);
 
+  XSETFRAME (frame, f);
+
 #define FROB(propprop, value)				\
 do {							\
   Lisp_Object temtem = (value);				\
@@ -2377,8 +2393,20 @@
 } while (0)
 
   FROB (Qname, f->name);
-  FROB (Qheight, make_int (FRAME_HEIGHT (f)));
-  FROB (Qwidth,  make_int (FRAME_WIDTH  (f)));
+
+  if (window_system_pixelated_geometry (frame))
+    {
+      pixel_to_real_char_size (f, FRAME_PIXWIDTH (f), FRAME_PIXHEIGHT (f),
+			       &width, &height);
+    }
+  else
+    {
+      height = FRAME_HEIGHT (f);
+      width = FRAME_WIDTH (f);
+    }
+  FROB (Qheight, make_int (height));
+  FROB (Qwidth,  make_int (width));
+
  /* NOTE: FSF returns Qnil instead of Qt for FRAME_HAS_MINIBUF_P.
      This is over-the-top bogosity, because it's inconsistent with
      the semantics of `minibuffer' when passed to `make-frame'.
@@ -2467,11 +2495,22 @@
        (frame, rows, pretend))
 {
   struct frame *f = decode_frame (frame);
+  int height, width;
   XSETFRAME (frame, f);
   CHECK_INT (rows);
 
-  internal_set_frame_size (f, FRAME_WIDTH (f), XINT (rows),
-			   !NILP (pretend));
+  if (window_system_pixelated_geometry (frame))
+    {
+      char_to_real_pixel_size (f, 0, XINT (rows), 0, &height);
+      width = FRAME_PIXWIDTH (f);
+    }
+  else
+    {
+      height = XINT (rows);
+      width = FRAME_WIDTH (f);
+    }
+
+  internal_set_frame_size (f, width, height, !NILP (pretend));
   return frame;
 }
 
@@ -2483,11 +2522,22 @@
        (frame, cols, pretend))
 {
   struct frame *f = decode_frame (frame);
+  int width, height;
   XSETFRAME (frame, f);
   CHECK_INT (cols);
 
-  internal_set_frame_size (f, XINT (cols), FRAME_HEIGHT (f),
-			    !NILP (pretend));
+  if (window_system_pixelated_geometry (frame))
+    {
+      char_to_real_pixel_size (f, XINT (cols), 0, &width, 0);
+      height = FRAME_PIXHEIGHT (f);
+    }
+  else
+    {
+      width = XINT (cols);
+      height = FRAME_HEIGHT (f);
+    }
+
+  internal_set_frame_size (f, width, height, !NILP (pretend));
   return frame;
 }
 
@@ -2499,11 +2549,20 @@
        (frame, cols, rows, pretend))
 {
   struct frame *f = decode_frame (frame);
+  int height, width;
   XSETFRAME (frame, f);
   CHECK_INT (cols);
   CHECK_INT (rows);
 
-  internal_set_frame_size (f, XINT (cols), XINT (rows), !NILP (pretend));
+  if (window_system_pixelated_geometry (frame))
+    char_to_real_pixel_size (f, XINT (cols), XINT (rows), &width, &height);
+  else
+    {
+      height = XINT (rows);
+      width = XINT (cols);
+    }
+
+  internal_set_frame_size (f, width, height, !NILP (pretend));
   return frame;
 }
 
@@ -2533,7 +2592,8 @@
 static void
 frame_conversion_internal (struct frame *f, int pixel_to_char,
 			   int *pixel_width, int *pixel_height,
-			   int *char_width, int *char_height)
+			   int *char_width, int *char_height,
+			   int real_face)
 {
   int cpw;
   int cph;
@@ -2542,7 +2602,11 @@
   Lisp_Object frame, window;
 
   XSETFRAME (frame, f);
-  default_face_height_and_width (frame, &cph, &cpw);
+  if (real_face)
+    default_face_height_and_width (frame, &cph, &cpw);
+  else
+    default_face_height_and_width_1 (frame, &cph, &cpw);
+
   window = FRAME_SELECTED_WINDOW (f);
 
   egw = max (glyph_width (Vcontinuation_glyph, Vdefault_face, 0, window),
@@ -2560,13 +2624,17 @@
 
   if (pixel_to_char)
     {
-      *char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
-      *char_height = (*pixel_height - bdr - obh) / cph;
+      if (char_width)
+	*char_width = 1 + ((*pixel_width - egw) - bdr - obw) / cpw;
+      if (char_height)
+	*char_height = (*pixel_height - bdr - obh) / cph;
     }
   else
     {
-      *pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
-      *pixel_height = *char_height * cph + bdr + obh;
+      if (pixel_width)
+	*pixel_width = (*char_width - 1) * cpw + egw + bdr + obw;
+      if (pixel_height)
+	*pixel_height = *char_height * cph + bdr + obh;
     }
 }
 
@@ -2586,7 +2654,7 @@
 		    int *char_width, int *char_height)
 {
   frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
-			     char_height);
+			     char_height, 0);
 }
 
 /* Given a character size, this returns the minimum number of pixels
@@ -2602,7 +2670,7 @@
 		    int *pixel_width, int *pixel_height)
 {
   frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
-			     &char_height);
+			     &char_height, 0);
 }
 
 /* Given a pixel size, rounds DOWN to the smallest size in pixels necessary
@@ -2618,6 +2686,34 @@
   char_to_pixel_size (f, char_width, char_height, out_width, out_height);
 }
 
+/* Versions of the above which always account for real font metrics.
+ */
+void
+pixel_to_real_char_size (struct frame *f, int pixel_width, int pixel_height,
+			 int *char_width, int *char_height)
+{
+  frame_conversion_internal (f, 1, &pixel_width, &pixel_height, char_width,
+			     char_height, 1);
+}
+
+void
+char_to_real_pixel_size (struct frame *f, int char_width, int char_height,
+			 int *pixel_width, int *pixel_height)
+{
+  frame_conversion_internal (f, 0, pixel_width, pixel_height, &char_width,
+			     &char_height, 1);
+}
+
+void
+round_size_to_real_char (struct frame *f, int in_width, int in_height,
+			 int *out_width, int *out_height)
+{
+  int char_width;
+  int char_height;
+  pixel_to_real_char_size (f, in_width, in_height, &char_width, &char_height);
+  char_to_real_pixel_size (f, char_width, char_height, out_width, out_height);
+}
+
 /* Change the frame height and/or width.  Values may be given as zero to
    indicate no change is to take place. */
 static void
@@ -2625,7 +2721,7 @@
 {
   Lisp_Object frame;
   int new_pixheight, new_pixwidth;
-  int font_height, font_width;
+  int font_height, real_font_height, font_width;
 
   /* #### Chuck -- shouldn't we be checking to see if the frame
      is being "changed" to its existing size, and do nothing if so? */
@@ -2638,7 +2734,8 @@
 
   XSETFRAME (frame, f);
 
-  default_face_height_and_width (frame, &font_height, &font_width);
+  default_face_height_and_width (frame, &real_font_height, 0);
+  default_face_height_and_width_1 (frame, &font_height, &font_width);
 
   /* This size-change overrides any pending one for this frame.  */
   FRAME_NEW_HEIGHT (f) = 0;
@@ -2711,9 +2808,9 @@
 	  int old_minibuf_height =
 	    XWINDOW(FRAME_MINIBUF_WINDOW(f))->pixel_height;
 	  int minibuf_height =
-	    f->init_finished && (old_minibuf_height % font_height) == 0 ?
-	    max(old_minibuf_height, font_height) :
-	    font_height;
+	    f->init_finished && (old_minibuf_height % real_font_height) == 0 ?
+	    max(old_minibuf_height, real_font_height) :
+	    real_font_height;
 	  set_window_pixheight (FRAME_ROOT_WINDOW (f),
 				/* - font_height for minibuffer */
 				new_pixheight - minibuf_height, 0);