Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-03

Controlling DPI

16 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys
to ik

2009/3/28 ik :

How can I control the DPI of a Lazarus based application regardless of the environment (gnome/kde etc..) DPI ?

Umm, good question. I thought there was a Screen.DPI or Screen.DotsPerInch setting, but I can't find it. Maybe I'm getting confused with Kylix.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 8 lines
2009/3/28 ik : > > How can I control the DPI of a Lazarus based application regardless of the > environment (gnome/kde etc..) DPI ? Umm, good question. I thought there was a Screen.DPI or Screen.DotsPerInch setting, but I can't find it. Maybe I'm getting confused with Kylix.

it is

Screen.PixelsPerInch

But this is read-only. For the rest, the answer depends entirely on what you want to do.

Michael.

ik
to Michael Van Canneyt

I would like to allow users to set their own DPI as they think it best for them.

Ido

On Sat, Mar 28, 2009 at 3:50 PM, Michael Van Canneyt <

Show quoted text 29 lines
wrote: On Sat, 28 Mar 2009, Graeme Geldenhuys wrote: > 2009/3/28 ik : > > > > How can I control the DPI of a Lazarus based application regardless of the > > environment (gnome/kde etc..) DPI ? > > Umm, good question. I thought there was a Screen.DPI or > Screen.DotsPerInch setting, but I can't find it. Maybe I'm getting > confused with Kylix. it is Screen.PixelsPerInch But this is read-only. For the rest, the answer depends entirely on what you want to do. Michael. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090328/c8612f2b/attachment.html

Michael Van Canneyt
to ik
ik wrote
I would like to allow users to set their own DPI as they think it best for them.

A zoom factor or the actual DPI ? The former is possible, the latter I have no idea how to do this.

Michael.

ik
to Michael Van Canneyt

I prefer the latter, but the zoon factor can also do the trick.

IDo

On Sat, Mar 28, 2009 at 6:26 PM, Michael Van Canneyt <

Show quoted text 19 lines
wrote: On Sat, 28 Mar 2009, ik wrote: > I would like to allow users to set their own DPI as they think it best for > them. A zoom factor or the actual DPI ? The former is possible, the latter I have no idea how to do this. Michael. _______________________________________________ Lazarus mailing list http://www.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090328/7887bc8b/attachment.html

David W Noon
to ik
ik wrote
I prefer the latter, but the zoon factor can also do the trick.

The DPI is controlled by the hardware driver for the video card. It applies to the entire screen and cannot be changed for a particular window on the screen. The only way to alter it is to restart the video driver with different initialization parameters. [For a UNIX-like system (e.g. Linux, FreeBSD), this means altering the X11 configuration and restarting the X11 daemon.]

A zoom factor applies to an image, either pictorial or rendered text. You can do whatever you want with that within your application.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Hans-Peter Diettrich
to David W Noon
> I prefer the latter, but the zoon factor can also do the trick. The DPI is controlled by the hardware driver for the video card.

That's a matter of definition of "DPI".

Windows allows to change the font size (DPI) at any time, and most other systems have similar capabilities. Since Delphi has its roots in Windows, this definition also should apply to FPC/Lazarus.

Show quoted text 6 lines
It applies to the entire screen and cannot be changed for a particular window on the screen. The only way to alter it is to restart the video driver with different initialization parameters. [For a UNIX-like system (e.g. Linux, FreeBSD), this means altering the X11 configuration and restarting the X11 daemon.]

Changing the screen resolution, for one or more monitors, requires an restart of the graphics system (GDI, X11...), of course, because it affects the desktop and all windows on the monitor(s).

DoDi

David W Noon
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 7 lines
David W Noon schrieb: >> I prefer the latter, but the zoon factor can also do the trick. > > The DPI is controlled by the hardware driver for the video card. That's a matter of definition of "DPI".

There is only one definition of DPI for any given device. Moreover, what you have written below isn't it -- for any device.

Windows allows to change the font size (DPI) at any time, and most other systems have similar capabilities. Since Delphi has its roots in Windows, this definition also should apply to FPC/Lazarus.

The *point size* of the font has nothing whatsoever to do with the DPI of the screen or printer, other than the rendering engine querying the DPI of the device in order to render the text to the appropriate size in pica points. There are approximately 72 pica points to an inch, regardless of the DPI of the device on which the text is being rendered.

See:
http://en.wikipedia.org/wiki/Pica_(unit_of_measure)

[The pica has also been "Americanized" to be exactly 1/72nd of an inch within the computer industry, but the classic definition if picas/didots and ciceros does not fit easily in Imperial Measures.]

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Hans-Peter Diettrich
to David W Noon: There is only one definition of DPI for any given device. Moreover, what you have written…
Show quoted text 8 lines
> Windows allows to change the font size (DPI) at any time, and most other > systems have similar capabilities. Since Delphi has its roots in > Windows, this definition also should apply to FPC/Lazarus. The *point size* of the font has nothing whatsoever to do with the DPI of the screen or printer, other than the rendering engine querying the DPI of the device in order to render the text to the appropriate size in pica points.

Right. The application provides a font size, and the system translates it into pixels, based on the Screen.DPI value. Pixel based sizes, as used in the LCL for the origin and extent of the forms and controls, are not affected by the DPI settings.

If you want to change that DPI factor, your application can scale the size of every used font accordingly.

Please specify if you have something else in mind, like an zoom factor for *all* elements of your application.

DoDi

David W Noon
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 13 lines
David W Noon schrieb: >> Windows allows to change the font size (DPI) at any time, and most other >> systems have similar capabilities. Since Delphi has its roots in >> Windows, this definition also should apply to FPC/Lazarus. > > The *point size* of the font has nothing whatsoever to do with the DPI > of the screen or printer, other than the rendering engine querying the > DPI of the device in order to render the text to the appropriate size in > pica points. Right. The application provides a font size, and the system translates it into pixels, based on the Screen.DPI value.

