Recent

Author Topic: [SOLVED] Patch for fixing a TextOut bug  (Read 450 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 294
[SOLVED] Patch for fixing a TextOut bug
« on: March 18, 2023, 04:26:09 pm »
The following example has been posted in this forum.

Code: Pascal  [Select][+][-]
  1.     procedure TForm1.Button1Click(Sender: TObject);
  2.     var
  3.       LFont: TFont;
  4.       LBmp: TBitmap;
  5.       w,h: integer;
  6.     begin
  7.       LFont := TFont.Create;
  8.       try
  9.         LBmp := TBitmap.Create;
  10.         try
  11.           LBmp.Width := Image1.Width;
  12.           LBmp.Height := Image1.Height;
  13.           LBmp.Canvas.Brush.Color := clWhite;
  14.           LBmp.Canvas.Brush.Style := bsSolid;
  15.           LBmp.Canvas.Rectangle(0, 0, LBmp.Width, LBmp.Height);
  16.           LFont.Name := 'Arial';
  17.           LFont.Size := 20;
  18.           LFont.Color := clRed;
  19.           LBmp.Canvas.Font := LFont;
  20.           w:=0;
  21.           h:=0;
  22.           h := LBmp.Canvas.TextHeight('Test');
  23.           w := LBmp.Canvas.TextWidth('Test');
  24.           LBmp.Canvas.TextOut(10, h, 'Test');
  25.           Image1.Picture.Bitmap.Assign(LBmp);
  26.         finally
  27.           LBmp.Free;
  28.         end;
  29.       finally
  30.         LFont.Free;
  31.       end;
  32.     end;
  33.  
   
Using LCLWidgetType "customdrawn", the color used for writing the text "Test" is black, although we have the line "LFont.Color := clRed;".
The following patch fixes the problem. As you can see, original code uses a constant, colBlack.

Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  2. index 4d3789ff39..3843bd1cef 100644
  3. --- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  4. +++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc
  5. @@ -2111,7 +2111,7 @@ begin
  6.      lFontSize := Round(ftFont.TextHeight(Str) * 0.75);// ToDo: Find out why this 75% factor works
  7.      RealX := X + lDestCanvas.WindowOrg.X + lDestCanvas.BaseWindowOrg.X;
  8.      RealY := Y + lDestCanvas.WindowOrg.Y + lDestCanvas.BaseWindowOrg.Y + lFontSize;
  9. -    FTDrawer.DrawText(Str, ftFont, RealX, RealY, colBlack, 255);
  10. +    FTDrawer.DrawText(Str, ftFont, RealX, RealY, lDestCanvas.Font.FPColor, 255);
  11.    finally
  12.      if FreeFTFont then ftFont.Free;
  13.      FTDrawer.Free;
« Last Edit: March 28, 2023, 01:02:32 pm by lagprogramming »

wp

  • Hero Member
  • *****
  • Posts: 10858
Re: Patch for fixing a TextOut bug
« Reply #1 on: March 27, 2023, 01:29:29 pm »
Please post this issue in the bug track for better documentation (it is hard to find in the forum).
And add a compilable project (my own attempt creating one with customdrawn as widgetset fails to compile in TCDWidgetSet.EnumDisplayMonitors due to "overloaded functions have the same parameter list" although the package itself can be installed properly).

Bart

  • Hero Member
  • *****
  • Posts: 4974
    • Bart en Mariska's Webstek
Re: Patch for fixing a TextOut bug
« Reply #2 on: March 27, 2023, 03:02:12 pm »
(my own attempt creating one with customdrawn as widgetset fails to compile in TCDWidgetSet.EnumDisplayMonitors due to "overloaded functions have the same parameter list" although the package itself can be installed properly).

Reported in bugtracker with possible patch.
Most likley due to Customdrawn: Implement EnumDisplayMonitors and GetMonitorInfo for CD_X11 and CD_win32.

Bart

lagprogramming

  • Sr. Member
  • ****
  • Posts: 294
Re: Patch for fixing a TextOut bug
« Reply #3 on: March 27, 2023, 04:52:07 pm »
(my own attempt creating one with customdrawn as widgetset fails to compile in TCDWidgetSet.EnumDisplayMonitors due to "overloaded functions have the same parameter list" although the package itself can be installed properly).

Reported in bugtracker with possible patch.
Most likley due to Customdrawn: Implement EnumDisplayMonitors and GetMonitorInfo for CD_X11 and CD_win32.

Bart

Maybe
Commit 5779a011 >  CustomDrawn: Fix compilation of CustomDrawn X11. Issue #37813, patch from Sven Barth.
Issue #37813 > Fix compilation of CustomDrawn X11
can be of interest.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4221
  • I like bugs.
Re: Patch for fixing a TextOut bug
« Reply #4 on: March 27, 2023, 05:18:27 pm »
Maybe
Commit 5779a011 >  CustomDrawn: Fix compilation of CustomDrawn X11. Issue #37813, patch from Sven Barth.
Issue #37813 > Fix compilation of CustomDrawn X11
can be of interest.
That one was already applied a long time ago.
I applied the fix in your first post above, and also the patch in Bart's bug report.
Please test.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

 

TinyPortal © 2005-2018