-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestKernFormat2.pas
More file actions
138 lines (117 loc) · 3.54 KB
/
TestKernFormat2.pas
File metadata and controls
138 lines (117 loc) · 3.54 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
unit TestKernFormat2;
interface
uses
TestFramework,
PascalType.Types,
PascalType.Classes,
PascalType.FontFace.SFNT,
PascalType.Shaper,
PascalType.GlyphString,
PascalType.Unicode;
type
TTestKernFormat2 = class(TTestCase)
private
FFontFace: TPascalTypeFontFace;
public
procedure SetUp; override;
procedure TearDown; override;
published
procedure TestKernAV;
procedure TestKernAlphabet;
end;
implementation
uses
System.SysUtils,
System.IOUtils;
{ TTestKernFormat2 }
procedure TTestKernFormat2.SetUp;
begin
inherited;
FFontFace := TPascalTypeFontFace.Create;
var FontPath := TPath.Combine(ExtractFilePath(ParamStr(0)), '..\Data\in-house\fonts\e39391c77a6321c2ac7a2d644de0396470cd4bfe.ttf');
if not TFile.Exists(FontPath) then
Fail('Font file not found: ' + FontPath);
FFontFace.LoadFromFile(FontPath);
end;
procedure TTestKernFormat2.TearDown;
begin
FFontFace.Free;
inherited;
end;
procedure TTestKernFormat2.TestKernAV;
var
Shaper: TPascalTypeShaper;
Glyphs: TPascalTypeGlyphString;
CodePoints: TPascalTypeCodePoints;
begin
SetLength(CodePoints, 2);
CodePoints[0] := $0041; // A
CodePoints[1] := $0056; // V
Shaper := TPascalTypeShaper.CreateShaper(FFontFace, 'latn');
try
Shaper.UserFeatures^['kern'] := True;
Glyphs := Shaper.TextToGlyphs(CodePoints);
try
Shaper.Shape(Glyphs);
// Harfbuzz expected: [A=0+701|V=1@-40,0+703]
// A (GID 36) original advance: 741.
// V (GID 57) original advance: 743.
// A-V kern delta in subtable 2 is -80.
// v2 = -80 div 2 = -40. v1 = -80 - (-40) = -40.
// A XAdvance: 741 - 40 = 701.
// V XOffset: 0 - 40 = -40.
// V XAdvance: 743 - 40 = 703.
CheckEquals(701, Glyphs[0].XAdvance, 'A XAdvance');
CheckEquals(-40, Glyphs[1].XOffset, 'V XOffset');
CheckEquals(703, Glyphs[1].XAdvance, 'V XAdvance');
finally
Glyphs.Free;
end;
finally
Shaper.Free;
end;
end;
procedure TTestKernFormat2.TestKernAlphabet;
var
Shaper: TPascalTypeShaper;
Glyphs: TPascalTypeGlyphString;
CodePoints: TPascalTypeCodePoints;
Input: string;
begin
Input := 'abcdefghijklmnop';
CodePoints := PascalTypeUnicode.UTF16ToUTF32(Input);
Shaper := TPascalTypeShaper.CreateShaper(FFontFace, 'latn');
try
Shaper.UserFeatures^['kern'] := True;
Glyphs := Shaper.TextToGlyphs(CodePoints);
try
Shaper.Shape(Glyphs);
// Harfbuzz expected: [a=0+626|b=1+672|c=2+564|d=3@-15,0+657|e=4+621|f=5+403|g=6@-10,0+662|h=7+666|i=8+316|j=9+316|k=10+591|l=11+316|m=12+1021|n=13+666|o=14+644|p=15+672]
// c (GID 69) original advance 579. d (GID 70) original advance 672.
// c-d kern delta in subtable 1 is -30.
// v2 = -15, v1 = -15.
// c XAdvance: 579 - 15 = 564.
// d XOffset: 0 - 15 = -15.
// d XAdvance: 672 - 15 = 657.
CheckEquals(564, Glyphs[2].XAdvance, 'c XAdvance');
CheckEquals(-15, Glyphs[3].XOffset, 'd XOffset');
CheckEquals(657, Glyphs[3].XAdvance, 'd XAdvance');
// f (GID 72) original advance 413. g (GID 73) original advance 672.
// f-g kern delta in subtable 1 is -20.
// v2 = -10, v1 = -10.
// f XAdvance: 413 - 10 = 403.
// g XOffset: 0 - 10 = -10.
// g XAdvance: 672 - 10 = 662.
CheckEquals(403, Glyphs[5].XAdvance, 'f XAdvance');
CheckEquals(-10, Glyphs[6].XOffset, 'g XOffset');
CheckEquals(662, Glyphs[6].XAdvance, 'g XAdvance');
finally
Glyphs.Free;
end;
finally
Shaper.Free;
end;
end;
initialization
RegisterTest(TTestKernFormat2.Suite);
end.