Lazarus

Programming => LCL => Topic started by: Slyde on December 09, 2020, 02:44:05 am

Title: [SOLVED] TLabel height
Post by: Slyde on December 09, 2020, 02:44:05 am
For readability, I bumped up the TLabel font size to 11.  Then I saw it was chopping the legs off characters, so I tried to increase the Label height.  But it isn't letting me do that.   The only way it lets me increase the Label height is to increase the font size again.  Not what I'm looking for. 

How can I keep my font size at 11 and increase the Label height?

Here is what it does to y g p
Title: Re: TLabel height
Post by: jamie on December 09, 2020, 02:51:13 am
Turn the autosize off
Title: Re: TLabel height
Post by: Slyde on December 09, 2020, 02:57:07 am
I feel like crawling under a rock.  Thank you, jamie.
Title: Re: [SOLVED] TLabel height
Post by: dbannon on December 09, 2020, 06:04:14 am
The trouble with auto size being off is you had better make sure what ever is going in there, fits.  So, if you write some new text in there during the execution of the programme or, perhaps have it translated to another language. And there are a people out there with poor eyesight who set their default fonts larger.

With autosize on, that clipping should not happen. I have seen this problem somewhere else on my own app and its also reported here https://forum.lazarus.freepascal.org/index.php/topic,52450.msg386611

Me thinks its a bug ....

We need to be able to demonstrate it reliably and log it.
 
Davo
Title: Re: [SOLVED] TLabel height
Post by: Slyde on December 09, 2020, 06:36:47 am
@dbannon - IMHO, autosize should work for the width only, not the height.  Autosize should only be concerned about the string's width.  Nothing else.  I want to be able to set the height, if necessary, to accommodate the font size.  And pass that ability on to the end-user so they can handle the height too if they need large fonts.

Anyway,  I'll have to make do with what I have. 

Thanks for the input.
Title: Re: [SOLVED] TLabel height
Post by: wp on December 09, 2020, 10:06:27 am
Setting AutoSize = false is like driving a car with the eyes shut! Don't do this. Autosizing and anchoring are the most efficient ways to create forms with self-adjusting layouts.

Your wish to autosize only the width, but not the height of a label causes lots of trouble with the Caption is word-wrapped.

When label AutoSize does not work as expected you should give more details: what is your OS? Widgetset? Lazarus and FPC versioms? Which font is showing the issue?

Did you try a TStaticText instead of TLabel? Does it show the same issue?
Title: Re: [SOLVED] TLabel height
Post by: Slyde on December 09, 2020, 09:32:54 pm
OS: Cinnamon 20
Lazarus 2.0.10
Widgetset: standard Lazarus compliment
FPC 3.2.0
Font: Defalt (Sans on my machine)
Font size used: 11
Autosize: true
Wordwrap: false

TStaticText works though.  So all's well that ends well  ;)



Title: Re: [SOLVED] TLabel height
Post by: winni on December 09, 2020, 09:47:59 pm
Hi!

This is a Lazarus bug since ages in Linux.

I don't know about Windows.

The only solution is like you said: Turn of autosize.
As I disable autosize for all components it does not hurt me much.

Really bad it gets with UTF8 symbols where the lower third (or so) is cut off. Try

⨀ ⨌ ⟁ ∫

Autosize also does not react on changing from  font.style := [] to font.style := [fsbold].
The last letter is partly cut off in x direction.

Avoid autosize and you avoid a lot of trouble.

Winni
 
Title: Re: [SOLVED] TLabel height
Post by: Slyde on December 09, 2020, 09:56:23 pm
@winni - agreed.  However, the TStaticText works for me.  Just have to remember to turn on autosizing as it rolls out turned off.  It even changes height based on the font size chosen.  No need for TLabel at all.
Title: Re: [SOLVED] TLabel height
Post by: lucamar on December 09, 2020, 10:28:25 pm
Note, though, that TStaticText wastes more resources than TLabel; not so many more that it always matters, but if you have a lot of them ...
Title: Re: [SOLVED] TLabel height
Post by: winni on December 09, 2020, 11:23:41 pm
Hi!

