Inno Setup - 如何在安装开始之前安装许多字体?

时间:2014-03-03 18:01:53

标签: fonts inno-setup

我想在安装开始之前安装一些字体,是否可以?

1 个答案:

答案 0 :(得分:3)

如何在没有安装的情况下为向导使用外部字体?

要将私人用途的字体注册到某个进程(在您的情况下是设置),您可以使用fl中指定的AddFontResourceEx标记调用的Windows API函数FR_PRIVATE参数。它将允许您仅为您的过程使用该字体。在下面的示例中,显示了如何将字体提取到临时文件夹,将其注册以供私人使用设置过程以及如何将其加载到向导表单控件:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
Source: "MyFont.ttf"; Flags: dontcopy

[Code]
#ifdef UNICODE
  #define AW "W"
#else
  #define AW "A"
#endif
const
  FR_PRIVATE = $10;
  FR_NOT_ENUM = $20;

function AddFontResourceEx(lpszFilename: string;
  fl: DWORD; pdv: Cardinal): Integer;
  external 'AddFontResourceEx{#AW}@gdi32.dll stdcall';
function RemoveFontResourceEx(lpFileName: string;
  fl: DWORD; pdv: Cardinal): BOOL;
  external 'RemoveFontResourceEx{#AW}@gdi32.dll stdcall';

var
  FontFlags: DWORD;

[Code]
procedure InitializeWizard;
var
  FontName: string;
begin
  // extract the font file to the temporary folder
  ExtractTemporaryFile('MyFont.ttf');
  // this combination specifies the reservation of this font for use
  // in the setup process and that this font cannot be enumerated
  FontFlags := FR_PRIVATE or FR_NOT_ENUM;
  // add the font resource
  if AddFontResourceEx(ExpandConstant('{tmp}\MyFont.ttf'),
    FontFlags, 0) <> 0 then
  begin
    // note, that this is the name of the font, which doesn't have
    // to match to the font file name
    FontName := 'My Font Name';
    // the global setting of the WizardForm.Font property causes many
    // of its child controls to inherit this font; except those listed
    // below; their default font has changed and they lost the ability
    // to inherit the font from their parent so we must do it manually
    WizardForm.Font.Name := FontName;
    WizardForm.WelcomeLabel1.Font.Name := FontName;
    WizardForm.PageNameLabel.Font.Name := FontName;
    WizardForm.FinishedHeadingLabel.Font.Name := FontName;
  end;
end;

procedure DeinitializeSetup;
begin
  // remove the font resource
  RemoveFontResourceEx(ExpandConstant('{tmp}\MyFont.ttf'),
    FontFlags, 0);
end;