Skip to content

Commit

Permalink
tests: Add fonts/device_font_list test
Browse files Browse the repository at this point in the history
This test verifies the behavior of styling with a list of fonts.
  • Loading branch information
kjarosh committed Jan 18, 2025
1 parent 3cf3206 commit 3bb449a
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 0 deletions.
114 changes: 114 additions & 0 deletions tests/tests/swfs/fonts/device_font_list/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package {
import flash.display.*;
import flash.text.*;

[SWF(width="100", height="200")]
public class Test extends Sprite {
[Embed(source="TestFontA.ttf", fontName="EmbeddedTestFontA", embedAsCFF="false", unicodeRange="U+0061-U+0064")]
private var EmbeddedTestFontA:Class;

[Embed(source="TestFontB.ttf", fontName="EmbeddedTestFontB", embedAsCFF="false", unicodeRange="U+0061-U+0064")]
private var EmbeddedTestFontB:Class;

private var nextY: Number = 0;

private var fontListsDevice: Array = [
"Totally Unknown, TestFontA , TestFontB",
" testFOntB , TestFontA , TestFontB",
];
private var fontListsEmbedded: Array = [
"Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB",
"EmbeddedTestFontA",
" EmbeddedTestFontA",
"EmbeddedTestFontA ",
" EmbeddedTestFontA ",
" embeddedTESTFonta",
];

public function Test() {
stage.scaleMode = "noScale";

for each (var embedded in [false, true]) {
var fontLists = embedded ? fontListsEmbedded : fontListsDevice;
for each (var fontList in fontLists) {
testFontListCss(embedded, fontList);
testFontListFormat(embedded, fontList);
}
}
}

function testFontListCss(embedded: Boolean, fontList: String) {
trace("Testing CSS font list fallback:");
trace(" Embedded? = " + embedded);
trace(" Font list? = " + fontList);

var style: StyleSheet = new StyleSheet();

var classFontList:Object = new Object();
classFontList.fontFamily = fontList;
classFontList.fontSize = 20;
style.setStyle(".fontlist", classFontList);

var text: TextField = new TextField();
text.embedFonts = embedded;
text.styleSheet = style;

text.width = 100;
text.height = 50;
text.y = nextY;
nextY += text.height;
text.text = "<span class='fontlist'>abc</span>";

addChild(text);

if (text.getCharBoundaries(2) == null) {
return;
}

traceChars(text);
}

function testFontListFormat(embedded: Boolean, fontList: String) {
trace("Testing TextFormat font list fallback:");
trace(" Embedded? = " + embedded);
trace(" Font list? = " + fontList);

var tf: TextFormat = new TextFormat(fontList, 20);
var text: TextField = new TextField();
text.embedFonts = embedded;
text.defaultTextFormat = tf;

text.width = 100;
text.height = 50;
text.y = nextY;
nextY += text.height;
text.text = "abc";

addChild(text);

if (text.getCharBoundaries(2) == null) {
return;
}

traceChars(text);
}

private function traceChars(text: TextField) {
traceChar(text, 0);
traceChar(text, 1);
traceChar(text, 2);
}

private function traceChar(text: TextField, i: int) {
try {
var ch: Number = text.getCharBoundaries(i).width;
if (ch == 32) {
trace(" Char " + i + " is TestFontA");
}
if (ch == 30) {
trace(" Char " + i + " is TestFontB");
}
} catch(e) {}
}
}
}
88 changes: 88 additions & 0 deletions tests/tests/swfs/fonts/device_font_list/TestFontA.sfd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
SplineFontDB: 3.2
FontName: TestFontA
FullName: TestFontA
FamilyName: TestFontA
Weight: Regular
Copyright: Copyright (c) 2024, Kamil Jarosz
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)"
Version: 001.000
ItalicAngle: 0
UnderlinePosition: -76
UnderlineWidth: 38
Ascent: 800
Descent: 200
InvalidEm: 0
LayerCount: 2
Layer: 0 0 "Back" 1
Layer: 1 0 "Fore" 0
XUID: [1021 253 198287149 6396829]
StyleMap: 0x0000
FSType: 0
OS2Version: 0
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 1
CreationTime: 1721856925
ModificationTime: 1737156144
PfmFamily: 17
TTFWeight: 400
TTFWidth: 5
LineGap: 100
VLineGap: 0
OS2TypoAscent: 0
OS2TypoAOffset: 1
OS2TypoDescent: 0
OS2TypoDOffset: 1
OS2TypoLinegap: 100
OS2WinAscent: 0
OS2WinAOffset: 1
OS2WinDescent: 0
OS2WinDOffset: 1
HheadAscent: 0
HheadAOffset: 1
HheadDescent: 0
HheadDOffset: 1
OS2Vendor: 'PfEd'
MarkAttachClasses: 1
DEI: 91125
Encoding: ISO8859-1
UnicodeInterp: none
NameList: AGL For New Fonts
DisplaySize: -48
AntiAlias: 1
FitToEm: 0
WinInfo: 0 30 10
BeginPrivate: 0
EndPrivate
BeginChars: 256 2

