Recent

Author Topic: Brush styles don't seem to apply with fonts.  (Read 321 times)

jamie

  • Hero Member
  • *****
  • Posts: 7493
Brush styles don't seem to apply with fonts.
« on: November 19, 2025, 11:13:30 pm »
Correct me here, is it true only Solid and Clear brushes work with Text for backgrounds?

Jamie
« Last Edit: November 19, 2025, 11:19:03 pm by jamie »
The only true wisdom is knowing you know nothing

speter

  • Sr. Member
  • ****
  • Posts: 479
Re: Brush styles don't seem to apply with fonts.
« Reply #1 on: November 20, 2025, 12:03:33 am »
I think you are correct, Jamie.
(tested on windows).
The work-around should be easy though, you can paint the background, then write the text...

I tested using textout (not textrect):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel_leftPaint(Sender: TObject);
  2. var
  3.   yinc, a : integer;
  4.   s : string;
  5.   k : tbrushstyle;
  6.   sz : tsize;
  7.   mid,p : tpoint;
  8.   arect : trect;
  9. begin
  10.   with panel_left do
  11.     begin
  12.       canvas.font.color := clblack;
  13.       canvas.brush.color := $ffa0a0;
  14.       canvas.pen.color := clred;
  15.  
  16.       yinc := height div 8;
  17.       mid.x := width div 2;
  18.       for k := bsSolid to bsDiagCross do
  19.         begin
  20.           a := ord(k);
  21.           arect := rect(0,yinc*a,width-1,yinc*(a+1));
  22.           canvas.brush.style := bssolid;
  23.           canvas.brush.color := $a0ffa0;
  24.           canvas.Rectangle(arect);
  25.  
  26.           canvas.brush.color := $ffa0a0;
  27.           canvas.brush.style := k;
  28.           writestr(s,k);
  29.           sz := canvas.textextent(s);
  30.           mid.y := (arect.top + arect.bottom) div 2;
  31.           p := point(mid.x - sz.cx div 2, mid.y - sz.cy div 2);
  32.  
  33.           canvas.textout(p.x,p.y,s);
  34.         end;
  35.     end;
  36. end;

cheers
S.
« Last Edit: November 20, 2025, 12:10:18 am by speter »
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

dsiders

  • Hero Member
  • *****
  • Posts: 1509
Re: Brush styles don't seem to apply with fonts.
« Reply #2 on: November 20, 2025, 01:15:10 am »
I think you are correct, Jamie.
(tested on windows).
The work-around should be easy though, you can paint the background, then write the text...

I tested using textout (not textrect):
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Panel_leftPaint(Sender: TObject);
  2. var
  3.   yinc, a : integer;
  4.   s : string;
  5.   k : tbrushstyle;
  6.   sz : tsize;
  7.   mid,p : tpoint;
  8.   arect : trect;
  9. begin
  10.   with panel_left do
  11.     begin
  12.       canvas.font.color := clblack;
  13.       canvas.brush.color := $ffa0a0;
  14.       canvas.pen.color := clred;
  15.  
  16.       yinc := height div 8;
  17.       mid.x := width div 2;
  18.       for k := bsSolid to bsDiagCross do
  19.         begin
  20.           a := ord(k);
  21.           arect := rect(0,yinc*a,width-1,yinc*(a+1));
  22.           canvas.brush.style := bssolid;
  23.           canvas.brush.color := $a0ffa0;
  24.           canvas.Rectangle(arect);
  25.  
  26.           canvas.brush.color := $ffa0a0;
  27.           canvas.brush.style := k;
  28.           writestr(s,k);
  29.           sz := canvas.textextent(s);
  30.           mid.y := (arect.top + arect.bottom) div 2;
  31.           p := point(mid.x - sz.cx div 2, mid.y - sz.cy div 2);
  32.  
  33.           canvas.textout(p.x,p.y,s);
  34.         end;
  35.     end;
  36. end;

cheers
S.

Sounds like useful information for help topics. Would this be something that needs mentioning in TCanvas.Brush or TCanvas.TextOut()? Both? Or other?

jamie

  • Hero Member
  • *****
  • Posts: 7493
Re: Brush styles don't seem to apply with fonts.
« Reply #3 on: November 20, 2025, 12:00:42 pm »
@speter

 That is about what i did.

  I use drawtext and now first clear the bacground with the desired brush, and that includes an image with the bounding rect, then use a clear brush for the text.

 This allows for custom brushes the user can define.

As for documentation, maybe it should be noted.
Jamie

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018