View Issue Details

IDProjectCategoryView StatusLast Update
0038268LazarusLCLpublic2021-04-23 17:36
ReporterCudaText man_ Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
OSLinux x64 Ubuntu 20.04.1 
Product Version2.1 (SVN) 
Summary0038268: In Ubuntu, TLabel is painted cropped for chars 'jy'
DescriptionI see that CudaText plugin paints TLabel with 'jy' chars cropped. I see the same on simple demo

- create new app
- add one Label (with AutoSize=true) and caption='xyzjk'.
- label is cropped (both ObjInspector in IDE + runtime)

picture added.
TagsNo tags attached.
Fixed in Revisionr65056
LazTarget-
WidgetsetGTK 2
Attached Files

Relationships

related to 0038211 new TLabel.autosize fails. Suse only! Since years. 
has duplicate 0038298 resolvedBart Broersma TLabel: too small if AutoSize = true 
has duplicate 0038327 resolvedJuha Manninen Gtk2: TLabel: Text is cropped 
related to 0038537 new IpHtml (e.g. used by IDE debugger tooltip) shows CJK text cropped 
related to 0038667 closedJuha Manninen gtk2: Hint of 50 lines shows only 45 lines 

Activities

CudaText man_

2020-12-28 12:18

reporter  

CudaText man_

2020-12-28 12:28

reporter   ~0127854

Lazarus 2.1.0 r64285M FPC 3.2.1 x86_64-linux-gtk2

Benito van der Zander

2021-01-09 14:53

reporter   ~0128198

I have the same problem when using DrawText:

uses LCLIntf,LCLType;

procedure TForm1.FormPaint(Sender: TObject);
var
  s: String;
  r: TRect;
begin
  s := 'xyzjkyg';
  r := rect(0,0,width,height);
  DrawText(Canvas.Handle, pchar(s),length(s), r,DT_NOPREFIX or DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS);
end;

although canvas.TextRect(rect(0,0,width,height),100,100,s); works

Anton Kavalenka

2021-01-09 17:27

reporter   ~0128206

@CudaText man_
Is you graphic subsystem XOrg or Wayland?

i've seen text cropping in GTK2 on Debian 11 Wayland.

Benito van der Zander

2021-01-14 17:21

reporter   ~0128320

Mine is XOrg

Anton Kavalenka

2021-01-15 09:25

reporter   ~0128337

Last edited: 2021-01-15 09:28

View 3 revisions

Can not reproduce on Debian 10.7, Xorg, Intel® HD Graphics 520 (Skylake GT2)
Package: libgtk2.0-0
Version: 2.24.32-3

CudaText man

2021-01-17 23:56

reporter   ~0128392

Mine is X.Org.

Anton Kavalenka

2021-01-18 07:34

reporter   ~0128394

Last edited: 2021-01-18 08:37

View 7 revisions

@Alextpp
@BeniBela

gtk2 version?
Xorg driver vendor?
Did the host was restarted after last updates/upgrades (maybe fontcache corrupted)?

If explicitly calling SelectFont before DrawText helps?
If changing font from default helps?

Benito van der Zander

2021-01-18 16:57

reporter   ~0128397

Last edited: 2021-01-18 17:14

View 2 revisions

> gtk2 version?

  2.24.32-4ubuntu4

Also: Lazarus 2.0.10 r55664M FPC 3.3.1 x86_64-linux-gtk2

>Xorg driver vendor?

How do I check that?

I have an RTX 2060

> If explicitly calling SelectFont before DrawText helps?

Like this? SelectObject(canvas.handle, font.handle);

No

> Did the host was restarted after last updates/upgrades (maybe fontcache corrupted)?

I restart it every day

> If changing font from default helps?

No

At first the font size seems to help. But probably it always cuts off 2 or 3 pixels and those pixels have less impact at bigger size
1.png (25,701 bytes)   
1.png (25,701 bytes)   
arial.png (1,899 bytes)   
arial.png (1,899 bytes)   
arial-2.png (23,645 bytes)   
arial-2.png (23,645 bytes)   
0.png (7,251 bytes)   
0.png (7,251 bytes)   

