-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNonBreakingHyphen.pas
More file actions
152 lines (134 loc) · 3.73 KB
/
TestNonBreakingHyphen.pas
File metadata and controls
152 lines (134 loc) · 3.73 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
unit TestNonBreakingHyphen;
interface
uses
TestFramework,
PascalType.Types,
PascalType.Classes,
PascalType.FontFace.SFNT,
PascalType.Shaper,
PascalType.Shaper.Script.Default;
type
TTestNonBreakingHyphen = class(TTestCase)
published
procedure TestNonBreakingHyphen;
procedure TestSpecialSpaces;
end;
implementation
uses
System.SysUtils,
PascalType.Unicode;
type
TTestShaper = class(TPascalTypeDefaultShaper);
type
TMockFontFace = class(TPascalTypeFontFace)
private
FSupportedCodePoints: TArray<TPascalTypeCodePoint>;
public
constructor Create(const ASupportedCodePoints: TArray<TPascalTypeCodePoint>); reintroduce;
function GetGlyphByCodePoint(ACodePoint: TPascalTypeCodePoint): Integer; override;
end;
constructor TMockFontFace.Create(const ASupportedCodePoints: TArray<TPascalTypeCodePoint>);
begin
inherited Create;
FSupportedCodePoints := ASupportedCodePoints;
end;
function TMockFontFace.GetGlyphByCodePoint(ACodePoint: TPascalTypeCodePoint): Integer;
begin
for var CP in FSupportedCodePoints do
if CP = ACodePoint then
Exit(1); // Return some valid glyph ID
Result := GlyphNotDef;
end;
{ TTestNonBreakingHyphen }
procedure TTestNonBreakingHyphen.TestNonBreakingHyphen;
var
FontFace: TMockFontFace;
Shaper: TTestShaper;
CodePoints: TPascalTypeCodePoints;
begin
// Case 1: Font supports U+2011
FontFace := TMockFontFace.Create([$2011]);
try
Shaper := TTestShaper.Create(FontFace);
try
SetLength(CodePoints, 1);
CodePoints[0] := $2011;
Shaper.ProcessCodePoints(CodePoints);
CheckEquals(Cardinal($2011), Cardinal(CodePoints[0]), 'U+2011 should be preserved if supported by font');
finally
Shaper.Free;
end;
finally
FontFace.Free;
end;
// Case 2: Font missing U+2011, supports U+2010
FontFace := TMockFontFace.Create([$2010]);
try
Shaper := TTestShaper.Create(FontFace);
try
SetLength(CodePoints, 1);
CodePoints[0] := $2011;
Shaper.ProcessCodePoints(CodePoints);
CheckEquals(Cardinal($2010), Cardinal(CodePoints[0]), 'U+2011 should fall back to U+2010 if supported');
finally
Shaper.Free;
end;
finally
FontFace.Free;
end;
// Case 3: Font missing U+2011 and U+2010, supports U+002D
FontFace := TMockFontFace.Create([$002D]);
try
Shaper := TTestShaper.Create(FontFace);
try
SetLength(CodePoints, 1);
CodePoints[0] := $2011;
Shaper.ProcessCodePoints(CodePoints);
CheckEquals(Cardinal($002D), Cardinal(CodePoints[0]), 'U+2011 should fall back to U+002D if U+2010 is missing');
finally
Shaper.Free;
end;
finally
FontFace.Free;
end;
end;
procedure TTestNonBreakingHyphen.TestSpecialSpaces;
var
FontFace: TMockFontFace;
Shaper: TTestShaper;
CodePoints: TPascalTypeCodePoints;
begin
// Case 1: Font supports U+00A0 (Non-breaking space)
FontFace := TMockFontFace.Create([$00A0]);
try
Shaper := TTestShaper.Create(FontFace);
try
SetLength(CodePoints, 1);
CodePoints[0] := $00A0;
Shaper.ProcessCodePoints(CodePoints);
CheckEquals(Cardinal($00A0), Cardinal(CodePoints[0]), 'U+00A0 should be preserved if supported by font');
finally
Shaper.Free;
end;
finally
FontFace.Free;
end;
// Case 2: Font missing U+00A0, supports U+0020
FontFace := TMockFontFace.Create([$0020]);
try
Shaper := TTestShaper.Create(FontFace);
try
SetLength(CodePoints, 1);
CodePoints[0] := $00A0;
Shaper.ProcessCodePoints(CodePoints);
CheckEquals(Cardinal($0020), Cardinal(CodePoints[0]), 'U+00A0 should fall back to U+0020 if missing');
finally
Shaper.Free;
end;
finally
FontFace.Free;
end;
end;
initialization
RegisterTest(TTestNonBreakingHyphen.Suite);
end.