Recent

Author Topic: [SOLVED] TLabel height  (Read 5382 times)

winni

  • Hero Member
  • *****
  • Posts: 2500
Re: [SOLVED] TLabel height
« Reply #30 on: December 12, 2020, 07:28:50 pm »

Bug report:

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

tetrastes

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] TLabel height
« Reply #31 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):

tetrastes

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] TLabel height
« Reply #32 on: December 12, 2020, 09:18:04 pm »
Something more: triangle is the evil!

tetrastes

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] TLabel height
« Reply #33 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...
« Last Edit: December 12, 2020, 09:28:25 pm by tetrastes »

winni

  • Hero Member
  • *****
  • Posts: 2500
Re: [SOLVED] TLabel height
« Reply #34 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
« Last Edit: December 12, 2020, 09:49:37 pm by winni »

lucamar

  • Hero Member
  • *****
  • Posts: 4155
Re: [SOLVED] TLabel height
« Reply #35 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 ...
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

winni

  • Hero Member
  • *****
  • Posts: 2500
Re: [SOLVED] TLabel height
« Reply #36 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

Winni
« Last Edit: December 12, 2020, 10:05:01 pm by winni »

tetrastes

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] TLabel height
« Reply #37 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.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3941
  • I like bugs.
Re: [SOLVED] TLabel height
« Reply #38 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.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

tetrastes

  • Full Member
  • ***
  • Posts: 120
Re: [SOLVED] TLabel height
« Reply #39 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  ;)

andyH

  • Jr. Member
  • **
  • Posts: 82
Re: [SOLVED] TLabel height
« Reply #40 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