Anton Kavalenka

2021-01-18 18:42

reporter   ~0128399

It looks like rectangle is of proper size, but text shifted down 2 pixels.
Maybe these problems already fixed in trunk

Benito van der Zander

2021-01-20 21:50

reporter   ~0128455

The DrawText issue also happens in trunk

Anton Kavalenka

2021-01-21 21:23

reporter   ~0128472

What font is default in your desktop?
If explicitly specified 'Arial' or 'FreeSans' reproduce the problem?

Benito van der Zander

2021-01-22 01:34

reporter   ~0128477

>What font is default in your desktop?

Noto Sans, 12

>If explicitly specified 'Arial' or 'FreeSans' reproduce the problem?

Yes. the third/forth picture above are arial

Sreejith kumar g

2021-01-22 08:17

reporter   ~0128480

The bug appears in gtk2 not in qt5 on same system

Tested on Linux Mint 20 Ulyana x86_64 Mate dektop
Screenshot QT5.png (18,346 bytes)   
Screenshot QT5.png (18,346 bytes)   
Screenshot GTk2.png (16,061 bytes)   
Screenshot GTk2.png (16,061 bytes)   

Anton Kavalenka

2021-01-24 08:15

reporter   ~0128539

Do removing DT_VCENTER flag helps?

Benito van der Zander

2021-01-24 10:53

reporter   ~0128546

No

Adding DT_NOCLIP helps, but I need clipping since the text might be wider than the box. (too bad there is no H-CLIP only option to disable V-CLIP)

Anton Kavalenka

2021-04-22 15:23

reporter   ~0130514

GTK2 Winapi emulated GetTextMetrics is broken
add the following lines in test
gettextmetrics(Canvas.Handle,tm);
writeln('tm.height=',tm.tmHeight);

There would be 2px difference on systems with newer GTK2/Xorg/Waylanad and older.

I tested
* Debian 10.9 + X.Org on nvidia vs
* Debian 11 + Wayland on Intel

Patch provided gets rid of using textmetrics in DrawText

Anton Kavalenka

2021-04-22 15:24

reporter   ~0130515

gtk2winapi.diff (1,059 bytes)   
Index: lcl/interfaces/gtk2/gtk2winapi.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2winapi.inc	(revision 65026)
+++ lcl/interfaces/gtk2/gtk2winapi.inc	(working copy)
@@ -2474,7 +2474,7 @@
     begin
       // ignore word and line breaks
       TextExtentPoint(PChar(AStr), length(AStr), AP{%H-});
-      theRect.Bottom := theRect.Top + TM.tmHeight;
+    //  theRect.Bottom := theRect.Top + TM.tmHeight;
       if (Flags and DT_CALCRECT)<>0 then
       begin
         theRect.Right := theRect.Left +  AP.cX;
@@ -2483,6 +2483,7 @@
       else
       begin
         theRect.Right := theRect.Left + Min(MaxWidth, AP.cX);
+        theRect.Bottom := theRect.Top +  AP.cY;
         if (Flags and DT_VCENTER) > 0 then
         begin
           OffsetRect(theRect, 0, ((Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top)) div 2);
@@ -2492,6 +2493,7 @@
         begin
           OffsetRect(theRect, 0, (Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top));
         end;
+
       end;
     end
     else
gtk2winapi.diff (1,059 bytes)   

Anton Kavalenka

2021-04-22 15:42

reporter   ~0130516

Last edited: 2021-04-22 16:55

View 2 revisions

TGtk2Widgetset.UpdateDCTextMetric(DC: TGtkDeviceContext);
is really hacky but pango context returns different ascent and descent on the same font descriptor

the following code placed inside proc
writeln(format('pm.ascent=%d pm.descent=%d',[pango_font_metrics_get_ascent(APangoMetrics),
      pango_font_metrics_get_descent(APangoMetrics)
      ]));

