0
votes

I'm building cross-platform desktop app with additional font (Abilene). On startup I check is the font installed and if it is not, I install it and use it. For Mac everything seems to be fine, but Windows version (and the IDE!!) does not display the font correctly. Here is the font installation procedure:

procedure InstallFont;
const
  REG_NT = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts';

var
  Reg: TRegistry;
  res: Boolean;
  installName,FileName: UnicodeString;

begin
  Reg := TRegistry.Create(KEY_ALL_ACCESS);
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    res := Reg.OpenKey(REG_NT, False);
    if not Res then Exit;

    installName := 'Abilene Regular (TrueType)';
    FileName:=ExtractFilePath(ParamCount(0)+'\Abilene.ttf';
    Reg.WriteString(installName, FileName);
    Reg.CloseKey;
  finally
    Reg.Free;
  end;

  AddFontResourceW(PWideChar(FileName));
  SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0);
end;

After installing the font it is displayed as shortcut in the Control panel, but all other programs can use it. Even Delphi can, but with VCL, not FMX applications (see attached pictures). I've attached pictures from the IDE. In the runtime it's the same.

Is there anything that must be done additionally for the font installation especially for FMX apps? Or this is just a bug which must be reported to Embarcaderro QC?

FMX IDE

VCL IDE

Edit: Adding some details: If I install the font by downloading it, clicking with the right mouse button and choose 'Install' then everything is OK. If I install it by my proc then the font is visible and usable for the whole world except the Delphi FMX. Delphi VCL can use it also. To test this I install ed the font with my proc in my %APPDATA% folder. Word, Excel, Delphi VCL can use it. Delphi FMX cannot.

Edit2: Added SendMessage(HWND_BROADCAST, WM_FONTCHANGE,0,0). No change.

Edit3: In the Font dialog the font is displayed correctly (image 3) enter image description here

1
This seems all wrong to me. You are going to force your app to show the UAC dialog to the users every time it runs, just so that it can do a one time only font install? Put the font install into your installer. As for the FMX specific issue, I think that's independent of the installation right? Even if you install it manually, outside of your program, you are saying that FMX won't display it correctly? Or is the problem only when you install the font from your program?David Heffernan
I first check is the font installed, i.e. if in the registry exists a key Abilene Regular (TrueType) the procedure is just skipped.LHristov
And if I install the font from the wizard and never check for it the user can uninstall it from the Control panelLHristov
All the same, you will be forcing the UAC dialog onto your users every time your program is run. You didn't answer any of the questions that I asked.David Heffernan
@LHristov Nobody writes installers into the program. If the user deletes an important component from your program, it's their fault. The user can just do a repair install to fix it. Sounds like you need to get a new boss.David Heffernan

1 Answers

0
votes

Obviously this is some sort of bug, because I've found a workaround: if I first copy the font to %windir%\Fonts folder then everything is OK. Even if I made a subfolder of the \windows\fonts folder and copy the font in it everything is fine also.

Why Firemonkey does not want to display fonts outside that folder I have no idea. And, as I said, this is for Windows only. Mac OS is OK (I use ~/Library/Fonts).