StartChar: a
Encoding: 97 97 0
Width: 1600
Flags: HW
LayerCount: 2
Fore
SplineSet
0 800 m 1
1600 800 l 1
1600 0 l 1
0 0 l 1
0 800 l 1
EndSplineSet
EndChar

StartChar: c
Encoding: 99 99 1
Width: 1600
Flags: HW
LayerCount: 2
Fore
SplineSet
0 800 m 1
1600 800 l 1
1600 0 l 1
0 0 l 1
0 800 l 1
EndSplineSet
EndChar
EndChars
EndSplineFont
Binary file not shown.
88 changes: 88 additions & 0 deletions tests/tests/swfs/fonts/device_font_list/TestFontB.sfd
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
SplineFontDB: 3.2
FontName: TestFontB
FullName: TestFontB
FamilyName: TestFontB
Weight: Regular
Copyright: Copyright (c) 2024, Kamil Jarosz
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)"
Version: 001.000
ItalicAngle: 0
UnderlinePosition: -76
UnderlineWidth: 38
Ascent: 800
Descent: 200
InvalidEm: 0
LayerCount: 2
Layer: 0 0 "Back" 1
Layer: 1 0 "Fore" 0
XUID: [1021 253 198287149 6396829]
StyleMap: 0x0000
FSType: 0
OS2Version: 0
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 1
CreationTime: 1721856925
ModificationTime: 1737156185
PfmFamily: 17
TTFWeight: 400
TTFWidth: 5
LineGap: 100
VLineGap: 0
OS2TypoAscent: 0
OS2TypoAOffset: 1
OS2TypoDescent: 0
OS2TypoDOffset: 1
OS2TypoLinegap: 100
OS2WinAscent: 0
OS2WinAOffset: 1
OS2WinDescent: 0
OS2WinDOffset: 1
HheadAscent: 0
HheadAOffset: 1
HheadDescent: 0
HheadDOffset: 1
OS2Vendor: 'PfEd'
MarkAttachClasses: 1
DEI: 91125
Encoding: ISO8859-1
UnicodeInterp: none
NameList: AGL For New Fonts
DisplaySize: -48
AntiAlias: 1
FitToEm: 0
WinInfo: 0 30 10
BeginPrivate: 0
EndPrivate
BeginChars: 256 2

StartChar: b
Encoding: 98 98 0
Width: 1500
Flags: HW
LayerCount: 2
Fore
SplineSet
0 0 m 1
1500 0 l 5
1500 -200 l 5
0 -200 l 1
0 0 l 1
EndSplineSet
EndChar

StartChar: c
Encoding: 99 99 1
Width: 1500
Flags: HW
LayerCount: 2
Fore
SplineSet
0 0 m 1
1500 0 l 5
1500 -200 l 5
0 -200 l 1
0 0 l 1
EndSplineSet
EndChar
EndChars
EndSplineFont
Binary file not shown.
64 changes: 64 additions & 0 deletions tests/tests/swfs/fonts/device_font_list/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
Testing CSS font list fallback:
Embedded? = false
Font list? = Totally Unknown, TestFontA , TestFontB
Char 0 is TestFontA
Char 2 is TestFontA
Testing TextFormat font list fallback:
Embedded? = false
Font list? = Totally Unknown, TestFontA , TestFontB
Char 0 is TestFontA
Char 2 is TestFontA
Testing CSS font list fallback:
Embedded? = false
Font list? = testFOntB , TestFontA , TestFontB
Char 1 is TestFontB
Char 2 is TestFontB
Testing TextFormat font list fallback:
Embedded? = false
Font list? = testFOntB , TestFontA , TestFontB
Char 1 is TestFontB
Char 2 is TestFontB
Testing CSS font list fallback:
Embedded? = true
Font list? = Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB
Testing TextFormat font list fallback:
Embedded? = true
Font list? = Totally Unknown, EmbeddedTestFontA, EmbeddedTestFontB
Testing CSS font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Char 0 is TestFontA
Char 2 is TestFontA
Testing TextFormat font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Char 0 is TestFontA
Char 2 is TestFontA
Testing CSS font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Char 0 is TestFontA
Char 2 is TestFontA
Testing TextFormat font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Testing CSS font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Testing TextFormat font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Testing CSS font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Testing TextFormat font list fallback:
Embedded? = true
Font list? = EmbeddedTestFontA
Testing CSS font list fallback:
Embedded? = true
Font list? = embeddedTESTFonta
Char 0 is TestFontA
Char 2 is TestFontA
Testing TextFormat font list fallback:
Embedded? = true
Font list? = embeddedTESTFonta
Binary file added tests/tests/swfs/fonts/device_font_list/test.swf
Binary file not shown.
9 changes: 9 additions & 0 deletions tests/tests/swfs/fonts/device_font_list/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
num_ticks = 1

[fonts.a]
family = "TestFontA"
path = "TestFontA.ttf"

[fonts.b]
family = "TestFontB"
path = "TestFontB.ttf"

0 comments on commit 3bb449a

Please sign in to comment.