Forum > CustomDrawn

[SOLVED] Patch for fixing a TextOut bug

(1/1)

lagprogramming:
The following example has been posted in this forum.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    procedure TForm1.Button1Click(Sender: TObject);    var      LFont: TFont;      LBmp: TBitmap;      w,h: integer;    begin      LFont := TFont.Create;      try        LBmp := TBitmap.Create;        try          LBmp.Width := Image1.Width;          LBmp.Height := Image1.Height;          LBmp.Canvas.Brush.Color := clWhite;          LBmp.Canvas.Brush.Style := bsSolid;          LBmp.Canvas.Rectangle(0, 0, LBmp.Width, LBmp.Height);          LFont.Name := 'Arial';          LFont.Size := 20;          LFont.Color := clRed;          LBmp.Canvas.Font := LFont;          w:=0;          h:=0;          h := LBmp.Canvas.TextHeight('Test');          w := LBmp.Canvas.TextWidth('Test');          LBmp.Canvas.TextOut(10, h, 'Test');          Image1.Picture.Bitmap.Assign(LBmp);        finally          LBmp.Free;        end;      finally        LFont.Free;      end;    end;    
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---diff --git a/lcl/interfaces/customdrawn/customdrawnwinapi.inc b/lcl/interfaces/customdrawn/customdrawnwinapi.incindex 4d3789ff39..3843bd1cef 100644--- a/lcl/interfaces/customdrawn/customdrawnwinapi.inc+++ b/lcl/interfaces/customdrawn/customdrawnwinapi.inc@@ -2111,7 +2111,7 @@ begin     lFontSize := Round(ftFont.TextHeight(Str) * 0.75);// ToDo: Find out why this 75% factor works     RealX := X + lDestCanvas.WindowOrg.X + lDestCanvas.BaseWindowOrg.X;     RealY := Y + lDestCanvas.WindowOrg.Y + lDestCanvas.BaseWindowOrg.Y + lFontSize;-    FTDrawer.DrawText(Str, ftFont, RealX, RealY, colBlack, 255);+    FTDrawer.DrawText(Str, ftFont, RealX, RealY, lDestCanvas.Font.FPColor, 255);   finally     if FreeFTFont then ftFont.Free;     FTDrawer.Free;

wp:
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:

--- Quote from: wp on March 27, 2023, 01:29:29 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).

--- End quote ---

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

Bart

lagprogramming:

--- Quote from: Bart on March 27, 2023, 03:02:12 pm ---
--- Quote from: wp on March 27, 2023, 01:29:29 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).

--- End quote ---

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

Bart

--- End quote ---

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:

--- Quote from: lagprogramming on March 27, 2023, 04:52:07 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.

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version