Recent

Author Topic: Most general way of getting screen pixelsperinch  (Read 3378 times)

wp

  • Hero Member
  • *****
  • Posts: 11858
Most general way of getting screen pixelsperinch
« on: April 18, 2014, 12:47:57 pm »
I am implementing column width support for fpspreadsheet. I want to provide several units, millimeters, pixels, characters etc.

For the conversion between units I need the screen resolution as pixels per inch in a very general way. I know that I can get this information from Screen.PixelsPerInch in unit Forms, or from ScreenInfo.PixelsPerInchX/Y in unit Graphics. But fpspreadsheet is supposed to be a very general library, there may be cases when these units are not used by the application, and I don't want to enforce their use. Is there another way to get the pixels per inch?

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Most general way of getting screen pixelsperinch
« Reply #1 on: April 18, 2014, 12:59:31 pm »
To many questions to little time let me ask those 3 for starters
1) you know that most of the time the reported DPI from the systems is an aproximation right? If yes then simple use 96 and you are right 90% of the time in todays TFTs and so own.
2) Have you tried to copy the code from the methods you just mentioned to a more system agnostic unit you can use?
3) Why you need dpi for a suite that only handles files? Wouldn't this be better left to the end user to provide ee add a default value of 96 and let the end user change it if the system requires it.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Most general way of getting screen pixelsperinch
« Reply #2 on: April 18, 2014, 01:21:45 pm »
Yes I think that's the solution: I define the column width only in terms of some kind of average character widths (similar to Excel). If the user wants other units it is his responsibility to do the conversion -- he should know all required parameters.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Most general way of getting screen pixelsperinch
« Reply #3 on: April 18, 2014, 01:30:20 pm »
exactly, just make sure that the average calculation is well documented and you are the king.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Most general way of getting screen pixelsperinch
« Reply #4 on: April 18, 2014, 02:01:33 pm »
No. Until you attach to a device (to display), there is no such info. There might be various displays with different DPI settings, and even if you know it will be displayed, you don't know which one, and thus can't know DPI till you really render.

So the most sane solution would be to  either

1) in the case it is going to be rendered on a canvas (display, printer, whatever), postpone decisions as long as possible till these are clear.

or
2) require user to specify it before rendering.

Rails

  • Guest
Re: Most general way of getting screen pixelsperinch
« Reply #5 on: April 18, 2014, 02:14:53 pm »
In some cases the display reports the DPI to the OS.

In some cases the OS will report the actual DPI to the application if it gets it from the display.

In some cases the OS will report something it makes up to the application. Usually 96 DPI.

In the case of Lazarus, the forms unit screen variable will hold the OS DPI value. If the OS information is absent, it will report 75 DPI.


 

TinyPortal © 2005-2018