Recent

Author Topic: TAChart + TChartGUIConnectorBGRA issue  (Read 1971 times)

ChristianH

  • New Member
  • *
  • Posts: 46
TAChart + TChartGUIConnectorBGRA issue
« on: March 07, 2023, 08:49:24 pm »
Hi,

i have a problem with the latest official Lazarus build in combination with TAChart and BGRA. The legends are rendered horribly wrong.

The reason is the DrawFontBackground:

Code: Pascal  [Select][+][-]
  1. procedure TBGRACanvas.TextOut(X, Y: Integer; const Text: String);
  2. var size: TSize;
  3.     c,s: single;
  4. begin
  5.   ApplyFont;
  6.   if DrawFontBackground then
  7.   begin
  8.     size := TextExtent(Text);
  9.     c := cos(Font.Orientation*Pi/1800);
  10.     s := -sin(Font.Orientation*Pi/1800);
  11.     PolygonF([PointF(X,Y),PointF(X+c*size.cx,Y+s*size.cx),
  12.               PointF(X+c*size.cx-s*size.cy,Y+s*size.cx+c*size.cy),
  13.               PointF(X-s*size.cy,Y+c*size.cy)],False,True);
  14.   end;
  15.   if Font.Texture <> nil then
  16.     FBitmap.TextOut(x,y,Text,Font.Texture) else
  17.     FBitmap.TextOut(x,y,Text,Font.BGRAColor);
  18. end;    

It is enabled by default and looks like this in my case like in the attached image. It was working in older builds, so I wonder is this a bug?

Christian

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #1 on: March 07, 2023, 09:47:57 pm »
Hi,

i have a problem with the latest official Lazarus build in combination with TAChart and BGRA. The legends are rendered horribly wrong.

The reason is the DrawFontBackground:

Code: Pascal  [Select][+][-]
  1. procedure TBGRACanvas.TextOut(X, Y: Integer; const Text: String);
  2. var size: TSize;
  3.     c,s: single;
  4. begin
  5.   ApplyFont;
  6.   if DrawFontBackground then
  7.   begin
  8.     size := TextExtent(Text);
  9.     c := cos(Font.Orientation*Pi/1800);
  10.     s := -sin(Font.Orientation*Pi/1800);
  11.     PolygonF([PointF(X,Y),PointF(X+c*size.cx,Y+s*size.cx),
  12.               PointF(X+c*size.cx-s*size.cy,Y+s*size.cx+c*size.cy),
  13.               PointF(X-s*size.cy,Y+c*size.cy)],False,True);
  14.   end;
  15.   if Font.Texture <> nil then
  16.     FBitmap.TextOut(x,y,Text,Font.Texture) else
  17.     FBitmap.TextOut(x,y,Text,Font.BGRAColor);
  18. end;    

It is enabled by default and looks like this in my case like in the attached image. It was working in older builds, so I wonder is this a bug?

Christian

Please report in BGRABitmap at GitHub:
https://github.com/bgrabitmap/bgrabitmap/issues/new

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #2 on: March 07, 2023, 10:37:50 pm »
No, this is not a BGRABitmap issue. I used the same version (v11.3.1) with both Laz-main and withLaz-2.0.8 and get the correct legend text in the old Laz version, but not in the current version. I think this issue is due to some changes made by myself some time ago to make TAChart colors more compatible with dark mode.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #3 on: March 08, 2023, 12:06:11 pm »
Fixed in Laz/main.

ChristianH

  • New Member
  • *
  • Posts: 46
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #4 on: March 08, 2023, 08:54:25 pm »
Wow, this was quick. Thanks. I found also another problem I guess. This time with aggpas.
If I use this GUIConnector the output is completely black. I attached a test binary. I did not found time to debug it yet, but I will probably do so tomorrow.

Christian

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #5 on: March 08, 2023, 10:04:44 pm »
OK - another left-over... As a quick fix: do not use system colors, only RGB colors (clWhite instead of clWindow). And in the AreaSeries, activate UseZeroLevel.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: TAChart + TChartGUIConnectorBGRA issue
« Reply #6 on: March 09, 2023, 12:26:39 pm »
This is difficult to fix because the drawers are planned to be kept independent of the LCL as much as possible, and wanting to replace system colors by the rgb values would mean to call the function ColorToRGB from unit graphics. However, the drawers are constructed quite flexibly: there is a function pointer DoChartColorToFPColor which converts TColor to the TFPColor values used internally by the drawer. Normally this points to the function ChartColorToFPColor which simply extracts the r,g,b bytes from the TColor and assigns them to the Red, Green, Blue words in TFPColor. Alternatively you can make it point to ChartColorSysToFPColor which does the conversion of the system colors first - of course, at your responsibility because now the drawer calls an LCL function.

The drawer is accessible as Chart.Drawer, and thus, when you add the following lines the blackness in the aggpas chart will be gone (you still need to update to the current TAChart units because several issues had to be fixed for this to work):

Code: Pascal  [Select][+][-]
  1. uses
  2.   TADrawerCanvas;
  3.  
  4. procedure TForm1.FormCreate(Sender: TObject);
  5. begin
  6.   Chart1.Drawer.DoChartColorToFPColor := @ChartColorSysToFPColor;
  7. end;

 

TinyPortal © 2005-2018