Re: Fix for 687451 default resolution for displaydevice

"Russell Lang" <[email protected]> Sun, 04 Jul 2004 11:31:17 +1000
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <40E7EA85.18581.992D4CEB@localhost>
An updated patch, to replace the one I sent on 1 July 2004.

Log Message:
Fixes bug Bug 687451 "default resolution for display device"
Set the display resolution from the MS-Windows display resolution,
using a device parameter -dDisplayResolution=DPI.

DETAILS:
The initial resolution must be set in display_put_params.
Setting it in display_open is too late because this leaves
the device resolution and currentpagedevice reporting
different values.  Callback can't be used in display_put_params
because the callback structure is not yet initialized.
This leaves a device parameter on the command line as
the cleanest implementation.
If HWResolution is set (e.g. from -r72), then use that.
Otherwise, if DisplayResolution is set, use that in the
initial display_put_params.  After that, ignore all further
use of DisplayResolution.
The Windows client adds -dDisplayResolution=DPI to the
command lines, similar to the existing -dDisplayFormat.
The Windows client gets the resolution from the GDI. 
The default Windows display resolution is 96dpi (the same
as the display device).  This can be changed to 120dpi by
selecting "large fonts", or other values in recent versions
of Windows.

diff -u l:/cvs/gs/src/dwmain.c src/dwmain.c
--- l:/cvs/gs/src/dwmain.c	Sat Jul 03 10:51:14 2004
+++ src/dwmain.c	Sun Jul 04 01:10:33 2004
@@ -271,6 +271,7 @@
     int nargc;
     char **nargv;
     char dformat[64];
+    char ddpi[64];
     char buf[256];
 
     memset(buf, 0, sizeof(buf));
@@ -300,6 +301,7 @@
 		DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 	HDC hdc = GetDC(NULL);	/* get hdc for desktop */
 	int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
+	sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY));
         ReleaseDC(NULL, hdc);
 	if (depth == 32)
  	    format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | 
@@ -319,11 +321,12 @@
 		DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
         sprintf(dformat, "-dDisplayFormat=%d", format);
     }
-    nargc = argc + 1;
+    nargc = argc + 2;
     nargv = (char **)malloc((nargc + 1) * sizeof(char *));
     nargv[0] = argv[0];
     nargv[1] = dformat;
-    memcpy(&nargv[2], &argv[1], argc * sizeof(char *));
+    nargv[2] = ddpi;
+    memcpy(&nargv[3], &argv[1], argc * sizeof(char *));
 
     code = gsdll.init_with_args(instance, nargc, nargv);
     if (code == 0)
diff -u l:/cvs/gs/src/dwmainc.c src/dwmainc.c
--- l:/cvs/gs/src/dwmainc.c	Sat Jul 03 10:51:14 2004
+++ src/dwmainc.c	Sun Jul 04 00:50:06 2004
@@ -329,6 +329,7 @@
     char **nargv;
     char buf[256];
     char dformat[64];
+    char ddpi[64];
 
     if (!_isatty(fileno(stdin)))
         _setmode(fileno(stdin), _O_BINARY);
@@ -379,6 +380,7 @@
 		DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
 	HDC hdc = GetDC(NULL);	/* get hdc for desktop */
 	int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
+	sprintf(ddpi, "-dDisplayResolution=%d", GetDeviceCaps(hdc, LOGPIXELSY));
         ReleaseDC(NULL, hdc);
 	if (depth == 32)
  	    format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | 
@@ -398,11 +400,12 @@
 		DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST;
         sprintf(dformat, "-dDisplayFormat=%d", format);
     }
-    nargc = argc + 1;
+    nargc = argc + 2;
     nargv = (char **)malloc((nargc + 1) * sizeof(char *));
     nargv[0] = argv[0];
     nargv[1] = dformat;
-    memcpy(&nargv[2], &argv[1], argc * sizeof(char *));
+    nargv[2] = ddpi;
+    memcpy(&nargv[3], &argv[1], argc * sizeof(char *));
 
     code = gsdll.init_with_args(instance, nargc, nargv);
     if (code == 0)