Specifically, the font engine uses the DPI provided by the video (or printer) driver. The application doesn't need to consider the DPI value, as fonts are specified in points and the font engine renders them appropriately. For example, a 12-point font should render to 1/6th of an inch high, regardless of the device's DPI.

Pixel based sizes, as used in the LCL for the origin and extent of the forms and controls, are not affected by the DPI settings.

I am not sure about this. I think they could well be affected by DPI, but the Lazarus developers could say for sure.

If you want to change that DPI factor, your application can scale the size of every used font accordingly.

No, this is wrong. The fonts do not need to be rescaled.

The point size required for a font to render to a particular size on screen or paper is independent of the DPI of the device. Point sizes are based on 1/72nd of an inch, regardless of how many device dots are in that inch. It is the American inch (slightly larger than the traditional Imperial inch, which it has largely supplanted) that is the defining factor, and this is fixed.

Please specify if you have something else in mind, like an zoom factor for *all* elements of your application.

It's not my application, so I presume this is intended for the o.p.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================
Graeme Geldenhuys
to Hans-Peter Diettrich: That's a matter of definition of "DPI". Windows allows to change the font size (DPI) at…
Hans-Peter Diettrich wrote
Changing the screen resolution, for one or more monitors, requires an restart of the graphics system (GDI, X11...), of course, because it affects the desktop and all windows on the monitor(s).

In Gnome you can select the DPI and it will affect all Gnome based applications - without a restart. Firefox and Thunderbird also allow you to select a specific DPI which then only applies to the application. But I think with all these, they simply take the real screen dpi and calculate the zoom factor for the applications.

All this is doable in FPC/Lazarus already.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Hans-Peter Diettrich
to David W Noon: Specifically, the font engine uses the DPI provided by the video (or printer) driver. The…
Specifically, the font engine uses the DPI provided by the video (or printer) driver.

In general: of the given Device Context (Windows: DC).

Show quoted text 6 lines
> Pixel based sizes, as > used in the LCL for the origin and extent of the forms and controls, are > not affected by the DPI settings. I am not sure about this. I think they could well be affected by DPI, but the Lazarus developers could say for sure.

Most Microsoft languages (VB, VC...) scale all visual elements in "twips" (1/20 point), but the Delphi VCL uses pixels for everything but fonts. As long as the LCL is Delphi compatible, it must behave in the same way.

Show quoted text 7 lines
> If you want to change that DPI factor, your application can scale the > size of every used font accordingly. No, this is wrong. The fonts do not need to be rescaled. The point size required for a font to render to a particular size on screen or paper is independent of the DPI of the device.

For pixel based output devices, the graphic system converts all units into pixels, based on the DPI value of the given device context. Then it depends on the actual device, how big the output will appear. At least on Windows a logical inch on the screen is larger than a physical inch, and the user can change that ratio by adjusting the DPI factor (accessibility option).

Show quoted text 5 lines
Point sizes are based on 1/72nd of an inch, regardless of how many device dots are in that inch. It is the American inch (slightly larger than the traditional Imperial inch, which it has largely supplanted) that is the defining factor, and this is fixed.

The established font sizes are essential for print media. Computer monitors have such a poor resolution, that in most cases the font size has to be increased for readable output. When you measure the font height on a monitor, it typically will be larger than the given (point) size of the font. On my Linux system 10cm really are 11cm on screen, independent of the screen size and geometry.

DoDi

Hans-Peter Diettrich
to Graeme Geldenhuys: On Sat, Mar 28, 2009 at 8:17 PM, Hans-Peter Diettrich In Gnome you can select the DPI and…
Show quoted text 6 lines
> Changing the screen resolution, for one or more monitors, requires an > restart of the graphics system (GDI, X11...), of course, because it > affects the desktop and all windows on the monitor(s). In Gnome you can select the DPI and it will affect all Gnome based applications - without a restart.

Well, it can be a soft restart, where all affected elements of the screen are repositioned and repainted in the new scaling.

Firefox and Thunderbird also allow you to select a specific DPI which then only applies to the application.

On KDE e.g. Firefox only allows to adjust the font size, and the font sizes in HTML documents are application dependent, not expressed in points. The text in the title bar etc. are not affected by such an adjustment.

But I think with all these, they simply take the real screen dpi and calculate the zoom factor for the applications. All this is doable in FPC/Lazarus already.

The OP asked *how* to do that. When it depends on the screen manager (Windows/KDE/Gnome...), the procedures may depend on the selected widgetset in Lazarus?

DoDi

Graeme Geldenhuys
to Hans-Peter Diettrich
Hans-Peter Diettrich wrote 5 lines
On KDE e.g. Firefox only allows to adjust the font size, and the font sizes in HTML documents are application dependent, not expressed in points. The text in the title bar etc. are not affected by such an adjustment.

====================
If none of the above or variations thereof work, as a last resort, you can use the brute force method of forcing Mozilla to use a particular DPI directly. Edit your user.js file and add:

	user_pref("layout.css.dpi", 108);

You may change the DPI number to any resolution you like. Setting it to 0 will restore Mozilla's use of the X Server DPI. Like prefs.js, user.js is a plain text file in your profile directory. If it doesn't exist, create it with your choice of text editor.

As an alternative to editing user.js, you can change layout.css.dpi by entering

about:config

in the urlbar, right clicking the current value, and changing it to any number you like.
======================

For more information on correctly setting your DPI system wide.

http://www.mozilla.org/unix/dpi.html

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/