Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Draw a Unicode Character?

Tags:

unicode

delphi

I'm trying to draw an font icon on a canvas. I'm using the Ionicons font. All I get is a rectangle on the screen.

var
  x1, y1: integer;
  xChr: WideChar;
begin

  x1 := 10;
  y1 := 10;

  fMaleIcon := $f202;
  fFemailIcon := $f25d;

  if xRep.Male then
    xChr := Char(fMaleIcon)
  else
    xChr := Char(fFemaleIcon);

  xCanvas.TextOut(x1, y1, xChr);
end;

What am I doing wrong?

Thanks - Steve

like image 392
Steve Maughan Avatar asked Sep 12 '25 08:09

Steve Maughan


1 Answers

The empty rectangle means that the font you are using does not contain glyphs for those characters. You must use a font that does.

Your code is rather convoluted. I'd write it like this:

var
  xChr: Char;
begin
  if xRep.Male then
    xChr := #$f202;
  else
    xChr := #$f25d;

  xCanvas.TextOut(10, 10, xChr);
end;

Or perhaps:

const
  GenderChars: array [Boolean] of Char = (#$f25d, #$f202);
....
xCanvas.TextOut(10, 10, GenderChars[xRep.Male]);

You might like to declare an enumerated type to hold your gender information, rather than a Boolean.

like image 193
David Heffernan Avatar answered Sep 14 '25 05:09

David Heffernan