supporting_20different_20dpi_20values
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
supporting_20different_20dpi_20values [2018/03/31 13:19] – external edit 127.0.0.1 | supporting_20different_20dpi_20values [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Supporting different DPI values===== | =====Supporting different DPI values===== | ||
- | //by Richard Russell, July 2006//\\ \\ Windows assumes, for certain operations (particularly displaying text), a specific **dots per inch** (or **pixels per inch**) value for the current display. The most common value used is 96 dots per inch (dpi), but other values, for example 120 dpi, will be encountered. A user can choose the higher value in **Display Properties... Settings** (in some versions of Windows by selecting **Large Fonts** and in others by selecting the DPI value directly).\\ \\ The table below shows the screen sizes (in inches, diagonal) which correspond to some common display resolutions at 96 dpi, 120 dpi and 144 dpi:\\ \\ | + | //by Richard Russell, July 2006//\\ \\ Windows assumes, for certain operations (particularly displaying text), a specific **dots per inch** (or **pixels per inch**) value for the current display. The most common value used is 96 dots per inch (dpi), but other values, for example 120 dpi, will be encountered. A user can choose the higher value in **Display Properties... Settings** (in some versions of Windows by selecting **Large Fonts** and in others by selecting the DPI value directly).\\ \\ The table below shows the screen sizes (in inches, diagonal) which correspond to some common display resolutions at 96 dpi, 120 dpi and 144 dpi: |
- | | Display resolution\\ | + | ^ Display resolution\\ |
| 800 x 600\\ | 10.4" | | 800 x 600\\ | 10.4" | ||
| 1024 x 768\\ | 13.3" | | 1024 x 768\\ | 13.3" | ||
Line 10: | Line 10: | ||
| 1400 x 1050\\ | 18.2" | | 1400 x 1050\\ | 18.2" | ||
| 1600 x 1200\\ | 20.8" | | 1600 x 1200\\ | 20.8" | ||
- | \\ | + | |
+ | So for example if you have a 15" diagonal screen, Windows would display text at approximately the intended size either by selecting 1152 x 864 at 96 dpi or 1400 x 1050 at 120 dpi. Of course if you have a flat panel screen there is likely to be only one display resolution at which it will give good results, giving you little choice over the DPI value. This is one reason why the 120 dpi setting is becoming more common.\\ \\ Since Windows displays text approximately 25% larger (in pixels) at 120dpi than at 96dpi you may well have to take the variation in text size into account when writing your programs. Listed below are some of the possible consequences for your programs of supporting different DPI values: | ||
==== Use of *FONT ==== | ==== Use of *FONT ==== | ||
- | \\ | + | |
+ | The good news is that if your program doesn' | ||
- Choose a size for your text that will look OK, and fit in the space available, at both 96dpi and 120dpi. This is the simplest solution, but will probably involve the text appearing slightly smaller than you would prefer at 96 dpi and slightly larger at 120 dpi. | - Choose a size for your text that will look OK, and fit in the space available, at both 96dpi and 120dpi. This is the simplest solution, but will probably involve the text appearing slightly smaller than you would prefer at 96 dpi and slightly larger at 120 dpi. | ||
Line 18: | Line 21: | ||
- Use the approach described in [[/ | - Use the approach described in [[/ | ||
- Adjust the size of your window and any graphics you draw (e.g. boxes containing text) to take account of the different text size. This is the most complicated solution, but is arguably the best one because it results in your program' | - Adjust the size of your window and any graphics you draw (e.g. boxes containing text) to take account of the different text size. This is the most complicated solution, but is arguably the best one because it results in your program' | ||
- | \\ | + | |
+ | You can discover the current DPI value, from which you can deduce the text size, as follows: | ||
+ | |||
+ | <code bb4w> | ||
SYS " | SYS " | ||
- | In all cases it is most important that any calculations involving text dimensions (for example calculations to ensure text is correctly centered) discover the actual height and width of the characters rather than assuming constant values. For a fixed-pitch font you can use the system variables **@vdu%!216** and **@vdu%!220** to find the width and height of a character in pixels; for a proportional-spaced font you will need to use **"SYS " | + | </ |
+ | |||
+ | In all cases it is most important that any calculations involving text dimensions (for example calculations to ensure text is correctly centered) discover the actual height and width of the characters rather than assuming constant values. For a fixed-pitch font you can use the system variables **@vdu%!216** and **@vdu%!220** to find the width and height of a character in pixels; for a proportional-spaced font you will need to use **"SYS " | ||
==== Window components ==== | ==== Window components ==== | ||
- | \\ | + | |
+ | Those components of the normal window ' | ||
* Since the text (in the title bar, menu bar or status bar) is displayed larger at 120 dpi than at 96 dpi, fewer characters may fit in the available width. Therefore you should check that any menu names, messages displayed in the status bar etc. are still entirely visible at 120 dpi. | * Since the text (in the title bar, menu bar or status bar) is displayed larger at 120 dpi than at 96 dpi, fewer characters may fit in the available width. Therefore you should check that any menu names, messages displayed in the status bar etc. are still entirely visible at 120 dpi. | ||
- | \\ | ||
* Since the height of the title bar, menu bar and/or status bar may change, you should never assume constant values for them in calculating the window size, graphics origin etc.(in any case they may also change between different Windows ' | * Since the height of the title bar, menu bar and/or status bar may change, you should never assume constant values for them in calculating the window size, graphics origin etc.(in any case they may also change between different Windows ' | ||
- | \\ | + | |
+ | The code below will resize your window to give a particular //client// size in pixels (i.e. the area in which your program' | ||
+ | |||
+ | <code bb4w> | ||
GWL_STYLE = -16 | GWL_STYLE = -16 | ||
DIM rc{l%, | DIM rc{l%, | ||
Line 45: | Line 57: | ||
VDU 26 | VDU 26 | ||
ORIGIN 0, | ORIGIN 0, | ||
- | Here **hs%** is the value returned from **" | + | </ |
+ | |||
+ | Here **hs%** is the value returned from **" | ||
==== Dialogue boxes ==== | ==== Dialogue boxes ==== | ||
- | \\ | + | |
+ | In Windows, the dimensions of dialogue boxes and the controls they contain are specified in //dialogue box units// rather than pixels. These are related to the size of the font used in the dialogue box, and hence also to the DPI setting. The result is that the dialogue box itself, all the controls it contains and the text displayed within those controls will all be approximately 25% larger at 120dpi than at 96dpi.\\ \\ Often this won't matter too much, because the text and the box(s) containing it are both scaled. However you should never assume the text will occupy a precise amount of space, or be formatted in a particular way, because of slight differences in the way the scaling is carried out.\\ \\ Where it will matter is if you use, for example, a **static box** to display a bitmap image. An image that is the correct size to fit neatly within the box at 96dpi will be too small at 120 dpi. The simplest solution is not to worry, because the effect is generally only cosmetic, but if it matters you will need to scale your bitmap image to the required size (or provide different images for the different DPI settings).\\ \\ You can convert the dimensions of a dialogue box (or a control contained therein) from dialogue box units to pixels as follows: | ||
+ | |||
+ | <code bb4w> | ||
DIM rc{l%, | DIM rc{l%, | ||
rc.l% = 0 | rc.l% = 0 | ||
Line 56: | Line 74: | ||
pixx% = rc.r%-rc.l% | pixx% = rc.r%-rc.l% | ||
pixy% = rc.b%-rc.t% | pixy% = rc.b%-rc.t% | ||
+ | </ | ||
+ | |||
Here **dlgx%** and **dlgy%** are the width and height in dialogue box units, **pixx%** and **pixy%** are the calculated width and height in pixels, and **dlg%** is the value returned from **" | Here **dlgx%** and **dlgy%** are the width and height in dialogue box units, **pixx%** and **pixy%** are the calculated width and height in pixels, and **dlg%** is the value returned from **" |
supporting_20different_20dpi_20values.1522502385.txt.gz · Last modified: 2024/01/05 00:16 (external edit)