We help IT Professionals succeed at work.

Halo text on a canvas

delpro
delpro asked
on
Medium Priority
408 Views
Last Modified: 2010-04-06
How can i make text halo and show it on the canvas
Comment
Watch Question

Commented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    procedure Paint; override;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.Paint;
begin
  inherited;
  Canvas.Brush.Style := bsClear;
  Canvas.TextOut(10,10,'Hello World');
end;

end.

Commented:
Delpro, this is not a 200 pts. question

Author

Commented:
I think it is a 300 point question.

Canvas.Brush.Style := bsClear;
makes the text transparent not halo
Halo is a line around the the text
it look if the text is bold but in a diverent color.
Inside black and outside white
I hope you understand zebada
listening...

Commented:
Sorry, I just thought you mistyped "Hello".

Commented:
the windows SYSTEM does almost all of the text rendering, I don't remember any text draw function that doesn't draw "solid" text, you might try this, draw the text 4 times, 3 times in the halo color (white), next moving it 2 pixels down and 2 pixels to the right, next just 2 pixels down. Then on top of that draw the text (one pixel down and 1 pixel to the right) in the text color. . . like this


procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Brush.Style := bsClear;
Canvas.Font.Name := 'Arial';
Canvas.Font.Size := 20;
Canvas.Font.Style := [fsBold];
Canvas.Font.Color := clWhite;
Canvas.TextOut(120,6,'Halo text');
Canvas.TextOut(122,8,'Halo text');
Canvas.TextOut(120,8,'Halo text');
Canvas.Font.Color := clBlack;
Canvas.TextOut(121,7,'Halo text');
end;

this gave me that effect, with a one pixel halo, let me know
Commented:
I looked around in some stuff I did a while ago and found this. It uses a windows Path that is formed on a TextOut draw, and then Strokes that path with the current Pen, giving an Outlined or Halo effect. You can also make Clipped areas with a Path. Here's the code . . . .



procedure TForm1.sbut_TexPathClick(Sender: TObject);
begin
PaintBox1.Canvas.Font.Name := 'Arial';
PaintBox1.Canvas.Font.Size := 44;
PaintBox1.Canvas.Font.Color := clBlack;
PaintBox1.Canvas.Font.Style := [fsBold];
PaintBox1.Canvas.Brush.Style := bsClear;
{you need a transparent brush bsClear}
BeginPath(PaintBox1.Canvas.Handle);
{a Path is a series of points and curves, a closed path
conects the begining and end of the path}
PaintBox1.Canvas.TextOut(13, 13, 'Halo Text');
{whatever is in between the BeginPath and EndPath is NOT
drawn on the HDC, it only makes the path}
EndPath(PaintBox1.Canvas.Handle);

{you have to do a textOut again to see it}
PaintBox1.Canvas.TextOut(13, 13, 'Halo Text');
PaintBox1.Canvas.Pen.Width := 2;
{a Pen width of 2 or 3 looks better on Large text}
PaintBox1.Canvas.Pen.Style := psSolid;
PaintBox1.Canvas.Pen.Color := clWhite;
{I tried other pen colors, but it seemed to always
use the white, you may have to select the pen}
StrokePath(PaintBox1.Canvas.Handle);
{StrokePath draws the Pen around the Path, but it is NOT
AntiAliased, so it is jaggy on curves and text}

{StrokeAndFillPath(PaintBox1.Canvas.Handle);
you may want to experiment with StrokeAndFillPath}

AbortPath(PaintBox1.Canvas.Handle);
{you don't need the path anymore so Abort it}

{Reset the PaintBox1 pen and brush}
PaintBox1.Canvas.Pen.Width := 1;
PaintBox1.Canvas.Brush.Style := bsSolid;
PaintBox1.Canvas.Brush.Color := clWhite;
PaintBox1.Canvas.Font := Font;
end;

 - - - - - - - - - - -
this looks different than the first code, but I usually like the look of the first because the font draw is usually AntiAlaised, let me know

Commented:
listening