gives different result for the same font on different systems
* Debian 10.9 Xorg
pm.acesnt=47104 pm.descent=13312
* Debian 11 Wayland
pm.acesnt=47070 pm.descent=12901

Either graphic context is not updated or GTK2 is broken on newer systems.

Anton Kavalenka

2021-04-22 16:03

reporter   ~0130518

This patch even better as it fixes rect calculation and GetTextMetrics
gtk2textmetrics.diff (2,083 bytes)   
Index: lcl/interfaces/gtk2/gtk2devicecontext.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2devicecontext.inc	(revision 65026)
+++ lcl/interfaces/gtk2/gtk2devicecontext.inc	(working copy)
@@ -875,7 +875,7 @@
 begin
   // create GC
 
-  if Drawable <> nil then
+  if (Drawable <> nil) and (Drawable^.parent_instance.ref_count>0) then
   begin
     if FWithChildWindows then
     begin
Index: lcl/interfaces/gtk2/gtk2widgetset.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2widgetset.inc	(revision 65026)
+++ lcl/interfaces/gtk2/gtk2widgetset.inc	(working copy)
@@ -5947,8 +5947,9 @@
       TextMetric.tmAveCharWidth := Max(1,
                  pango_font_metrics_get_approximate_char_width(APangoMetrics)
                  div PANGO_SCALE);
