-
Notifications
You must be signed in to change notification settings - Fork 0
/
FONTTYPE.PAS
141 lines (123 loc) · 3.04 KB
/
FONTTYPE.PAS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
{$I COMPILER.INC}
unit FontType;
interface
uses
AplObj,
AplTypes,
Streams,
Graphics;
type
PFontProperties = ^TFontProperties;
PFontAppSettings = ^TFontAppSettings;
TFontProperties = object(TIdentifiable)
private
public
Format: TFontFormat;
MaxWidth: integer;
Height: integer;
Spacing: integer;
function CreateFont: PFont;
procedure Init; virtual;
procedure Assign(var ASource: TObject); virtual;
procedure AssignFromFont(AFont: PFont); virtual;
end;
TFontAppSettings = object(TPersistent)
private
public
LastOpenDir: PChar;
LastSaveDir: PChar;
procedure LoadFromStream(AStream: PStream); virtual;
procedure SaveToStream(AStream: PStream); virtual;
destructor Free; virtual;
procedure Init; virtual;
procedure Assign(var ASource: TObject); virtual;
end;
const
SupportedFontFormats: TFontFormats = [
ffMonoSpace,
ffProportional,
ffSystem,
ffColored
];
implementation
uses
AplUtils,
AplStr;
procedure TFontProperties.Init;
begin
Id := nil;
Format := ffProportional;
MaxWidth := 8;
Height := 16;
Spacing := 1;
end;
procedure TFontProperties.Assign(var ASource: TObject);
var
source: PFontProperties;
begin
inherited Assign(ASource);
source := PFontProperties(@ASource);
TString.Assign(Id, source^.Id);
Format := Source^.Format;
MaxWidth := Source^.MaxWidth;
Height := Source^.Height;
Spacing := Source^.Spacing;
end;
procedure TFontProperties.AssignFromFont(AFont: PFont);
begin
TString.Assign(Id, AFont^.Id);
Format := AFont^.Format;
MaxWidth := AFont^.MaxWidth;
Height := AFont^.Height;
Spacing := AFont^.Spacing;
end;
function TFontProperties.CreateFont: PFont;
var
result: PFont;
begin
case Format of
ffMonoSpace: result := New(PMonospaceFont, CreateSize(MaxWidth, Height, Spacing));
ffProportional: result := New(PProportionalFont, CreateSize(MaxWidth, Height, Spacing));
ffSystem: result := New(PSystemFont, Create);
ffColored: result := New(PColoredFont, CreateSize(MaxWidth, Height, Spacing));
end;
result^.Id := TString.Copy(Id);
result^.SetFormat(Format);
CreateFont := result;
end;
procedure TFontAppSettings.Init;
begin
inherited Init;
LastOpenDir := TString.New(AppDir);
LastSaveDir := TString.New(AppDir);
end;
procedure TFontAppSettings.Assign(var ASource: TObject);
var
source: PFontAppSettings;
begin
inherited Assign(ASource);
source := PFontAppSettings(@ASource);
TString.Assign(LastOpenDir, source^.LastOpenDir);
TString.Assign(LastSaveDir, source^.LastSaveDir);
end;
procedure TFontAppSettings.LoadFromStream(AStream: PStream);
begin
inherited Create;
TString.Free(LastOpenDir);
TString.Free(LastSaveDir);
LastOpenDir := AStream^.ReadPChar;
LastSaveDir := AStream^.ReadPChar;
end;
procedure TFontAppSettings.SaveToStream(AStream: PStream);
begin
AStream^.WritePChar(LastOpenDir);
AStream^.WritePChar(LastSaveDir);
CheckReRaise(AStream);
end;
destructor TFontAppSettings.Free;
begin
TString.Free(LastOpenDir);
TString.Free(LastSaveDir);
inherited Free;
end;
end.