Repository navigation
Expand file tree
/
Copy pathTestFontFace.Load.pas
More file actions
116 lines (98 loc) · 2.88 KB
/
Copy pathTestFontFace.Load.pas
File metadata and controls
116 lines (98 loc) · 2.88 KB
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
unit TestFontFace.Load;
interface
uses
Generics.Collections,
Windows, Classes, SysUtils,
PascalType.FontFace,
PascalType.FontFace.SFNT,
TestFramework;
type
TTestPascalTypeFontFaceApple = class(TTestCase)
private
FFontFace: TPascalTypeFontFace;
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestAppleChancery;
procedure TestZapfTable;
end;
implementation
uses
IOUtils,
PascalType.Types,
PascalType.Tables.Apple,
TestFontFace;
type
TPascalTypeFontFaceCracker = class(TPascalTypeFontFace);
const
sFontFolder = '..\Data\';
procedure TTestPascalTypeFontFaceApple.SetUp;
begin
inherited;
FFontFace := TPascalTypeFontFace.Create;
end;
procedure TTestPascalTypeFontFaceApple.TearDown;
begin
inherited;
FreeAndNil(FFontFace);
end;
procedure TTestPascalTypeFontFaceApple.TestAppleChancery;
begin
// Apple Chancery is an old OS 9 system font.
// Notably it contains a 'kern' version 1 table with a format 2 subtable.
FFontFace.LoadFromFile(sFontFolder+'Apple Chancery.ttf');
end;
procedure TTestPascalTypeFontFaceApple.TestZapfTable;
var
ZapfTable: TPascalTypeZapfTable;
Stream1, Stream2, Stream3: TMemoryStream;
NewTable1, NewTable2: TPascalTypeZapfTable;
p1, p2: PByte;
i: Integer;
begin
FFontFace.LoadFromFile(sFontFolder+'Apple Chancery.ttf');
ZapfTable := FFontFace.GetTableByName('Zapf') as TPascalTypeZapfTable;
CheckNotNull(ZapfTable, 'Zapf table should exist in Apple Chancery');
Stream1 := TMemoryStream.Create;
Stream2 := TMemoryStream.Create;
Stream3 := TMemoryStream.Create;
NewTable1 := TPascalTypeZapfTable.Create(TPascalTypeFontFaceCracker(FFontFace).RootTable);
NewTable2 := TPascalTypeZapfTable.Create(TPascalTypeFontFaceCracker(FFontFace).RootTable);
try
ZapfTable.SaveToStream(Stream1);
CheckTrue(Stream1.Size > 0, 'Saved stream size should be greater than 0');
Stream1.Position := 0;
NewTable1.LoadFromStream(Stream1, Stream1.Size);
NewTable1.SaveToStream(Stream2);
CheckEquals(Stream1.Size, Stream2.Size, 'Round-trip stream sizes should match');
p1 := Stream1.Memory;
p2 := Stream2.Memory;
for i := 0 to Stream1.Size - 1 do
begin
CheckEquals(p1^, p2^, 'Stream contents at byte ' + IntToStr(i) + ' should match');
Inc(p1);
Inc(p2);
end;
NewTable2.Assign(ZapfTable);
NewTable2.SaveToStream(Stream3);
CheckEquals(Stream1.Size, Stream3.Size, 'Assigned stream sizes should match');
p1 := Stream1.Memory;
p2 := Stream3.Memory;
for i := 0 to Stream1.Size - 1 do
begin
CheckEquals(p1^, p2^, 'Assigned stream contents at byte ' + IntToStr(i) + ' should match');
Inc(p1);
Inc(p2);
end;
finally
NewTable1.Free;
NewTable2.Free;
Stream1.Free;
Stream2.Free;
Stream3.Free;
end;
end;
initialization
TestSuiteFontFace.AddSuite(TTestPascalTypeFontFaceApple.Suite);
end.