-      TextMetric.tmAscent := pango_font_metrics_get_ascent(APangoMetrics) div PANGO_SCALE;
-      TextMetric.tmDescent := pango_font_metrics_get_descent(APangoMetrics) div PANGO_SCALE;
+
+      TextMetric.tmAscent := PANGO_PIXELS(pango_font_metrics_get_ascent(APangoMetrics));
+      TextMetric.tmDescent := PANGO_PIXELS(pango_font_metrics_get_descent(APangoMetrics));
       TextMetric.tmHeight := TextMetric.tmAscent+TextMetric.tmDescent;
 
       pango_layout_set_text(UseFont, PChar(TestString[IsDoubleByteChar]),
Index: lcl/interfaces/gtk2/gtk2winapi.inc
===================================================================
--- lcl/interfaces/gtk2/gtk2winapi.inc	(revision 65026)
+++ lcl/interfaces/gtk2/gtk2winapi.inc	(working copy)
@@ -2483,6 +2483,7 @@
       else
       begin
         theRect.Right := theRect.Left + Min(MaxWidth, AP.cX);
+        theRect.Bottom := theRect.Top +  AP.cY;
         if (Flags and DT_VCENTER) > 0 then
         begin
           OffsetRect(theRect, 0, ((Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top)) div 2);
@@ -2492,6 +2493,7 @@
         begin
           OffsetRect(theRect, 0, (Rect.Bottom - Rect.Top) - (theRect.Bottom - theRect.Top));
         end;
+
       end;
     end
     else
gtk2textmetrics.diff (2,083 bytes)   

Anton Kavalenka

2021-04-22 16:07

reporter   ~0130519

#define PANGO_PIXELS(d) (((int)(d) + 512) >> 10)

Looks like this is everywhere in GTK2 and GTK3 and leads to precision loss

CudaText man

2021-04-22 18:19

reporter   ~0130523

Anton, sorry but I have changed OS setup, installed XFCE and bug 'was fixed there'. on the 2nd PC - Ubuntu- I also don't see the bug.

CudaText man

2021-04-22 20:14

reporter   ~0130525

Last patch fixes this https://bugs.freepascal.org/view.php?id=38667
all 50 lines are OK now.

Juha Manninen

2021-04-23 17:36

developer   ~0130542

Applied, thanks.

Issue History

Date Modified Username Field Change
2020-12-28 12:18 CudaText man_ New Issue
2020-12-28 12:18 CudaText man_ File Added: Screenshot from 2020-12-28 14-10-07.png
2020-12-28 12:28 CudaText man_ Note Added: 0127854
2021-01-03 17:56 Bart Broersma Relationship added has duplicate 0038298
2021-01-08 17:40 Juha Manninen Relationship added has duplicate 0038327
2021-01-09 14:53 Benito van der Zander Note Added: 0128198
2021-01-09 17:27 Anton Kavalenka Note Added: 0128206
2021-01-14 17:21 Benito van der Zander Note Added: 0128320
2021-01-15 09:25 Anton Kavalenka Note Added: 0128337
2021-01-15 09:25 Anton Kavalenka File Added: Здымак экрана, 2021-01-15 11-24-20.png
2021-01-15 09:27 Anton Kavalenka Note Edited: 0128337 View Revisions
2021-01-15 09:28 Anton Kavalenka Note Edited: 0128337 View Revisions
2021-01-17 23:56 CudaText man Note Added: 0128392
2021-01-18 07:34 Anton Kavalenka Note Added: 0128394
2021-01-18 07:34 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 08:13 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 08:15 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 08:31 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 08:32 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 08:37 Anton Kavalenka Note Edited: 0128394 View Revisions
2021-01-18 16:57 Benito van der Zander Note Added: 0128397
2021-01-18 16:57 Benito van der Zander File Added: 0.png
2021-01-18 16:57 Benito van der Zander File Added: 1.png
2021-01-18 16:57 Benito van der Zander File Added: arial.png
2021-01-18 16:57 Benito van der Zander File Added: arial-2.png
2021-01-18 17:14 Benito van der Zander Note Edited: 0128397 View Revisions
2021-01-18 18:42 Anton Kavalenka Note Added: 0128399
2021-01-19 13:49 Zeljan Rikalo Relationship added related to 0038211
2021-01-20 21:50 Benito van der Zander Note Added: 0128455
2021-01-21 21:23 Anton Kavalenka Note Added: 0128472
2021-01-22 01:34 Benito van der Zander Note Added: 0128477
2021-01-22 08:17 Sreejith kumar g Note Added: 0128480
2021-01-22 08:17 Sreejith kumar g File Added: Screenshot QT5.png
2021-01-22 08:17 Sreejith kumar g File Added: Screenshot GTk2.png
2021-01-24 08:15 Anton Kavalenka Note Added: 0128539
2021-01-24 10:53 Benito van der Zander Note Added: 0128546
2021-02-26 18:30 Martin Friebe Relationship added related to 0038537
2021-03-27 09:53 Juha Manninen Relationship added related to 0038667
2021-04-22 15:23 Anton Kavalenka Note Added: 0130514
2021-04-22 15:24 Anton Kavalenka Note Added: 0130515
2021-04-22 15:24 Anton Kavalenka File Added: gtk2winapi.diff
2021-04-22 15:42 Anton Kavalenka Note Added: 0130516
2021-04-22 16:03 Anton Kavalenka Note Added: 0130518
2021-04-22 16:03 Anton Kavalenka File Added: gtk2textmetrics.diff
2021-04-22 16:07 Anton Kavalenka Note Added: 0130519
2021-04-22 16:55 Anton Kavalenka Note Edited: 0130516 View Revisions
2021-04-22 18:19 CudaText man Note Added: 0130523
2021-04-22 20:14 CudaText man Note Added: 0130525
2021-04-23 17:15 Juha Manninen Assigned To => Juha Manninen
2021-04-23 17:15 Juha Manninen Status new => assigned
2021-04-23 17:36 Juha Manninen Status assigned => resolved
2021-04-23 17:36 Juha Manninen Resolution open => fixed
2021-04-23 17:36 Juha Manninen Fixed in Revision => r65056
2021-04-23 17:36 Juha Manninen LazTarget => -
2021-04-23 17:36 Juha Manninen Widgetset GTK 2 => GTK 2
2021-04-23 17:36 Juha Manninen Note Added: 0130542