If you want to reduce ressources:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormPaint(Sender: TObject);
  2. begin
  3.    self.Canvas.TextOut(10,10,'I am the great pretender of Label42');
  4.    self.Canvas.TextOut(30,30,'I am the great pretender of StaticText23');
  5. end;


Winni
Title: Re: [SOLVED] TLabel height
Post by: jamie on December 09, 2020, 11:41:40 pm
does anyone ever use the BorderSpacing properties ?
Title: Re: [SOLVED] TLabel height
Post by: wp on December 09, 2020, 11:49:27 pm
Always. If you link controls by using the Anchor Editor you can define the spacing between them with the BorderSpacing. I am rather sure that it can help with clipping the label because this is due to incorrect consideration of font metrics.
Title: Re: [SOLVED] TLabel height
Post by: lucamar on December 09, 2020, 11:53:26 pm
does anyone ever use the BorderSpacing properties ?

Yes; I myself use them in almost all programs. Handy little buggers :)
Title: Re: [SOLVED] TLabel height
Post by: winni on December 10, 2020, 12:23:12 am
Always. If you link controls by using the Anchor Editor you can define the spacing between them with the BorderSpacing. I am rather sure that it can help with clipping the label because this is due to incorrect consideration of font metrics.

The answer is quiete easy:

Create a new project.

The only component you need is a label.

Resizie your form to 1000 x 1000
Put the label in the center.

Add for the label.caption :

⨀ ⨌ ⟁ ∫

Sit back in amazement and enjoy how the glyphs are cut of.

That was the end of the BorderSpacing theory.

Winni

Title: Re: [SOLVED] TLabel height
Post by: jamie on December 10, 2020, 12:58:55 am
Always. If you link controls by using the Anchor Editor you can define the spacing between them with the BorderSpacing. I am rather sure that it can help with clipping the label because this is due to incorrect consideration of font metrics.

Well three is a InnerBorder property that I don't see in the Anchor editor unless I missed something and it does not seem to have any effects..
Title: Re: [SOLVED] TLabel height
Post by: jamie on December 10, 2020, 01:06:24 am
Hmm, I don't see any of that cutoff over here.. all content is showing property with large text and glyphs .

I run my screen at 96DPI maybe that has something to do with it ?
Title: Re: [SOLVED] TLabel height
Post by: winni on December 10, 2020, 01:44:35 am
Hi!

96 dpi, KDE Plasma, gtk2, Suse Tumbleweed.


See cut off in attachment.
But I know this Lazarus Bug on Linux since  ~ 15 years.

Winni
Title: Re: [SOLVED] TLabel height
Post by: jamie on December 10, 2020, 01:49:45 am
I don't get that. Looks normal to me..

I'll try some different chars in there.
Title: Re: [SOLVED] TLabel height
Post by: jamie on December 10, 2020, 02:10:45 am
Well there you go, you are on Linux. I keep telling everyone that windows is superior but they keep throwing stuff at me, mainly their notes with all the Linux bugs written on them. I've gotten hit, a lot ! but they still have plenty more buggy notes to throw at me so I stay clear now. ;)
Title: Re: [SOLVED] TLabel height
Post by: bd4kc on December 11, 2020, 11:13:01 am
property Layout;
property OptimalFill;
property Font.size;
property AutoSize;

These property are related to each other, and I often worry about designing a label precisely. Adjust here and there many times. optimalfill and Layout there propertys can be tried more, autosize will also change itself, when you set other properties.
Title: Re: [SOLVED] TLabel height
Post by: wp on December 11, 2020, 11:58:34 am
This screenshot is taken off of LMDE4 Cinnamon, 64 bit, gtk2, MintY Dark. --> correct display, nothing cut off.

I would not say that the incorrect text height determination is a Lazarus bug. Lazarus cannot fix the inconsistencies of the widgetsets and their dependence on dozens of themes.

