View Issue Details

IDProjectCategoryView StatusLast Update
0033990LazarusWidgetsetpublic2019-10-04 16:50
ReportercobataAssigned ToDmitry Boyarintsev 
PrioritynormalSeverityminorReproducibilityalways
Status assignedResolutionopen 
Platformcocoa32/64OSmacOSOS Version10.13.5
Product Version1.9 (SVN)Product Build58509 
Target VersionFixed in Version 
Summary0033990: Difference between Cocoa and Carbon DPI, or Font size, or Line height...?
DescriptionPorting from Carbon to Cocoa...
Exists some difference between Cocoa and Carbon DPI, or Font size, or Line height...? It is more obvious on forms with more components and/ or TLabels with multiline text, for example.
The attached zip contains the project and sources.
Steps To ReproduceSee above.
Just open and build the project for Carbon on Lazarus 1.8.4 and for Cocoa on Lazarus Trunk 1.9.0 and run them.

Because the forms contain just 2 components, run the Carbon and Cocoa apps and place their main forms one over the other and switch continuously between the apps by clicking on their icons (to catch the differences).
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetCocoa
Attached Files

Activities

cobata

2018-07-14 19:55

reporter  

test.zip (130,229 bytes)

cobata

2018-07-18 17:01

reporter   ~0109562

Guys,

I read 0031037, which actually I found:
https://forum.lazarus.freepascal.org/index.php/topic,34896.0.html

Thanks to Alextp and the other devs...

I am doing cross-platform software: Vista_32/Delphi->Vista_32/Lazarus->Win10_64/Lazarus->macOS_Carbon (and NOW macOS_Cocoa)...

Actually, (till NOW) I solved the issue for my software, with the following code for the main form:
{$IFDEF FPC}
  ScreenInfo.PixelsPerInchX:=96;
  ScreenInfo.PixelsPerInchY:=96;
{$ENDIF}

But NOW I found the reported difference, which is not too big, but I found it and please, do not rely on this -> there is something.

I built my software with and without the solution above, but I found no change.

1. Can I continue use my solution after your intervention?
2. Do you have idea what causes this difference?
3. Do you know some workaround?

Best Regards,

Chris Rorden

2018-07-19 16:17

reporter   ~0109571

With Cocoa, some native widgets are drawn at a specific size, so a TButton will have a fixed height on Cocoa regardless of what height or scaling you request. The benefit of this approach is you are using the native widgets, and these widgets appear identical to other native Mac applications (style consistency). If this is unacceptable, you may want to choose a themed widget (like tspeedbutton) instead: this may make your applications appear more similar between Linux/Windows/Mac at the cost of looking alien in MacOS.

The Font size difference between Cocoa and Carbon is described here
  http://wiki.lazarus.freepascal.org/Cocoa_Internals/Canvas
A good resource is here
  http://wiki.lazarus.freepascal.org/Cocoa_Internals/Buttons

For a cross-platform project, you may want to examine your auto-size anchor options
 http://wiki.freepascal.org/Anchor_Sides
 http://wiki.freepascal.org/Autosize_/_Layout

cobata

2018-07-22 11:56

reporter   ~0109629

With this set, on both Carbon and Cocoa:
{$IFDEF FPC}
  ScreenInfo.PixelsPerInchX:=96;
  ScreenInfo.PixelsPerInchY:=96;
{$ENDIF}
On Carbon the Font Size is 12, but on Cocoa the Font Size is 16 - looking in the Font dialogs.
As I already said the Fonts look nearly the same, but they are not (12 vs 16). You can reset the Font Sizes to be equal (to 12), but then the visual difference is big.

When remove the condition on Cocoa:
{$IFDEF FPC}
  //ScreenInfo.PixelsPerInchX:=96;
  //ScreenInfo.PixelsPerInchY:=96;
{$ENDIF}
The observations are the same.

cobata

2018-08-04 10:03

reporter   ~0109873

Is the last provided info useful?
Do you plan to fix this?

cobata

2019-07-18 09:58

reporter   ~0117299

Guys,

Again, on this issue... The problem is not in Carbon as you describe in the documentation (above), or we talk for different/ more problems. I think that because, as I already said: I found the DPI problem (above) and I do intensive cross-platform development and in CARBON the things behave more like in Windows (ws)... The issue appears on COCOA mainly when on assigning Font (or Font properties) and for the same thing (for example a TLabel component) the input differs from the output: the read Font.size value differs from the written one. This does not appear for Carbon.

Please, take attention on this.
I do not know where is exactly the problem in Cocoa ws in Lazarus or Cocoa macOS.

Best Regards

cobata

2019-07-18 10:50

reporter   ~0117300

