View Issue Details

IDProjectCategoryView StatusLast Update
0031276LazarusLCLpublic2017-09-19 23:12
Reporterbald zhangAssigned ToMichl 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformwin32OSwindowsOS Version10
Product Version1.7 (SVN)Product Buildtrunk 
Target Version1.8Fixed in Version1.9 (SVN) 
Summary0031276: Set Font.Size in FormCreate cause scaled twice
Descriptionmigration an exist project to 1.7
set DPI awareness to "on" in project options, *nothing* changed with unit/forms

when program execute on a 4k display(192dpi), the font was double sized to 18.

existing code has
  Font.Size := 9;
in FormCreate

do some tracking, the problem is
1) in TFont.SetFont
  FHeight := -MulDiv(AValue, FPixelsPerInch, 72);
  where FPixesPerInch is 192
  then FHeight = -24

2) in TCustomForm.DoAutoAdjustLayout
  Form's DesignTimePPI = 192, read from Screen, and PixelsPerInch = 96, the default value
  then another round of scaled performed, Font.Size changed to 18.

I try to do like this:
  Font.Height := 12; (simulate calculation: 9 * 96 / 72)
then the program looks ok.

as far as I know, lots of code was written like "Font.Size := ##", then this may confuse lots of people...
TagsNo tags attached.
Fixed in Revision54210, 54211, 55841, 55884
LazTarget1.8
Widgetset
Attached Files

Relationships

related to 0032359 confirmedMichl Themed drawing doesn't work for High-DPI scaled forms. 
related to 0031336 closedOndrej Pokorny High DPI: form scaled to 4 times of MinWidth, MinHeight 

Activities

bald zhang

2017-01-26 00:14

reporter  

bald zhang

2017-01-26 00:15

reporter  

fontsize.zip (130,092 bytes)

Ondrej Pokorny

2017-02-19 22:06

reporter   ~0098323

confirmed

bald zhang

2017-02-23 10:11

reporter   ~0098389

test passed at r54256.

bald zhang

2017-09-10 17:44

reporter   ~0102756

yesterday I check my project under linux/gtk2, found this issue appear again.
check under windows, yes, this one again.
is a regression I think.

font-size-ok: 96 DPI
font-size-bad: 192 DPI

proj96: project for 96 dpi; proj192: for 192.

will give more info under linux gtk2/qt5 this afternoon

bald zhang

2017-09-10 17:44

reporter  

font-size-ok.jpg (103,348 bytes)
font-size-ok.jpg (103,348 bytes)

bald zhang

2017-09-10 17:44

reporter  

font-size-bad.jpg (111,437 bytes)
font-size-bad.jpg (111,437 bytes)

bald zhang

2017-09-10 17:45

reporter  

fontsize2.zip (257,507 bytes)

bald zhang

2017-09-10 17:58

reporter  

font-size-gtk2-bad.jpg (67,050 bytes)
font-size-gtk2-bad.jpg (67,050 bytes)

bald zhang

2017-09-10 17:58

reporter  

font-size-qt5-bad.jpg (74,618 bytes)
font-size-qt5-bad.jpg (74,618 bytes)

bald zhang

2017-09-10 18:01

reporter   ~0102758

linux env:

slackware-current x86_64, fpc 3.0.2, lazarus fixes_1_8
4k display, xfce 4.12, dpi set to 192 manually

Ondrej Pokorny

2017-09-10 22:23

reporter   ~0102764

Please bisect the guilty revision. Thanks.

bald zhang

2017-09-11 02:08

reporter   ~0102770

ok, I found it, caused by r55815.
tested under win32/gtk2/qt5, it's the same.

bald zhang

2017-09-11 02:17

reporter   ~0102771

btw, I tested change font.inc back to r55814, is not ok, so it related to control.inc change.

Michl

2017-09-11 22:00

developer   ~0102786

Fixed in Trunk revision 55841. Please test and close if ok.

bald zhang

2017-09-12 02:32

reporter   ~0102789

tested win32, the font is ok now, but the treeview's indent and buttons became half size. you may found it in any treeview of the ide.

should I close this anyway or wait for more fix ?

Ondrej Pokorny

2017-09-12 09:19

reporter   ~0102792