The problem with Linux compared to Windows is that it is so heterogeneous (I do agree that there are also problems of the Windows side -- so please, don't start a flame war here).
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 12:05:16 am
Hi!

No flamewars but let's get the reason for this cut off .

As I said: I know this error since ~ 15 years.
My Linux Desktop System in all the years was always Suse.
Desktop was always KDE on gtkX.
When KDE had such nice features like a wooden roof on top of the windows  .....

My Lazarus packages  where sometimes from Suse.
But also from the fpc/Lazarus homepage. That differs.

On the other side you tell me with Cinnamon everything is ok.

Question 1: Is this a "Suse only bug" ?  Therefore we need more Infos from other Linux distros.

And if this is true then Question 2: How does Suse manage to cut off the label?
A little troll  with scissors inside? 
I got really no idea but joking.

Questions - nothing but questions.

Winni
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 03:56:27 pm
Hi!

I keep on going on the search of the "magical" bug:

Just tested the behaviour on the comination Debian/KDE:

No problems with label and autosize. Nothing cut off.
At default setting (default font, 10 pt) the height of the label is 19 pixel
Screen  solution is 96 dpi.

Oppsite to Suse/KDE

The label does not set the correct height with autosize.
The lower part of large Letters and UTF8 Symbols is cut of.
At default setting (default font, 10 pt) the height of the label is 13 pixel
Screen  solution is 96 dpi.

As in both cases KDE / gtk2 are used this is not a KDE error.

Where do I find the bug???

Winni

Title: Re: [SOLVED] TLabel height
Post by: lucamar on December 12, 2020, 04:25:48 pm
Where do I find the bug???

Look for differences in the installed libraries (versión, etc.). Since it works in Debian/KDE, it's obvious that something in Suse is working differently.

Note also that some KDE themes/composers can't deal gracefully with GTK applications unless a "suplement" for GTK is added, usually in a package with a name like, say, "oxygene-gtk".
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 04:51:04 pm
Thanx Lucamar

I will have a look if there are different libs

As I thinks that themes are a waste of developer time, cpu time and ressources I never use them resp. throw them out.  If I want to look at beauty I don't look at the screen. I look at women. Yes - they exist. But not in this forum.

As I know this bug since ~15 years it must be a long term incorrect use of some libs.


Winni
Title: Re: [SOLVED] TLabel height
Post by: jamie on December 12, 2020, 05:22:11 pm

As I thinks that themes are a waste of developer time, cpu time and ressources I never use them resp. throw them out.  If I want to look at beauty I don't look at the screen. I look at women. Yes - they exist. But not in this forum.

Winni

What makes you think women don't exists here ? Haven't you seen girl coders with long hair, mustache and beard ?

Putting that off the side, there are woman here but I can't say if they have grown any facial hairs !  :D
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 05:28:28 pm

Bug report:

https://bugs.freepascal.org/view.php?id=38211 (https://bugs.freepascal.org/view.php?id=38211)
Title: Re: [SOLVED] TLabel height
Post by: Bart on December 12, 2020, 05:41:32 pm
Long time ago, I was on Suse 10.0.
I cannot recall that I ever saw this problem.

Bart
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 12, 2020, 06:04:26 pm

Bug report:

https://bugs.freepascal.org/view.php?id=38211 (https://bugs.freepascal.org/view.php?id=38211)

Not Suse only. I have also seen this bug on Fedora 32 LXQt.
And on Debian 10 (Xfce, gtk2) with font size 10 all OK, but with font size 9 you can also notice this bug, but not as big, as yours on Suse (left label is AutoSized, right is not, hope the difference is noticeable):
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 07:28:50 pm

Bug report:

https://bugs.freepascal.org/view.php?id=38211 (https://bugs.freepascal.org/view.php?id=38211)

Not Suse only. I have also seen this bug on Fedora 32 LXQt.
And on Debian 10 (Xfce, gtk2) with font size 10 all OK, but with font size 9 you can also notice this bug, but not as big, as yours on Suse (left label is AutoSized, right is not, hope the difference is noticeable):

Thanx.

Added your infos to the bug report.

Winni
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 12, 2020, 08:16:52 pm
I played with TLabel's font sizes just for fun, and it seems that TLabel's AutoSize works correctly only for font size 10 (Debian 10 64 bit, Xfce, system font size 9, DPI 96, fpc 3.2.0, Lazarus 2.0.10 gtk2):
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 12, 2020, 09:18:04 pm
Something more: triangle is the evil!
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 12, 2020, 09:25:36 pm
And at last: change system font from DejaVu Sans to Noto Sans. Works fine also with Nimbus Sans and does not work with Liberation Sans.
Is it really Lazarus bug? It looks like bug in some fonts...
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 09:47:14 pm
Hi!

" Triangle is the evil! "

You should sell that as storyboard to Sesame Street ....

Anyway:

This is the "triangle":

U+27C1

E29F81
14851969
⟁
WHITE TRIANGLE CONTAINING SMALL WHITE TRIANGLE

* Not all UTF8 glyphs are implemeted in all fonts.
As this is still work in  progress it seems to be useless t make a table which code block is implemented in which font. There are a lot waiting to be implemented.
* There are still bugs with UTF8 in Lazarus with some kind of glyphs.
Especially with zero width combining marks.

So:

We work on three different kinds of error:
*  the faulty implementation of TLabel.autosize
* the last hooks of the faulty implementation of the printing of UTF8-Glyphs
* the not complete implementation of the glyphs in some fonts.

Winni
Title: Re: [SOLVED] TLabel height
Post by: lucamar on December 12, 2020, 10:02:53 pm
In Linux, at least, if a font doesn't implement a specific glyph and the system has a fallback one that implements it, it will silently replace one with the other, but the metrics will be taken from the original font and they might or might not be valid for the replaced glyph.

This might be what is happening here. IIRC there are API calls in the font renderer o check for this situation, but I'm no expert at this, sorry ...
Title: Re: [SOLVED] TLabel height
Post by: winni on December 12, 2020, 10:03:07 pm
  and does not work with Liberation Sans

Hi

You've got an old version of Liberation.
There is a new one around with UTF8 glyphs.

https://github.com/liberationfonts/liberation-fonts (https://github.com/liberationfonts/liberation-fonts)

Winni
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 12, 2020, 11:48:09 pm
Thanks for the explanations. So in this case the problem is lack of glyphs in particular font.
But this is not the case of the very first post, where the problem was with latin letters. And I cannot reproduce it on Debian, but I saw it at Fedora. It seems that these are different problems.
Title: Re: [SOLVED] TLabel height
Post by: JuhaManninen on December 13, 2020, 06:35:05 pm
Have you people tested with QT5 bindings on the problematic systems. Usually it works better with KDE which is also built using QT.
Title: Re: [SOLVED] TLabel height
Post by: tetrastes on December 14, 2020, 08:42:37 am
But this is not only KDE issue:

OS: Cinnamon 20
Lazarus 2.0.10
Widgetset: standard Lazarus compliment
FPC 3.2.0
Font: Defalt (Sans on my machine)
Font size used: 11
Autosize: true
Wordwrap: false

TStaticText works though.  So all's well that ends well  ;)
Title: Re: [SOLVED] TLabel height
Post by: andyH on May 15, 2021, 02:21:27 pm
Maybe a few months late to this, but I got fed up with chopped descenders and couldn't find a solution. So I did my own. You set the caption with TLabelGTK.setCaption('My Caption') rather than TLabelGTK.Caption:= 'My Caption'.

Not tested with different font sizes, in the application I'm developing think my default is Ubuntu 10 (running LM20.1 cinnamon).
Code: Pascal  [Select][+][-]
  1. {-------------------------------------------------------------------------------
  2. UNIT - GTKLABEL
  3.  
  4. This unit fixes a bug in the standard TLabel. See:
  5. https://forum.lazarus.freepascal.org/index.php?topic=53544.msg396318#msg396318
  6.  
  7. With a standard TLabel, when autosize = true (the default), descenders in the
  8. caption get chopped. It is a reported bug, not fixed as of Mar 2021.
  9.  
  10. Autosizing labels are required as label captions will change, dependent on function and
  11. language.
  12.  
  13. GTKLabel defines a TLabeLGTK that will autosize on caption change WITHOUT chopping the descenders.
  14.  
  15. V1.0 - 03 Mar 2021
  16. -------------------------------------------------------------------------------}
  17. unit GTKlabel;
  18.  
  19. {$mode objfpc}{$H+}
  20.  
  21. interface
  22.  
  23. uses
  24.   Classes, SysUtils, StdCtrls, Graphics;
  25.  
  26. type
  27.   TLabelGTK = class(TLabel)
  28.     const
  29.       hAdd = 2; //add to text height of caption
  30.       wAdd = 10; //add to text width of caption
  31.     private
  32.       procedure setWidth;
  33.       procedure setHeight;
  34.     public
  35.       constructor Create(TheOwner: TComponent);  override;
  36.       procedure setCaption(CaptionStr : string);
  37.   end;
  38.  
  39. implementation
  40. {-------------------------------------------------------------------------------
  41. TLABELGTK.CONSTRUCTOR
  42. Constructor that inherits the TLabel constructor and sets autosize = false and sets
  43. vertical alignment = centre.
  44.  
  45. V1.0 - 03 Mar 2021
  46. -------------------------------------------------------------------------------}
  47. constructor TLabelGTK.Create(TheOwner: TComponent);
  48. begin
  49.   inherited Create(TheOwner);
  50.   AutoSize:= false;
  51.   Layout:= tlCenter;
  52. end;
  53. {-------------------------------------------------------------------------------
  54. TLABELGTK.SETWIDTH (private)
  55. Calculates the width of a TLabel caption in pixels by writing it to a bitmap canvas and using the
  56. TextWidth function to determine width which is then written to the TLabel width.
  57.  
  58. The width of the label is increased by wAdd.
  59.  
  60. Used by: TLabelGTK.setCaption
  61.  
  62. V1.0 - 03 Mar 2021
  63. -------------------------------------------------------------------------------}
  64. procedure TLabelGTK.setWidth;
  65. var
  66.   bmp: TBitmap;
  67. begin
  68.   bmp := TBitmap.Create;
  69.   try
  70.     bmp.Canvas.Font.Assign(Font);
  71.     Width:= bmp.Canvas.TextWidth(Caption) + wAdd;
  72.   finally
  73.     bmp.Free;
  74.   end;
  75. end;
  76. {-------------------------------------------------------------------------------
  77. TLABELGTK.SETHEIGHT (private)
  78. Calculates the height of a TLabel caption in pixels by writing it to a bitmap canvas and using the
  79. TextHeight function to determine height which is then written to the TLabel height.
  80.  
  81. The height of the label is increased by hAdd.
  82.  
  83. Used by: TLabelGTK.setCaption
  84.  
  85. V1.0 - 03 Mar 2021
  86. -------------------------------------------------------------------------------}
  87. procedure TLabelGTK.setHeight;
  88. var
  89.   bmp: TBitmap;
  90. begin
  91.   bmp := TBitmap.Create;
  92.   try
  93.     bmp.Canvas.Font.Assign(Font);
  94.     Height:= bmp.Canvas.TextHeight(Caption) + hAdd;
  95.   finally
  96.     bmp.Free;
  97.   end;
  98. end;
  99. {-------------------------------------------------------------------------------
  100. TLABELGTK.SETCAPTION (public)
  101. Set the caption of a TLabelGTK. Use this to set/change a caption instead of MyLabel.Caption:= 'something'.
  102. Use MyLabel.setCaption('something').
  103.  
  104. Uses setWidth and setHeight to 'autosize' the caption.
  105.  
  106. Used by: general
  107.  
  108. V1.0 - 03 Mar 2021
  109. -------------------------------------------------------------------------------}
  110. procedure TLabelGTK.setCaption(CaptionStr : string);
  111. begin
  112.   Caption:= CaptionStr;
  113.   setWidth;
  114.   setHeight;
  115. end;
  116.  
  117. end.
  118.  
TinyPortal © 2005-2018