Вопрос Сторонний шрифт

Awalder

Новичок
Всем доброго времени суток)
Использовал для инсталлятора на ботве несколько кастомных шрифтов. Отображается всё нормально, но при закрытии ошибка (Прекращена работа Setup/Uninstall)
Пока использовал один сторонний шрифт - все работало. Видимо при закрытии шрифты остаются "висеть" во временной папке, вот кусок кода:

procedure DeinitializeSetup;
begin
if SetupInitialized then
WizardForm.Free;
if IsCustomFontInstalled then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font10}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font20}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font30}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font40}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font50}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font60}'), $10, 0);
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font70}'), $10, 0);
gdipShutDown;
UnloadSkin;
end;

Что то здесь не так?
 

vint56

Ветеран
Проверенный
Awalder, Пример из Igromany
#define Font "segoeui.ttf"
#define Font2 "corbel.ttf"
#define FontName "Segoe UI"
#define FontName2 "Corbel"

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

[Files]
Source: "Dll\*"; Flags: dontcopy;

[code ]
#ifdef UNICODE
#define A "W"
type
PChar = PAnsiChar;
#else
#define A "A"
#endif

const
FR_PRIVATE = $10;

var
segoeui: TLabel;
corbel: TLabel;


function AddFontResource(lpszFilename: String; fl, pdv: DWORD): Integer;
external 'AddFontResourceEx{#A}@gdi32.dll stdcall';
function RemoveFontResource(lpFileName: String; fl, pdv: DWORD): BOOL;
external 'RemoveFontResourceEx{#A}@gdi32.dll stdcall';

function InitializeSetup: boolean;
begin
if not (FontExists('{#FontName}')) then begin
ExtractTemporaryFile('{#Font}');
AddFontResource(ExpandConstant('{tmp}\{#Font}'), FR_PRIVATE, 0);
end;

if not (FontExists('{#FontName2}')) then begin
ExtractTemporaryFile('{#Font2}');
AddFontResource(ExpandConstant('{tmp}\{#Font2}'), FR_PRIVATE, 0);
end;

Result := True;
end;

procedure InitializeWizard();
begin
with WizardForm do
begin
AutoScroll := False;
ClientWidth := ScaleX(666);
end;

{ segoeui }
segoeui := TLabel.Create(WizardForm);
with segoeui do
begin
Parent := WizardForm;
Caption := 'segoeui.ttf';
Font.Color := clWindowText;
Font.Height := -32;
Font.Name := '{#FontName}';
Font.Style := [];
ParentFont := False;
Left := ScaleX(504);
Top := ScaleY(16);
Width := ScaleX(158);
Height := ScaleY(39);
Font.Style := [fsItalic, fsBold];
end;

{ corbel }
corbel := TLabel.Create(WizardForm);
with corbel do
begin
Parent := WizardForm;
Caption := 'corbel.ttf';
Font.Color := clWindowText;
Font.Height := -32;
Font.Name := '{#FontName2}';
Font.Style := [];
ParentFont := False;
Left := ScaleX(504);
Top := ScaleY(56);
Width := ScaleX(158);
Height := ScaleY(39);
Font.Style := [fsItalic, fsBold];
end;
end;

procedure DeinitializeSetup();
begin
if FileExists(ExpandConstant('{tmp}\{#Font}')) then
RemoveFontResource(ExpandConstant('{tmp}\{#Font}'), FR_PRIVATE, 0);
if FileExists(ExpandConstant('{tmp}\{#Font2}')) then
RemoveFontResource(ExpandConstant('{tmp}\{#Font2}'), FR_PRIVATE, 0);
end;
 

Awalder

Новичок
Awalder, Пример из Igromany
#define Font "segoeui.ttf"
#define Font2 "corbel.ttf"
#define FontName "Segoe UI"
#define FontName2 "Corbel"

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

[Files]
Source: "Dll\*"; Flags: dontcopy;

[code ]
#ifdef UNICODE
#define A "W"
type
PChar = PAnsiChar;
#else
#define A "A"
#endif

const
FR_PRIVATE = $10;

var
segoeui: TLabel;
corbel: TLabel;


function AddFontResource(lpszFilename: String; fl, pdv: DWORD): Integer;
external 'AddFontResourceEx{#A}@gdi32.dll stdcall';
function RemoveFontResource(lpFileName: String; fl, pdv: DWORD): BOOL;
external 'RemoveFontResourceEx{#A}@gdi32.dll stdcall';

function InitializeSetup: boolean;
begin
if not (FontExists('{#FontName}')) then begin
ExtractTemporaryFile('{#Font}');
AddFontResource(ExpandConstant('{tmp}\{#Font}'), FR_PRIVATE, 0);
end;

if not (FontExists('{#FontName2}')) then begin
ExtractTemporaryFile('{#Font2}');
AddFontResource(ExpandConstant('{tmp}\{#Font2}'), FR_PRIVATE, 0);
end;

Result := True;
end;

procedure InitializeWizard();
begin
with WizardForm do
begin
AutoScroll := False;
ClientWidth := ScaleX(666);
end;

{ segoeui }
segoeui := TLabel.Create(WizardForm);
with segoeui do
begin
Parent := WizardForm;
Caption := 'segoeui.ttf';
Font.Color := clWindowText;
Font.Height := -32;
Font.Name := '{#FontName}';
Font.Style := [];
ParentFont := False;
Left := ScaleX(504);
Top := ScaleY(16);
Width := ScaleX(158);
Height := ScaleY(39);
Font.Style := [fsItalic, fsBold];
end;

{ corbel }
corbel := TLabel.Create(WizardForm);
with corbel do
begin
Parent := WizardForm;
Caption := 'corbel.ttf';
Font.Color := clWindowText;
Font.Height := -32;
Font.Name := '{#FontName2}';
Font.Style := [];
ParentFont := False;
Left := ScaleX(504);
Top := ScaleY(56);
Width := ScaleX(158);
Height := ScaleY(39);
Font.Style := [fsItalic, fsBold];
end;
end;

procedure DeinitializeSetup();
begin
if FileExists(ExpandConstant('{tmp}\{#Font}')) then
RemoveFontResource(ExpandConstant('{tmp}\{#Font}'), FR_PRIVATE, 0);
if FileExists(ExpandConstant('{tmp}\{#Font2}')) then
RemoveFontResource(ExpandConstant('{tmp}\{#Font2}'), FR_PRIVATE, 0);
end;
Большое спасибо за идею! Синтаксис к ботве пришлось немного доработать, иначе не компилилось:

procedure DeinitializeSetup;
begin
if SetupInitialized then
WizardForm.Free;
if FileExists(ExpandConstant('{tmp}\{#Font}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font10}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font10}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font20}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font20}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font30}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font30}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font40}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font40}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font50}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font50}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font60}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font60}'), $10, 0);
if FileExists(ExpandConstant('{tmp}\{#Font70}')) then
RemoveFontResourceEx(PAnsiChar(ExpandConstant('{tmp}') + '\{#Font70}'), $10, 0);
gdipShutDown;
UnloadSkin;
end;

Все работает, тему можно закрывать. Ещё раз спасибо
 
Сверху