Michl, did you test multi-DPI-monitor setup? (Sorry, I didn't test now.)

+ The if-condition from r55841 has to be moved into DoFixDesignFontPPI. (If it's OK in multi-DPI.)

Michl

2017-09-12 10:26

developer   ~0102794

The commit was a workaround, that seemed to work. It breaks the returning of font height.
I'll remove it this evening and look for a better fix.

The per monitor DPI aware default font doesn't work at all. Imho we need a private variable for default font testing, not a test of Height <> 0.

bald zhang

2017-09-12 21:49

reporter   ~0102813

Last edited: 2017-09-13 05:08

View 2 revisions

in file: control.inc, method: TControl.DoScaleFontPPI()

> Font.PPI= 192, Scrn.PPI = 192, Proportion = 2.00, - Label2
   Font.PPI= 96, Scrn.PPI = 192, Proportion = 2.00, - Label3
> Font.PPI= 192, Scrn.PPI = 192, Proportion = 2.00, - Button2
   Font.PPI= 96, Scrn.PPI = 192, Proportion = 2.00, - Button3
> Font.PPI= 192, Scrn.PPI = 192, Proportion = 2.00, - CheckBox2
   Font.PPI= 96, Scrn.PPI = 192, Proportion = 2.00, - CheckBox3

this three controls, Font.PPI scaled again and become 384 ...

  PPI, SIZE, HEIGHT - NAME
  ----------------------------------
  192, 0, 0 - Form1
  192, 0, 0 - Label1
> 384, 9, -48 - Label2
  192, 9, -24 - Label3
  192, 0, 0 - Button1
> 384, 9, -48 - Button2
  192, 9, -24 - Button3
  192, 0, 0 - CheckBox1
> 384, 9, -48 - CheckBox2
  192, 9, -24 - CheckBox3
  192, 0, 0 - Memo1

tested with this code in the method before all other code:
  if AFont.PixelsPerInch = Screen.PixelsPerInch then
    Exit;

then the test project and my project are all ok. the treeview's indent is ok also.
I'm not sure this is the right solution, but I think the point is found.

only win32 under Windows 10 checked. will check gtk2/qt5 when I return home.

UPDATE:
gtk2/qt5 confirmed, it is same.

more detail:

step 1: in TControl.FixDesignFontsPPI
  {Label,Button,CheckBox}2: not touched, because Font.IsDefault = True
  so Font.PixelPerInch = 192

step 2: in FormCreate
  Font.Color changed, but remain Font.Height = 0

step 3: in TControl.DoScaleFontPPI
  because AFont.Height = 0 and AFont.IsDefault = False,
  then AFont.Height was scaled from 192 to 384.


my temporary code may not a *good* sulotion but a quirk fix,
another way, move FixDesignFontsPPI after FormCreate, is it ok ?

Michl

2017-09-19 22:06

developer   ~0102926

In Trunk revision 55884, I reverted revision 55761 as it breaks to much things.

bald zhang

2017-09-19 23:12

reporter   ~0102929

testing project and all my projects passed.

Issue History

Date Modified Username Field Change
2017-01-26 00:14 bald zhang New Issue
2017-01-26 00:14 bald zhang File Added: font.size scaled twice.PNG
2017-01-26 00:15 bald zhang File Added: fontsize.zip
2017-01-26 08:15 Ondrej Pokorny Assigned To => Ondrej Pokorny
2017-01-26 08:15 Ondrej Pokorny Status new => assigned
2017-02-19 22:06 Ondrej Pokorny LazTarget => 1.8
2017-02-19 22:06 Ondrej Pokorny Note Added: 0098323
2017-02-19 22:06 Ondrej Pokorny Target Version => 1.8
2017-02-20 14:59 Ondrej Pokorny Fixed in Revision => 54210
2017-02-20 14:59 Ondrej Pokorny Status assigned => resolved
2017-02-20 14:59 Ondrej Pokorny Resolution open => fixed
2017-02-20 16:05 Ondrej Pokorny Fixed in Revision 54210 => 54210, 54211
2017-02-23 10:11 bald zhang Note Added: 0098389
2017-02-23 10:11 bald zhang Status resolved => closed
2017-03-06 15:28 Juha Manninen Relationship added related to 0031336
2017-09-10 17:44 bald zhang Note Added: 0102756
2017-09-10 17:44 bald zhang Status closed => assigned
2017-09-10 17:44 bald zhang Resolution fixed => reopened
2017-09-10 17:44 bald zhang File Added: font-size-ok.jpg
2017-09-10 17:44 bald zhang File Added: font-size-bad.jpg
2017-09-10 17:45 bald zhang File Added: fontsize2.zip
2017-09-10 17:58 bald zhang File Added: font-size-gtk2-bad.jpg
2017-09-10 17:58 bald zhang File Added: font-size-qt5-bad.jpg
2017-09-10 18:01 bald zhang Note Added: 0102758
2017-09-10 22:23 Ondrej Pokorny Note Added: 0102764
2017-09-11 02:08 bald zhang Note Added: 0102770
2017-09-11 02:17 bald zhang Note Added: 0102771
2017-09-11 10:26 Michl Assigned To Ondrej Pokorny => Michl
2017-09-11 11:53 Michl Relationship added related to 0032359
2017-09-11 22:00 Michl Fixed in Revision 54210, 54211 => 54210, 54211, 55841
2017-09-11 22:00 Michl Note Added: 0102786
2017-09-11 22:00 Michl Status assigned => resolved
2017-09-11 22:00 Michl Fixed in Version => 1.9 (SVN)
2017-09-11 22:00 Michl Resolution reopened => fixed
2017-09-12 02:32 bald zhang Note Added: 0102789
2017-09-12 09:19 Ondrej Pokorny Note Added: 0102792
2017-09-12 10:26 Michl Note Added: 0102794
2017-09-12 10:26 Michl Status resolved => assigned
2017-09-12 10:26 Michl Resolution fixed => reopened
2017-09-12 21:49 bald zhang Note Added: 0102813
2017-09-13 05:08 bald zhang Note Edited: 0102813 View Revisions
2017-09-19 22:06 Michl Note Added: 0102926
2017-09-19 22:06 Michl Fixed in Revision 54210, 54211, 55841 => 54210, 54211, 55841, 55884
2017-09-19 22:06 Michl Status assigned => resolved
2017-09-19 22:06 Michl Resolution reopened => fixed
2017-09-19 23:12 bald zhang Note Added: 0102929
2017-09-19 23:12 bald zhang Status resolved => closed