diff -u l:/cvs/gs/src/gdevdsp.c src/gdevdsp.c
--- l:/cvs/gs/src/gdevdsp.c	Sat Jul 03 10:51:14 2004
+++ src/gdevdsp.c	Sun Jul 04 01:13:35 2004
@@ -204,6 +204,7 @@
     0,				/* nFormat */
     NULL,			/* pBitmap */
     0, 				/* ulBitmapSize */
+    0, 				/* HWResolution_set */
 
     {    /* devn_params specific parameters */
       8,        /* Bits per color - must match ncomp, depth, etc. */
@@ -748,6 +749,8 @@
 	    "DisplayHandle", (long *)(&ddev->pHandle))) < 0 ||
 	(code = param_write_int(plist, 
 	    "DisplayFormat", &ddev->nFormat)) < 0 ||
+	(code = param_write_float(plist, 
+	    "DisplayResolution", &ddev->HWResolution[1])) < 0 ||
 	(code = devn_get_params(dev, plist, &ddev->devn_params, 
 		&ddev->equiv_cmyk_colors)) < 0);
     return code;
@@ -764,6 +767,8 @@
     gx_device_display *ddev = (gx_device_display *) dev;
     int ecode = 0, code;
     bool is_open = dev->is_open;
+    gs_param_float_array hwra;
+    float dispres = 0.0;
 
     int old_width = dev->width;
     int old_height = dev->height;
@@ -821,6 +826,31 @@
 	    ecode = code;
 	  hdle:param_signal_error(plist, "DisplayHandle", ecode);
 	case 1:
+	    break;
+    }
+
+    /* 
+     * Set the initial display resolution.
+     * If HWResolution is explicitly set, e.g. using -rDPI on the 
+     * command line, then use that.  Otherwise, use DisplayResolution
+     * which is typically set by the client to the display
+     * logical resolution.  Once either of these have been
+     * used, ignore all further DisplayResolution parameters.
+     */
+    if (param_read_float_array(plist, "HWResolution", &hwra) == 0)
+	ddev->HWResolution_set = 1;
+
+    switch (code = param_read_float(plist, "DisplayResolution", &dispres)) {
+	case 0:
+	    if (!ddev->HWResolution_set) {
+	        gx_device_set_resolution(dev, dispres, dispres);
+		ddev->HWResolution_set = 1;
+	    }
+	    break;
+	default:
+	    ecode = code;
+	    param_signal_error(plist, "DisplayResolution", ecode);
+	case 1:
 	    break;
     }
 
diff -u l:/cvs/gs/src/gdevdsp.h src/gdevdsp.h
--- l:/cvs/gs/src/gdevdsp.h	Sat Jul 03 10:51:14 2004
+++ src/gdevdsp.h	Sun Jul 04 01:09:37 2004
@@ -216,6 +216,7 @@
      * and hence to RGB for display.
      * GS must only use this callback if version_major >= 2.
      * The unsigned short c,m,y,k values are 65535 = 1.0.
+     * This function pointer may be set to NULL if not required.
      */
     int (*display_separation)(void *handle, void *device,
 	int component, const char *component_name,
diff -u l:/cvs/gs/src/gdevdsp2.h src/gdevdsp2.h
--- l:/cvs/gs/src/gdevdsp2.h	Sat Jul 03 10:51:14 2004
+++ src/gdevdsp2.h	Sat Jul 03 12:21:17 2004
@@ -29,6 +29,7 @@
 	int nFormat;\
 	void *pBitmap;\
 	unsigned long ulBitmapSize;\
+	int HWResolution_set;\
         gs_devn_params devn_params;\
         equivalent_cmyk_color_params equiv_cmyk_colors

diff -u l:/cvs/gs/doc/Devices.htm doc/Devices.htm
--- l:/cvs/gs/doc/Devices.htm	Sat Jul 03 10:51:13 2004
+++ doc/Devices.htm	Sun Jul 04 01:18:19 2004
@@ -638,6 +638,12 @@
 </ul>
 For more details, see the <a href="API.htm#display">Ghostscript 
 Interpreter API.</a>
+<dt><b><tt>-dDisplayResolution=</tt></b><b><em>DPI</em></b>
+<dd>Set the initial resolution resolution for the display device.
+This is used by the Windows clients to set the display device
+resolution to the Windows display logical resolution.
+This can be overriden by the command line option 
+<b><tt>-r</tt><em>DPI</em></b>.
 </dl>
 
 </blockquote>

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review