diff --git a/tests/tests/swfs/fonts/device_font_list/Test.as b/tests/tests/swfs/fonts/device_font_list/Test.as new file mode 100644 index 000000000000..32a190f192cd --- /dev/null +++ b/tests/tests/swfs/fonts/device_font_list/Test.as @@ -0,0 +1,106 @@ +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 = "abc"; + + addChild(text); + + 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); + + 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) {} + } +} +} diff --git a/tests/tests/swfs/fonts/device_font_list/TestFontA.sfd b/tests/tests/swfs/fonts/device_font_list/TestFontA.sfd new file mode 100644 index 000000000000..abd3c3249485 --- /dev/null +++ b/tests/tests/swfs/fonts/device_font_list/TestFontA.sfd @@ -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 diff --git a/tests/tests/swfs/fonts/device_font_list/TestFontA.ttf b/tests/tests/swfs/fonts/device_font_list/TestFontA.ttf new file mode 100644 index 000000000000..bc68e32831c6 Binary files /dev/null and b/tests/tests/swfs/fonts/device_font_list/TestFontA.ttf differ diff --git a/tests/tests/swfs/fonts/device_font_list/TestFontB.sfd b/tests/tests/swfs/fonts/device_font_list/TestFontB.sfd new file mode 100644 index 000000000000..586e531b3d3a --- /dev/null +++ b/tests/tests/swfs/fonts/device_font_list/TestFontB.sfd @@ -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 diff --git a/tests/tests/swfs/fonts/device_font_list/TestFontB.ttf b/tests/tests/swfs/fonts/device_font_list/TestFontB.ttf new file mode 100644 index 000000000000..2a3252194969 Binary files /dev/null and b/tests/tests/swfs/fonts/device_font_list/TestFontB.ttf differ diff --git a/tests/tests/swfs/fonts/device_font_list/output.txt b/tests/tests/swfs/fonts/device_font_list/output.txt new file mode 100644 index 000000000000..0735b72c6ae0 --- /dev/null +++ b/tests/tests/swfs/fonts/device_font_list/output.txt @@ -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 diff --git a/tests/tests/swfs/fonts/device_font_list/test.swf b/tests/tests/swfs/fonts/device_font_list/test.swf new file mode 100644 index 000000000000..c2047980a853 Binary files /dev/null and b/tests/tests/swfs/fonts/device_font_list/test.swf differ diff --git a/tests/tests/swfs/fonts/device_font_list/test.toml b/tests/tests/swfs/fonts/device_font_list/test.toml new file mode 100644 index 000000000000..fdd8414b3064 --- /dev/null +++ b/tests/tests/swfs/fonts/device_font_list/test.toml @@ -0,0 +1,9 @@ +num_ticks = 1 + +[fonts.a] +family = "TestFontA" +path = "TestFontA.ttf" + +[fonts.b] +family = "TestFontB" +path = "TestFontB.ttf"