-
-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add avm2/edittext_line_metrics test
This test verifies the behavior of TextField.getLineMetrics().
- Loading branch information
Showing
9 changed files
with
314 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package { | ||
import flash.display.Sprite; | ||
import flash.text.TextField; | ||
import flash.text.TextFormat; | ||
import flash.text.TextLineMetrics; | ||
|
||
[SWF(width="300", height="300")] | ||
public class Test extends Sprite { | ||
[Embed(source="NotoSans.ttf", fontName="Noto Sans", embedAsCFF="false", unicodeRange="U+0020-U+007E")] | ||
private var notoSans:Class; | ||
|
||
[Embed(source="TestFont.ttf", fontName="TestFont", embedAsCFF="false", unicodeRange="U+0061-U+0064")] | ||
private var testFont:Class; | ||
|
||
[Embed(source="TestFontDefault.ttf", fontName="TestFontDefault", embedAsCFF="false", unicodeRange="U+0061-U+0064")] | ||
private var testFontDefault:Class; | ||
|
||
private var text:TextField; | ||
|
||
public function Test() { | ||
stage.scaleMode = "noScale"; | ||
text = new TextField(); | ||
text.border = true; | ||
text.x = 10; | ||
text.y = 10; | ||
text.width = 280; | ||
text.height = 280; | ||
text.multiline = true; | ||
text.embedFonts = true; | ||
text.wordWrap = true; | ||
var tf = new TextFormat(); | ||
tf.font = "TestFontDefault"; | ||
text.defaultTextFormat = tf; | ||
addChild(text); | ||
|
||
text.htmlText = ""; | ||
text.htmlText += "<font face='TestFont'>acbd</font>\n"; | ||
text.htmlText += "<font face='Noto Sans'>acbd</font>\n"; | ||
text.htmlText += "\n"; | ||
text.htmlText += "<font face='TestFont'>acbd</font><font face='Noto Sans'>mixed fonts</font>\n"; | ||
text.htmlText += "<font face='Noto Sans'><font size='+2'>mixed</font> <font size='-2'>sizes</font></font>\n"; | ||
text.htmlText += "<textformat leading='5'><font face='TestFont'>acbd</font><font face='Noto Sans'>leading</font></textformat>\n"; | ||
text.htmlText += "<textformat leading='4'><font face='Noto Sans'>line so long that it will need to break at some point</font> <font face='TestFont'>acbd</font></textformat>\n"; | ||
// TODO add cases for alignment (when it's fixed) | ||
|
||
for (var i = -1; i <= 9; ++i) { | ||
trace("text.getLineMetrics(" + i + ") = " + testMetrics(i)); | ||
} | ||
} | ||
|
||
private function testMetrics(i:int):String { | ||
try { | ||
return metricsToStr(text.getLineMetrics(i)); | ||
} catch(e) { | ||
return "" + e; | ||
} | ||
return ""; | ||
} | ||
|
||
private function metricsToStr(metrics:TextLineMetrics):String { | ||
return "ascent=" + metrics.ascent + ", descent=" + metrics.descent + ", leading=" + metrics.leading + ", width=" + metrics.width + ", height=" + metrics.height + ", x=" + metrics.x; | ||
} | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
tests/tests/swfs/avm2/edittext_line_metrics/TestFont.sfd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
SplineFontDB: 3.2 | ||
FontName: TestFont | ||
FullName: TestFont | ||
FamilyName: TestFont | ||
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.6667 | ||
UnderlineWidth: 38.3333 | ||
Ascent: 500 | ||
Descent: 500 | ||
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: 1729718098 | ||
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 4 | ||
|
||
StartChar: a | ||
Encoding: 97 97 0 | ||
Width: 800 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 500 m 5 | ||
800 500 l 5 | ||
800 0 l 1 | ||
0 0 l 1 | ||
0 500 l 5 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: b | ||
Encoding: 98 98 1 | ||
Width: 108 | ||
VWidth: 1083 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 500 m 5 | ||
108 500 l 5 | ||
108 0 l 1 | ||
0 0 l 1 | ||
0 500 l 5 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: c | ||
Encoding: 99 99 2 | ||
Width: 800 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 0 m 1 | ||
800 0 l 1 | ||
800 -500 l 5 | ||
0 -500 l 5 | ||
0 0 l 1 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: d | ||
Encoding: 100 100 3 | ||
Width: 100 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 0 m 1 | ||
100 0 l 1 | ||
100 -500 l 1 | ||
0 -500 l 1 | ||
0 0 l 1 | ||
EndSplineSet | ||
EndChar | ||
EndChars | ||
EndSplineFont |
Binary file not shown.
119 changes: 119 additions & 0 deletions
119
tests/tests/swfs/avm2/edittext_line_metrics/TestFontDefault.sfd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
SplineFontDB: 3.2 | ||
FontName: TestFontDefault | ||
FullName: TestFontDefault | ||
FamilyName: TestFontDefault | ||
Weight: Regular | ||
Copyright: Copyright (c) 2024, Kamil Jarosz | ||
UComments: "2024-7-24: Created with FontForge (http://fontforge.org)" | ||
Version: 001.000 | ||
ItalicAngle: 0 | ||
UnderlinePosition: -7 | ||
UnderlineWidth: 3 | ||
Ascent: 20 | ||
Descent: 80 | ||
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: 1729779161 | ||
PfmFamily: 17 | ||
TTFWeight: 400 | ||
TTFWidth: 5 | ||
LineGap: 10 | ||
VLineGap: 0 | ||
OS2TypoAscent: 0 | ||
OS2TypoAOffset: 1 | ||
OS2TypoDescent: 0 | ||
OS2TypoDOffset: 1 | ||
OS2TypoLinegap: 10 | ||
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 4 | ||
|
||
StartChar: a | ||
Encoding: 97 97 0 | ||
Width: 80 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 20 m 5 | ||
80 20 l 5 | ||
80 0 l 1 | ||
0 0 l 1 | ||
0 20 l 5 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: b | ||
Encoding: 98 98 1 | ||
Width: 10 | ||
VWidth: 108 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 20 m 1 | ||
10 20 l 5 | ||
10 0 l 5 | ||
0 0 l 1 | ||
0 20 l 1 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: c | ||
Encoding: 99 99 2 | ||
Width: 80 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 0 m 1 | ||
80 0 l 1 | ||
80 -80 l 5 | ||
0 -80 l 5 | ||
0 0 l 1 | ||
EndSplineSet | ||
EndChar | ||
|
||
StartChar: d | ||
Encoding: 100 100 3 | ||
Width: 10 | ||
Flags: HW | ||
LayerCount: 2 | ||
Fore | ||
SplineSet | ||
0 0 m 1 | ||
10 0 l 1 | ||
10 -80 l 5 | ||
0 -80 l 5 | ||
0 0 l 1 | ||
EndSplineSet | ||
EndChar | ||
EndChars | ||
EndSplineFont |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
text.getLineMetrics(-1) = RangeError: Error #2006: The supplied index is out of bounds. | ||
text.getLineMetrics(0) = ascent=6, descent=6, leading=0, width=21.65, height=12, x=2 | ||
text.getLineMetrics(1) = ascent=13.45, descent=4.7, leading=0, width=27.15, height=18.15, x=2 | ||
text.getLineMetrics(2) = ascent=2.4, descent=9.6, leading=0, width=0, height=12, x=2 | ||
text.getLineMetrics(3) = ascent=13.45, descent=6, leading=0, width=88.15, height=19.45, x=2 | ||
text.getLineMetrics(4) = ascent=15.7, descent=5.5, leading=0, width=65.9, height=21.2, x=2 | ||
text.getLineMetrics(5) = ascent=13.45, descent=6, leading=5, width=63.3, height=24.45, x=2 | ||
text.getLineMetrics(6) = ascent=13.45, descent=4.7, leading=4, width=254.8, height=22.15, x=2 | ||
text.getLineMetrics(7) = ascent=13.45, descent=9.6, leading=4, width=51, height=27.05, x=2 | ||
text.getLineMetrics(8) = ascent=2.4, descent=9.6, leading=0, width=0, height=12, x=2 | ||
text.getLineMetrics(9) = RangeError: Error #2006: The supplied index is out of bounds. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
num_ticks = 1 |