If you are using Delphi 2009 or later, where String
is Unicode, you need to typecast your String
to PChar
when passing it to CreateFontFileReference()
:
hr := DWriteFactory.CreateFontFileReference(
PChar(FontPath),
ft,
FontFile);
If you are using Delphi 2007 or earlier, where String
is Ansi, you need to convert your String
to a WideString
first and then typecast that to PWideChar
:
hr := DWriteFactory.CreateFontFileReference(
PWideChar(WideString(FontPath)),
ft,
FontFile);
Update: turns out there is a bug in the declaration of the first parameter of CreateFontFileReference()
. Embarcadero declares it as var filePath: WCHAR
, but it should have been declared as const filePath: PWCHAR
instead. So you will have to account for that bug by dereferencing the PChar
/PWideChar
pointer, eg:
hr := DWriteFactory.CreateFontFileReference(
PChar(FontPath)^,
...);
hr := DWriteFactory.CreateFontFileReference(
PWideChar(WideString(FontPath))^,
...);