Skip to content

Commit 609d095

Browse files
committed
tests: Add fonts/device_font_list test
This test verifies the behavior of styling with a list of fonts.
1 parent 626513b commit 609d095

File tree

8 files changed

+355
-0
lines changed

8 files changed

+355
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package {
2+
import flash.display.*;
3+
import flash.text.*;
4+
5+
[SWF(width="100", height="200")]
6+
public class Test extends Sprite {
7+
[Embed(source="TestFontA.ttf", fontName="EmbeddedTestFontA", embedAsCFF="false", unicodeRange="U+0061-U+0064")]
8+
private var EmbeddedTestFontA:Class;
9+
10+
[Embed(source="TestFontB.ttf", fontName="EmbeddedTestFontB", embedAsCFF="false", unicodeRange="U+0061-U+0064")]
11+
private var EmbeddedTestFontB:Class;
12+
13+
private var nextY: Number = 0;
14+
15+
private var fontListsDevice: Array = [
16+
"Totally Unknown, TestFontA , TestFontB",
17+
" testFOntB , TestFontA , TestFontB",
18+
];
19+
private var fontListsEmbedded: Array = [
20+
"Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB",
21+
"EmbeddedTestFontA",
22+
" EmbeddedTestFontA",
23+
"EmbeddedTestFontA ",
24+
" EmbeddedTestFontA ",
25+
" embeddedTESTFonta",
26+
];
27+
28+
public function Test() {
29+
stage.scaleMode = "noScale";
30+
31+
for each (var embedded in [false, true]) {
32+
var fontLists = embedded ? fontListsEmbedded : fontListsDevice;
33+
for each (var fontList in fontLists) {
34+
testFontListCss(embedded, fontList);
35+
testFontListFormat(embedded, fontList);
36+
}
37+
}
38+
}
39+
40+
function testFontListCss(embedded: Boolean, fontList: String) {
41+
trace("Testing CSS font list fallback:");
42+
trace(" Embedded? = " + embedded);
43+
trace(" Font list? = " + fontList);
44+
45+
var style: StyleSheet = new StyleSheet();
46+
47+
var classFontList:Object = new Object();
48+
classFontList.fontFamily = fontList;
49+
classFontList.fontSize = 20;
50+
style.setStyle(".fontlist", classFontList);
51+
52+
var text: TextField = new TextField();
53+
text.embedFonts = embedded;
54+
text.styleSheet = style;
55+
56+
text.width = 100;
57+
text.height = 50;
58+
text.y = nextY;
59+
nextY += text.height;
60+
text.text = "<span class='fontlist'>abc</span>";
61+
62+
addChild(text);
63+
64+
traceChars(text);
65+
}
66+
67+
function testFontListFormat(embedded: Boolean, fontList: String) {
68+
trace("Testing TextFormat font list fallback:");
69+
trace(" Embedded? = " + embedded);
70+
trace(" Font list? = " + fontList);
71+
72+
var tf: TextFormat = new TextFormat(fontList, 20);
73+
var text: TextField = new TextField();
74+
text.embedFonts = embedded;
75+
text.defaultTextFormat = tf;
76+
77+
text.width = 100;
78+
text.height = 50;
79+
text.y = nextY;
80+
nextY += text.height;
81+
text.text = "abc";
82+
83+
addChild(text);
84+
85+
traceChars(text);
86+
}
87+
88+
private function traceChars(text: TextField) {
89+
traceChar(text, 0);
90+
traceChar(text, 1);
91+
traceChar(text, 2);
92+
}
93+
94+
private function traceChar(text: TextField, i: int) {
95+
try {
96+
var ch: Number = text.getCharBoundaries(i).width;
97+
if (ch == 32) {
98+
trace(" Char " + i + " is TestFontA");
99+
}
100+
if (ch == 30) {
101+
trace(" Char " + i + " is TestFontB");
102+
}
103+
} catch(e) {}
104+
}
105+
}
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SplineFontDB: 3.2
2+
FontName: TestFontA
3+
FullName: TestFontA
4+
FamilyName: TestFontA
5+
Weight: Regular
6+
Copyright: Copyright (c) 2024, Kamil Jarosz
7+
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)"
8+
Version: 001.000
9+
ItalicAngle: 0
10+
UnderlinePosition: -76
11+
UnderlineWidth: 38
12+
Ascent: 800
13+
Descent: 200
14+
InvalidEm: 0
15+
LayerCount: 2
16+
Layer: 0 0 "Back" 1
17+
Layer: 1 0 "Fore" 0
18+
XUID: [1021 253 198287149 6396829]
19+
StyleMap: 0x0000
20+
FSType: 0
21+
OS2Version: 0
22+
OS2_WeightWidthSlopeOnly: 0
23+
OS2_UseTypoMetrics: 1
24+
CreationTime: 1721856925
25+
ModificationTime: 1737156144
26+
PfmFamily: 17
27+
TTFWeight: 400
28+
TTFWidth: 5
29+
LineGap: 100
30+
VLineGap: 0
31+
OS2TypoAscent: 0
32+
OS2TypoAOffset: 1
33+
OS2TypoDescent: 0
34+
OS2TypoDOffset: 1
35+
OS2TypoLinegap: 100
36+
OS2WinAscent: 0
37+
OS2WinAOffset: 1
38+
OS2WinDescent: 0
39+
OS2WinDOffset: 1
40+
HheadAscent: 0
41+
HheadAOffset: 1
42+
HheadDescent: 0
43+
HheadDOffset: 1
44+
OS2Vendor: 'PfEd'
45+
MarkAttachClasses: 1
46+
DEI: 91125
47+
Encoding: ISO8859-1
48+
UnicodeInterp: none
49+
NameList: AGL For New Fonts
50+
DisplaySize: -48
51+
AntiAlias: 1
52+
FitToEm: 0
53+
WinInfo: 0 30 10
54+
BeginPrivate: 0
55+
EndPrivate
56+
BeginChars: 256 2
57+
58+
StartChar: a
59+
Encoding: 97 97 0
60+
Width: 1600
61+
Flags: HW
62+
LayerCount: 2
63+
Fore
64+
SplineSet
65+
0 800 m 1
66+
1600 800 l 1
67+
1600 0 l 1
68+
0 0 l 1
69+
0 800 l 1
70+
EndSplineSet
71+
EndChar
72+
73+
StartChar: c
74+
Encoding: 99 99 1
75+
Width: 1600
76+
Flags: HW
77+
LayerCount: 2
78+
Fore
79+
SplineSet
80+
0 800 m 1
81+
1600 800 l 1
82+
1600 0 l 1
83+
0 0 l 1
84+
0 800 l 1
85+
EndSplineSet
86+
EndChar
87+
EndChars
88+
EndSplineFont
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
SplineFontDB: 3.2
2+
FontName: TestFontB
3+
FullName: TestFontB
4+
FamilyName: TestFontB
5+
Weight: Regular
6+
Copyright: Copyright (c) 2024, Kamil Jarosz
7+
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)"
8+
Version: 001.000
9+
ItalicAngle: 0
10+
UnderlinePosition: -76
11+
UnderlineWidth: 38
12+
Ascent: 800
13+
Descent: 200
14+
InvalidEm: 0
15+
LayerCount: 2
16+
Layer: 0 0 "Back" 1
17+
Layer: 1 0 "Fore" 0
18+
XUID: [1021 253 198287149 6396829]
19+
StyleMap: 0x0000
20+
FSType: 0
21+
OS2Version: 0
22+
OS2_WeightWidthSlopeOnly: 0
23+
OS2_UseTypoMetrics: 1
24+
CreationTime: 1721856925
25+
ModificationTime: 1737156185
26+
PfmFamily: 17
27+
TTFWeight: 400
28+
TTFWidth: 5
29+
LineGap: 100
30+
VLineGap: 0
31+
OS2TypoAscent: 0
32+
OS2TypoAOffset: 1
33+
OS2TypoDescent: 0
34+
OS2TypoDOffset: 1
35+
OS2TypoLinegap: 100
36+
OS2WinAscent: 0
37+
OS2WinAOffset: 1
38+
OS2WinDescent: 0
39+
OS2WinDOffset: 1
40+
HheadAscent: 0
41+
HheadAOffset: 1
42+
HheadDescent: 0
43+
HheadDOffset: 1
44+
OS2Vendor: 'PfEd'
45+
MarkAttachClasses: 1
46+
DEI: 91125
47+
Encoding: ISO8859-1
48+
UnicodeInterp: none
49+
NameList: AGL For New Fonts
50+
DisplaySize: -48
51+
AntiAlias: 1
52+
FitToEm: 0
53+
WinInfo: 0 30 10
54+
BeginPrivate: 0
55+
EndPrivate
56+
BeginChars: 256 2
57+
58+
StartChar: b
59+
Encoding: 98 98 0
60+
Width: 1500
61+
Flags: HW
62+
LayerCount: 2
63+
Fore
64+
SplineSet
65+
0 0 m 1
66+
1500 0 l 5
67+
1500 -200 l 5
68+
0 -200 l 1
69+
0 0 l 1
70+
EndSplineSet
71+
EndChar
72+
73+
StartChar: c
74+
Encoding: 99 99 1
75+
Width: 1500
76+
Flags: HW
77+
LayerCount: 2
78+
Fore
79+
SplineSet
80+
0 0 m 1
81+
1500 0 l 5
82+
1500 -200 l 5
83+
0 -200 l 1
84+
0 0 l 1
85+
EndSplineSet
86+
EndChar
87+
EndChars
88+
EndSplineFont
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Testing CSS font list fallback:
2+
Embedded? = false
3+
Font list? = Totally Unknown, TestFontA , TestFontB
4+
Char 0 is TestFontA
5+
Char 2 is TestFontA
6+
Testing TextFormat font list fallback:
7+
Embedded? = false
8+
Font list? = Totally Unknown, TestFontA , TestFontB
9+
Char 0 is TestFontA
10+
Char 2 is TestFontA
11+
Testing CSS font list fallback:
12+
Embedded? = false
13+
Font list? = testFOntB , TestFontA , TestFontB
14+
Char 1 is TestFontB
15+
Char 2 is TestFontB
16+
Testing TextFormat font list fallback:
17+
Embedded? = false
18+
Font list? = testFOntB , TestFontA , TestFontB
19+
Char 1 is TestFontB
20+
Char 2 is TestFontB
21+
Testing CSS font list fallback:
22+
Embedded? = true
23+
Font list? = Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB
24+
Testing TextFormat font list fallback:
25+
Embedded? = true
26+
Font list? = Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB
27+
Testing CSS font list fallback:
28+
Embedded? = true
29+
Font list? = EmbeddedTestFontA
30+
Char 0 is TestFontA
31+
Char 2 is TestFontA
32+
Testing TextFormat font list fallback:
33+
Embedded? = true
34+
Font list? = EmbeddedTestFontA
35+
Char 0 is TestFontA
36+
Char 2 is TestFontA
37+
Testing CSS font list fallback:
38+
Embedded? = true
39+
Font list? = EmbeddedTestFontA
40+
Char 0 is TestFontA
41+
Char 2 is TestFontA
42+
Testing TextFormat font list fallback:
43+
Embedded? = true
44+
Font list? = EmbeddedTestFontA
45+
Testing CSS font list fallback:
46+
Embedded? = true
47+
Font list? = EmbeddedTestFontA
48+
Testing TextFormat font list fallback:
49+
Embedded? = true
50+
Font list? = EmbeddedTestFontA
51+
Testing CSS font list fallback:
52+
Embedded? = true
53+
Font list? = EmbeddedTestFontA
54+
Testing TextFormat font list fallback:
55+
Embedded? = true
56+
Font list? = EmbeddedTestFontA
57+
Testing CSS font list fallback:
58+
Embedded? = true
59+
Font list? = embeddedTESTFonta
60+
Char 0 is TestFontA
61+
Char 2 is TestFontA
62+
Testing TextFormat font list fallback:
63+
Embedded? = true
64+
Font list? = embeddedTESTFonta
2.74 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
num_ticks = 1
2+
3+
[fonts.a]
4+
family = "TestFontA"
5+
path = "TestFontA.ttf"
6+
7+
[fonts.b]
8+
family = "TestFontB"
9+
path = "TestFontB.ttf"

0 commit comments

Comments
 (0)