Fix for 687451 default resolution for display device
"Russell Lang" <[email protected]> Thu, 01 Jul 2004 12:01:33 +1000
| Newsgroups | gmane.comp.printing.ghostscript.patches |
|---|---|
| Message-ID | <40E3FD1D.13760.E4990@localhost> |
Log Message: Set the display resolution from the MS-Windows display resolution. Fixes bug Bug 687451 "default resolution for display device" DETAILS: This affects Windows only and can't be built into the display device, since this code is platform independent. The implementation checks the command line to see if the display device is used and resolution is not specified, and if so adds the resolution from Windows LOGPIXELSY to the command line. This could be confused by various means, including setting the device and resolution with PostScript code on the command line. 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. Russell Lang [email protected] diff -u /cvs/gs/src/dwmain.c src/dwmain.c --- /cvs/gs/src/dwmain.c Mon Jun 21 05:33:38 2004 +++ src/dwmain.c Thu Jul 01 01:27:03 2004 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2001 Ghostgum Software Pty Ltd. All rights reserved. +/* Copyright (C) 1996-2004 Ghostgum Software Pty Ltd. All rights reserved. This software is provided AS-IS with no warranty, either express or implied. @@ -255,6 +255,11 @@ char **nargv; char dformat[64]; char buf[256]; + char ddpi[64]; + int dpi; + int use_dpi = 1; + int extra_args = 1; + int i; memset(buf, 0, sizeof(buf)); if (load_dll(&gsdll, buf, sizeof(buf))) { @@ -283,6 +288,7 @@ DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST; HDC hdc = GetDC(NULL); /* get hdc for desktop */ int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); + dpi = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); if (depth == 32) format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | @@ -302,11 +308,30 @@ DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST; sprintf(dformat, "-dDisplayFormat=%d", format); } - nargc = argc + 1; - nargv = (char **)malloc((nargc + 1) * sizeof(char *)); + /* If using display device, and resolution not specified, + * use the resolution reported by Windows. + */ + for (i=1; i<argc; i++) { + if (argv[i][0] == '@') + use_dpi = 0; /* dpi or device could be specified in config file */ + if ((strncmp(argv[i], "-sDEVICE=", 9) == 0) && + (strcmp(argv[i], "-sDEVICE=display") != 0)) + use_dpi = 0; /* not display device */ + if (strncmp(argv[i], "-r", 2) == 0) + use_dpi = 0; /* dpi already specified */ + } + if (use_dpi) { + sprintf(ddpi, "-r%d", dpi); + extra_args++; + } + + nargc = argc + extra_args; + nargv = (char **)malloc((nargc + extra_args) * sizeof(char *)); nargv[0] = argv[0]; nargv[1] = dformat; - memcpy(&nargv[2], &argv[1], argc * sizeof(char *)); + if (use_dpi) + nargv[2] = ddpi; + memcpy(&nargv[extra_args+1], &argv[1], argc * sizeof(char *)); code = gsdll.init_with_args(instance, nargc, nargv); if (code == 0) diff -u /cvs/gs/src/dwmainc.c src/dwmainc.c --- /cvs/gs/src/dwmainc.c Mon Jun 21 05:36:29 2004 +++ src/dwmainc.c Thu Jul 01 01:26:22 2004 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-2001 Ghostgum Software Pty Ltd. All rights reserved. +/* Copyright (C) 1996-2004 Ghostgum Software Pty Ltd. All rights reserved. This software is provided AS-IS with no warranty, either express or implied. @@ -313,6 +313,11 @@ char **nargv; char buf[256]; char dformat[64]; + char ddpi[64]; + int dpi; + int use_dpi = 1; + int extra_args = 1; + int i; if (!_isatty(fileno(stdin))) _setmode(fileno(stdin), _O_BINARY); @@ -363,6 +368,7 @@ DISPLAY_DEPTH_1 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST; HDC hdc = GetDC(NULL); /* get hdc for desktop */ int depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); + dpi = GetDeviceCaps(hdc, LOGPIXELSY); ReleaseDC(NULL, hdc); if (depth == 32) format = DISPLAY_COLORS_RGB | DISPLAY_UNUSED_LAST | @@ -382,11 +388,30 @@ DISPLAY_DEPTH_4 | DISPLAY_LITTLEENDIAN | DISPLAY_BOTTOMFIRST; sprintf(dformat, "-dDisplayFormat=%d", format); } - nargc = argc + 1; - nargv = (char **)malloc((nargc + 1) * sizeof(char *)); + /* If using display device, and resolution not specified, + * use the resolution reported by Windows. + */ + for (i=1; i<argc; i++) { + if (argv[i][0] == '@') + use_dpi = 0; /* dpi or device could be specified in config file */ + if ((strncmp(argv[i], "-sDEVICE=", 9) == 0) && + (strcmp(argv[i], "-sDEVICE=display") != 0)) + use_dpi = 0; /* not display device */ + if (strncmp(argv[i], "-r", 2) == 0) + use_dpi = 0; /* dpi already specified */ + } + if (use_dpi) { + sprintf(ddpi, "-r%d", dpi); + extra_args++; + } + + nargc = argc + extra_args; + nargv = (char **)malloc((nargc + extra_args) * sizeof(char *)); nargv[0] = argv[0]; nargv[1] = dformat; - memcpy(&nargv[2], &argv[1], argc * sizeof(char *)); + if (use_dpi) + nargv[2] = ddpi; + memcpy(&nargv[extra_args+1], &argv[1], argc * sizeof(char *)); code = gsdll.init_with_args(instance, nargc, nargv); if (code == 0) _______________________________________________ gs-code-review mailing list [email protected] http://www.ghostscript.com/mailman/listinfo/gs-code-review