[changeset] Missing ScreenSize & ScreenPixelsPerInch properties

Ben Abbott bpabbott at mac.com
Thu Jan 22 11:56:12 CST 2009


On Thursday, January 22, 2009, at 10:36AM, "John W. Eaton" <jwe at octave.org> wrote:
>On 22-Jan-2009, Ben Abbott wrote:
>
>| Better yet, if octave is able to parse compressed XML files, the information can be read directly.
>
>I'd rather call a few simple functions from C++ like on other
>systems.  Does the following work?
>
>jwe
>
>
>#include <iostream>
>
>#include <CGDirectDisplay.h>
>#include <CGDisplayConfiguration.h>
>
>int
>main (void)
>{
>  CGDirectDisplayID display = CGMainDisplayID ();
>
>  if (display)
>    {
>
>      size_t ht = CGDisplayPixelsHigh (display);
>      size_t wd = CGDisplayPixelsWide (display);
>
>      std::cerr << wd << "x" << ht << " pixels" << std::endl;
>
>      CGSize sz_mm = CGDisplayScreenSize (display);
>
>      CGFloat ht_mm = sz_mm.height;
>      CGFloat wd_mm = sz_mm.width;
>
>      std::cerr << wd_mm << "x" << ht_mm << " mm" << std::endl;
>
>      double resy = wd * 25.4 / wd_mm;
>      double resx = ht * 25.4 / ht_mm;
>
>      std::cerr << resx << " resx" << std::endl;
>      std::cerr << resy << " resx" << std::endl;
>
>      std::cerr << (resx + resy) / 2 << " avg dpi" << std::endl;
>
>      size_t depth = CGDisplayBitsPerPixel (display);
>
>      std::cerr << depth << " bit depth" << std::endl;
>    }
>  else
>    std::cerr << "failed to find display" << std::endl;
>
>  return 0;
>}

The program's output is below.

1280x1024 pixels
380x310 mm
83.9019 resx
85.5579 resx
84.7299 avg dpi
32 bit depth

I can confirm the numbers are correct as well ... well almost. The physical size of my screen is 14.75x11.75 inches.

>> [1280,1024]./[14.75,11.75]
ans =
   86.7797   87.1489

The manufacturer likes to claim 15x12inches

>> [1280,1024]./[15,12]
ans =
   85.3333   85.3333

In any event, looks good to me.

Ben






More information about the Octave-maintainers mailing list