digao-dalpiaz / DzHTMLText

Delphi and Lazarus HTML Label component
MIT License
194 stars 53 forks source link

Canvas state of other controls affected by the DzHTMLText control #87

Closed MyBuzzTechnologies closed 8 months ago

MyBuzzTechnologies commented 8 months ago
  1. Create a simple Firemonkey app.
  2. Add a DzHTMLText with the following text (excluding quotes):

'This is <B>bold text</B>'

NOTE: The important thing is that the must be the last thing in the string.

  1. Add a paintbox control to the form, with the following OnPaint event (it can be anything that paints text to the screen):
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
begin
  Canvas.BeginScene;
  try
    Canvas.Fill.Color:=claBlue;
    Canvas.FillText(PaintBox1.BoundsRect, 'Sample Text', False, 1.0, [], TTextAlign.Center);
  finally
    Canvas.EndScene;
  end;
end;
  1. Run the app and you'll see the paintbox text displays in bold.
  2. Now change the DzHtmlText text to end with a "." (so is NOT the last thing in the string). E.g.:

'This is <B>bold text</B>.'

  1. Run the app and you'll see the paintbox text is showing normal (not bold).

It seems like the DzHtmlText label isn't restoring the canvas state after rendering.

digao-dalpiaz commented 8 months ago

Very interesting. I'll check that out.

digao-dalpiaz commented 8 months ago

So, the interesting fact is that this happens between Delphi's own controls. If you place two TPaintBox and in one of them you set the font to Bold on the canvas, depending on the display order of the components, the next one will get the Bold font style too, even though the canvas object of each one is specific.

digao-dalpiaz commented 8 months ago

Done!