Difference between revisions of "High DPI/ru"

From Free Pascal wiki
Jump to navigationJump to search
Line 56: Line 56:
 
Если вы выбрали 125% (120 DPI), опция «Использовать масштабирование DPI в стиле Windows XP» будет включена. Приложения, которые вы запускаете под этим параметром, масштабируются так, как будто они работают под Windows XP.
 
Если вы выбрали 125% (120 DPI), опция «Использовать масштабирование DPI в стиле Windows XP» будет включена. Приложения, которые вы запускаете под этим параметром, масштабируются так, как будто они работают под Windows XP.
  
If you select 150% (144 DPI) the option "Use Windows XP style DPI scaling" is disabled (DPI Virtualization is enabled), and applications you run under this setting must be High DPI Awareness to prevent system scaling which will produce a blurred image.
+
Если вы выберете 150% (144 DPI), опция «Использовать масштабирование DPI в стиле Windows XP» будет отключена (виртуализация DPI включена), и приложения, которые вы запускаете с этим параметром, должны иметь High DPI Awareness, чтобы предотвратить масштабирование системы, которое приведет к размытию изображения.
  
You can also set your custom DPI setting via the option "Set custom text size (DPI)" and enable/disable the DPI Virtualization.
+
Вы также можете установить свои собственные настройки DPI с помощью параметра "Set custom text size (DPI)"(Установить собственный размер текста (DPI)) и включить/отключить виртуализацию DPI.
  
 
==== Windows 8 Metro Applications ====
 
==== Windows 8 Metro Applications ====

Revision as of 16:00, 2 February 2019

Deutsch (de) English (en) español (es) русский (ru)

Вступление

DPI (Dots Per Inch) - это соотношение между размером в пикселях и фактическим размером дисплея. Здесь точка является эквивалентом пикселя в терминологии печати. Приложения могут либо использовать размеры в пикселях, либо учитывать фактический размер дисплея. Во втором случае размеры указаны в пунктах.

Большинство современных операционных систем используют значение DPI по умолчанию, установленное в 96, и позволяют вручную изменить его на более высокое значение. Физический DPI можно определить по отображению через протокол EDID по данным физического размера и фактического разрешения. Но физический DPI не используется системой автоматически, поэтому, если вы подключите видеовыход к монитору с другим размером, то разрешение экрана и визуальный размер элементов управления не изменятся автоматически.

Обычно DPI представляется как одно значение, но оно может отличаться для горизонтальной и вертикальной осей, если пиксель не квадратный.

В дополнение к базовому пониманию DPI приложения вы можете добавить в приложение собственные параметры DPI, чтобы пользователи могли настраивать DPI для каждого приложения, чтобы избежать неправильной настройки DPI системы.

Свойства Lazarus, ссылающиеся на DPI


Пиксели и точки

Например, 300 DPI означает, что на дюйм приходится 300 пикселей (или точек). Есть 72 точки на дюйм, так что:

300 пикселей ↔ 1 дюйм

300/72 пикселей ↔ 1 точка

4,16 пикселей ↔ 1 точка

Теперь с 96 DPI:

96 пикселей ↔ 1 дюйм

1,33 пикселя ↔ 1 дюйм

Теперь с 144 DPI:

144 пикселя ↔ 1 дюйм

2 пикселя ↔ 1 точка

Настройка High DPI

Windows

В Windows 95 и более поздних версиях можно изменить соотношение DPI, чтобы увеличить размер элементов. Высокий DPI означает любую пользовательскую настройку DPI с более чем 96 DPI (настройка по умолчанию) (ссылка).

Высокая осведомленность о DPI означает, что приложение учитывает этот параметр DPI.

Windows Vista и Windows 7

В Windows 7 перейдите в «Панель управления > Все элементы управления > Экран».

Выберите Мелкий 100% (по умолчанию), Средний 125% или Крупный 150%. Если вы выбираете 100% (96 DPI), это значение по умолчанию для Windows DPI (High DPI не используется по умолчанию).

Если вы выбрали 125% (120 DPI), опция «Использовать масштабирование DPI в стиле Windows XP» будет включена. Приложения, которые вы запускаете под этим параметром, масштабируются так, как будто они работают под Windows XP.

Если вы выберете 150% (144 DPI), опция «Использовать масштабирование DPI в стиле Windows XP» будет отключена (виртуализация DPI включена), и приложения, которые вы запускаете с этим параметром, должны иметь High DPI Awareness, чтобы предотвратить масштабирование системы, которое приведет к размытию изображения.

Вы также можете установить свои собственные настройки DPI с помощью параметра "Set custom text size (DPI)"(Установить собственный размер текста (DPI)) и включить/отключить виртуализацию DPI.

