Mercurial > octave-libtiff
changeset 27181:5754e8d8199a
guess screen dpi if screen size is reported to be zero
* cdisplay.c (octave_get_display_info): Guess screen DPI if screen
size is zero. Refactor to perform DPI calculation and error detection
in one place.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Jun 2019 09:23:11 -0500 |
parents | 269d71efaf04 |
children | 0beeb6817376 |
files | libinterp/corefcn/cdisplay.c |
diffstat | 1 files changed, 30 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/cdisplay.c Wed Jun 12 16:55:22 2019 -0500 +++ b/libinterp/corefcn/cdisplay.c Thu Jun 13 09:23:11 2019 -0500 @@ -55,6 +55,9 @@ *dpy_avail = 0; + double ht_mm = 0.0; + double wd_mm = 0.0; + #if defined (OCTAVE_USE_WINDOWS_API) octave_unused_parameter (dpy_name); @@ -68,11 +71,8 @@ *ht = GetDeviceCaps (hdc, VERTRES); *wd = GetDeviceCaps (hdc, HORZRES); - double ht_mm = GetDeviceCaps (hdc, VERTSIZE); - double wd_mm = GetDeviceCaps (hdc, HORZSIZE); - - *rx = *wd * 25.4 / wd_mm; - *ry = *ht * 25.4 / ht_mm; + ht_mm = GetDeviceCaps (hdc, VERTSIZE); + wd_mm = GetDeviceCaps (hdc, HORZSIZE); *dpy_avail = 1; } @@ -118,11 +118,8 @@ values, but the CGFloat typedef is not present on older systems, so use double instead. */ - double ht_mm = sz_mm.height; - double wd_mm = sz_mm.width; - - *rx = *wd * 25.4 / wd_mm; - *ry = *ht * 25.4 / ht_mm; + ht_mm = sz_mm.height; + wd_mm = sz_mm.width; *dpy_avail = 1; } @@ -149,11 +146,8 @@ int screen_number = XScreenNumberOfScreen (screen); - double ht_mm = DisplayHeightMM (display, screen_number); - double wd_mm = DisplayWidthMM (display, screen_number); - - *rx = *wd * 25.4 / wd_mm; - *ry = *ht * 25.4 / ht_mm; + ht_mm = DisplayHeightMM (display, screen_number); + wd_mm = DisplayWidthMM (display, screen_number); } else msg = "X11 display has no default screen"; @@ -178,5 +172,26 @@ #endif + if (*dpy_avail) + { + if (wd_mm == 0 || ht_mm == 0) + { + msg = "screen width or height reported to be zero"; + + // Sizes reported as zero have been found on some systems. + // For example, X/Wayland running inside virtualbox. + + // Guess a DPI. + + *rx = 96.0; + *ry = 96.0; + } + else + { + *rx = *wd * 25.4 / wd_mm; + *ry = *ht * 25.4 / ht_mm; + } + } + return msg; }