Last edited: 2019-07-18 12:05

View 3 revisions

Addition: the diff between the read and the write Font.size value (ex.: TLabel) appears after reading the value in the Font dialog/ after open the Font dialog in runtime (ex.: for TLabel) (and it appears with sign "-" if you print it).

Dmitry Boyarintsev

2019-07-19 15:48

developer  

forms.png (26,465 bytes)
forms.png (26,465 bytes)

Dmitry Boyarintsev

2019-07-19 16:31

developer   ~0117317

I've attached a screenshot from Cocoa, Carbon and Windows.
Could you please explain in details - your concern.

Cocoa and Carbon look alike to me. Yes, the "font" for label is different (but this is due to different APIs used to get "system default" font)

macOS systems vs Windows look different, is likely due to different DPI (96) (PPI 72) used.

cobata

2019-07-20 04:57

reporter   ~0117325

Last edited: 2019-07-20 05:13

View 2 revisions

Hi, Dmitry,

Thank you for your attention.
The difference in Font representation is small and as I already described above is not the problem.
The problem is that for the same component TLabel with Font.size = 12 (pt) on Carbon Font dialog opened for the TLabel to get/set shows size 12, but on Cocoa - 16 and when you try to set it to 12 the difference is big - its as first.
The second is that in case that you just open a Font dialog for a TLabel, just to get/ see the size value, but even do not try to set it and next to print the Font.size for that TLabel the printed value is with sign minus, which is not correct - and this is on Cocoa only.

Those are my concerns: I extensively work with the Font dialog to read/get and write/set the Font.size values and to write and read them to/from a file.

Thank you, Dmitry,
Best Regards

Dmitry Boyarintsev

2019-07-21 04:45

developer   ~0117332

if Font dialog is the issue, then it certainty can be be.

could you please provide an example?
preferably with screen shots, indicating the difference between Carbon and Cocoa.

cobata

2019-07-21 09:48

reporter   ~0117333

Today I will prepare an example...
I thought the same that the problem is in the Font dialog, but that I saw in the code, it just uses Font.Assign() for the SET and in Font (classes hierarchy) the .size and the .height props are set with formula, taking in account the DPIs, from where the sign MINUS appears for the .size (I am not compared the diffs between Carbon Font (classes) and Cocoa Font (classes), but it is like the .height value is assigning to the .size OR vice versa, or the DPI params are swapped...

cobata

2019-07-21 16:12

reporter  

bug.zip (2,064 bytes)

cobata

2019-07-21 16:12

reporter  

1.png (210,791 bytes)
1.png (210,791 bytes)

cobata

2019-07-21 16:13

reporter  

2.png (221,731 bytes)
2.png (221,731 bytes)

cobata

2019-07-21 16:17

reporter   ~0117338

See the attachments on Cocoa: On Carbon (compiled on Laz 1.8.4) FontDialog get/ set the correct values.

cobata

2019-10-04 11:54

reporter   ~0118316

Dmitry, do you need additional info?

Issue History

Date Modified Username Field Change
2018-07-14 19:55 cobata New Issue
2018-07-14 19:55 cobata File Added: test.zip
2018-07-18 17:01 cobata Note Added: 0109562
2018-07-19 16:17 Chris Rorden Note Added: 0109571
2018-07-22 11:56 cobata Note Added: 0109629
2018-08-04 10:03 cobata Note Added: 0109873
2019-07-18 09:58 cobata Note Added: 0117299
2019-07-18 10:50 cobata Note Added: 0117300
2019-07-18 11:08 cobata Note Edited: 0117300 View Revisions
2019-07-18 12:05 cobata Note Edited: 0117300 View Revisions
2019-07-19 15:48 Dmitry Boyarintsev File Added: forms.png
2019-07-19 16:31 Dmitry Boyarintsev Note Added: 0117317
2019-07-20 04:57 cobata Note Added: 0117325
2019-07-20 05:13 cobata Note Edited: 0117325 View Revisions
2019-07-21 04:45 Dmitry Boyarintsev Note Added: 0117332
2019-07-21 04:45 Dmitry Boyarintsev Assigned To => Dmitry Boyarintsev
2019-07-21 04:45 Dmitry Boyarintsev Status new => feedback
2019-07-21 04:45 Dmitry Boyarintsev LazTarget => -
2019-07-21 09:48 cobata Note Added: 0117333
2019-07-21 09:48 cobata Status feedback => assigned
2019-07-21 16:12 cobata File Added: bug.zip
2019-07-21 16:12 cobata File Added: 1.png
2019-07-21 16:13 cobata File Added: 2.png
2019-07-21 16:17 cobata Note Added: 0117338
2019-10-04 11:54 cobata Note Added: 0118316