Windows 8 Metro Applications

For Windows 8 Metro Applications read this http://blogs.msdn.com/b/b8/archive/2012/03/21/scaling-to-different-screens.aspx

Windows 10

Windows 10 "Control Panel > Appearance and Personalization > Display" have more options. You can have different font sizes for each element: Title bar, Menu, Dialog box and so on. Ensure you test twice in order to check if everything works under different sizes.

Now is based on Font Size, not DPI. The DPI option is not recommended, but still there. So, instead of changing the size of all elements in desktop, this will change just the font size (And of course everything else is changed to fit).

Remember that under Windows 10 there are Universal Applications (WinRT) and the classic desktop applications (Win32). We're talking here about desktop applications.

Linux

On Linux DPI setting is more complicated and depends on used software and their version.

You can discover your current monitor DPI by command:

xdpyinfo|grep dots

You can change DPI to new value by command:

xrandr --dpi 144x144

To preserve setting after reboot you need to add the command as script to /etc/X11/Xsession.d/77set_dpi.

More information:

Examples

Fixed Font Sizes (not HighDPI)

Here is a form with an undefined font size (set to zero, which is the default value). It has been designed at 96 DPI (100%), and it looks like this :

Testdpi100.png

Now, at 120 DPI (125%), it becomes :

Testdpi125.png

As you can see, the font gets bigger and so the text is clipped. The window title gets bigger, but the client area of the window remains the same size. Note that these changes in size can occur by using an application with a different Windows theme, or with another operating system.

To avoid this, you must set the font size to a non-zero value. Note that Font.Size is expressed in points and Font.Height is expressed in pixels. In fact, only the value of Font.Height is stored, and Font.Size changes according to current DPI value. So if we set the font size, it will be fixed to a certain size in pixels.

If we try again with a fixed font size of 9 points, then at 96 DPI (100%), we get this :

Testdpi100fixedM12P9.png

Now if the same program is run at 120 DPI (125%), it becomes :

Testdpi125fixedM12P9.png

The result is the almost the same. The title bar is bigger, but the client area and the font size is the same. Note that in fact, the size in points of the font has changed.

The conclusion from this is that it is possible to avoid inconsistency in the display by fixing font sizes. But we do not take into account that the graphical elements may be smaller according to actual DPI of the screen. With DPI awareness, it is possible to make an application behave as if it knew the real size of the pixels.


DPI Aware Application (For Vista +)

CPickSniff is an application to capture screen colors. We will use it as an example to see how High DPI works in Windows.

Default DPI

This is the app running at 96 DPI (100%). It's the default mode, when scaling isn't necessary.

cpicksniff defaultdpi.png

Windows DPI Scaling

This is the same app running at 144 DPI (150%) without a manifest, so Windows scales it like a bitmap. The result is a blurred image.

cpicksniff blured.png

With Manifest

Running at 144 DPI (150%). This time the app includes a manifest but the application contains no code to handle scaling. Items aren't scaled whereas fonts are scaled (Windows does this automatically), so text is clipped.

cpicksniff nohighdpi.png

High DPI

Finally with both a manifest and a LCL scaling, the app is in High DPI.

cpicksniff highdpi.png

High DPI in Lazarus 1.8 and above

To handle High DPI using new features in 1.8, follow these steps:

  • On Windows: enable DPI awareness in Project Options -> Application. Decide if you want to support per monitor DPI awareness or not.
  • Enable LCL scaling for your application DPI awareness in Project Options -> Application -> "Use LCL scaling (Hi-DPI).
  • Set TForm.Scaled=True for all your forms (it is the default value). All WYSIWYG should work automatically. Also the designer scales the forms accordingly.
  • If you create controls run-time, scale all coordinates, sizes etc that have to be DPI-aware with TControl.Scale96ToForm() or ScaleDesignToForm() (depending on your choice of default PPI) or prepare your container (e.g. panel with controls) as it was with 96 PPI and then call TControl.AutoAdjustLayout(lapAutoAdjustForDPI, 96, ParentFormOfTheContainer.PixelsPerInch, 0, 0);
  • If some of your components don't scale their inner sizes, override DoAutoAdjustLayout and scale the sizes (see TToolBar) - it has to be done for all controls. If a LCL control misses DoAutoAdjustLayout please report to mantis and provide a patch if you can.

Lazarus IDE high DPI

The Lazarus IDE is DPI-aware itself.

High DPI in older Lazarus

Is not as nice as 1.8 but it works, call on each form OnCreate event:

Self.AutoAdjustLayout(lapAutoAdjustForDPI, 96, Screen.PixelsPerInch, Self.Width, ScaleX(Self.Width, 96));

External Links