octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [changeset] Missing ScreenSize & ScreenPixelsPerInch properties


From: John W. Eaton
Subject: Re: [changeset] Missing ScreenSize & ScreenPixelsPerInch properties
Date: Thu, 22 Jan 2009 10:36:36 -0500

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;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]