Skip to content

Commit 1cfb420

Browse files
committed
tests: Improve edittext_getcharboundaries test
This patch removes y precision constraint, as now Ruffle produces output consistent with Flash Player, additionally some test cases are added.
1 parent 1e0de46 commit 1cfb420

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

tests/tests/swfs/avm2/edittext_getcharboundaries/Test.as

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,35 @@ public class Test extends Sprite {
2727
text.defaultTextFormat = tf;
2828
addChild(text);
2929

30-
// TODO Add cases with multiple lines when leading is fixed.
31-
testHtml("test\n");
30+
testHtml("test");
3231
testHtml("ay .,\n");
3332
testHtml("x<font size='-2'>x<font size='+1'>x</font></font>");
3433
testHtml("<li>i</li>", 2);
3534
testHtml("<p align='right'>test</p>", 2);
36-
testHtml("l1\nl2\n", 0, 2);
35+
testHtml("l1\nl2\n", 0);
36+
testHtml("<li>i</li><li>j</li>", 2);
37+
testHtml("1\n2\n3\n4\n5", 0);
38+
testHtml("<p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>", 0);
39+
40+
var tf = text.defaultTextFormat;
41+
tf.leading = 0;
42+
text.defaultTextFormat = tf;
43+
44+
testHtml("<p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>", 0);
3745
}
3846

39-
private function testHtml(htmlText:String, xPrecision:int = 0, yPrecision:int = 0):void {
47+
private function testHtml(htmlText:String, xPrecision:int = 0):void {
4048
text.htmlText = htmlText;
4149
trace("Text: " + htmlText.replace(/[\r\n]/g, "\\n"));
4250

43-
testAt(-5, xPrecision, yPrecision);
44-
testAt(-1, xPrecision, yPrecision);
51+
testAt(-5, xPrecision);
52+
testAt(-1, xPrecision);
4553
for (var i = 0; i <= text.text.length; ++i) {
46-
testAt(i, xPrecision, yPrecision);
54+
testAt(i, xPrecision);
4755
}
4856
}
4957

50-
private function testAt(charIndex:int, xPrecision:int, yPrecision:int):void {
58+
private function testAt(charIndex:int, xPrecision:int):void {
5159
var bounds = text.getCharBoundaries(charIndex);
5260
if (bounds != null) {
5361
// TODO These precision-related calculations should be deleted.
@@ -56,9 +64,6 @@ public class Test extends Sprite {
5664
if (xPrecision > 0) {
5765
bounds.x = Math.ceil(bounds.x / xPrecision) * xPrecision;
5866
}
59-
if (yPrecision > 0) {
60-
bounds.y = Math.floor(bounds.y / yPrecision) * yPrecision;
61-
}
6267
}
6368
trace(" text.getCharBoundaries(" + charIndex + ") = " + bounds);
6469
}

tests/tests/swfs/avm2/edittext_getcharboundaries/output.txt

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
Text: test\n
1+
Text: test
22
text.getCharBoundaries(-5) = null
33
text.getCharBoundaries(-1) = null
44
text.getCharBoundaries(0) = (x=2, y=2, w=4.3, h=12)
55
text.getCharBoundaries(1) = (x=6.3, y=2, w=6.75, h=12)
66
text.getCharBoundaries(2) = (x=13.05, y=2, w=5.7, h=12)
77
text.getCharBoundaries(3) = (x=18.75, y=2, w=4.3, h=12)
88
text.getCharBoundaries(4) = null
9-
text.getCharBoundaries(5) = null
109
Text: ay .,\n
1110
text.getCharBoundaries(-5) = null
1211
text.getCharBoundaries(-1) = null
@@ -49,3 +48,56 @@ Text: l1\nl2\n
4948
text.getCharBoundaries(4) = (x=5.05, y=18, w=6.85, h=12)
5049
text.getCharBoundaries(5) = null
5150
text.getCharBoundaries(6) = null
51+
Text: <li>i</li><li>j</li>
52+
text.getCharBoundaries(-5) = null
53+
text.getCharBoundaries(-1) = null
54+
text.getCharBoundaries(0) = (x=38, y=2, w=3.05, h=12)
55+
text.getCharBoundaries(1) = null
56+
text.getCharBoundaries(2) = (x=38, y=18, w=3.05, h=12)
57+
text.getCharBoundaries(3) = null
58+
text.getCharBoundaries(4) = null
59+
Text: 1\n2\n3\n4\n5
60+
text.getCharBoundaries(-5) = null
61+
text.getCharBoundaries(-1) = null
62+
text.getCharBoundaries(0) = (x=2, y=2, w=6.85, h=12)
63+
text.getCharBoundaries(1) = null
64+
text.getCharBoundaries(2) = (x=2, y=18, w=6.85, h=12)
65+
text.getCharBoundaries(3) = null
66+
text.getCharBoundaries(4) = (x=2, y=34, w=6.85, h=12)
67+
text.getCharBoundaries(5) = null
68+
text.getCharBoundaries(6) = (x=2, y=50, w=6.85, h=12)
69+
text.getCharBoundaries(7) = null
70+
text.getCharBoundaries(8) = (x=2, y=66, w=6.85, h=12)
71+
text.getCharBoundaries(9) = null
72+
Text: <p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>
73+
text.getCharBoundaries(-5) = null
74+
text.getCharBoundaries(-1) = null
75+
text.getCharBoundaries(0) = (x=2, y=2, w=7.4, h=14.05)
76+
text.getCharBoundaries(1) = (x=9.4, y=2, w=7.1, h=14.05)
77+
text.getCharBoundaries(2) = (x=16.5, y=2, w=12.7, h=14.05)
78+
text.getCharBoundaries(3) = null
79+
text.getCharBoundaries(4) = (x=2, y=20.05, w=8.45, h=16.1)
80+
text.getCharBoundaries(5) = (x=10.45, y=20.05, w=8.15, h=16.1)
81+
text.getCharBoundaries(6) = (x=18.6, y=20.05, w=14.5, h=16.1)
82+
text.getCharBoundaries(7) = null
83+
text.getCharBoundaries(8) = (x=2, y=40.15, w=5.25, h=10.05)
84+
text.getCharBoundaries(9) = (x=7.25, y=40.15, w=5.05, h=10.05)
85+
text.getCharBoundaries(10) = (x=12.3, y=40.15, w=9.05, h=10.05)
86+
text.getCharBoundaries(11) = null
87+
text.getCharBoundaries(12) = null
88+
Text: <p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>
89+
text.getCharBoundaries(-5) = null
90+
text.getCharBoundaries(-1) = null
91+
text.getCharBoundaries(0) = (x=2, y=2, w=7.4, h=14.05)
92+
text.getCharBoundaries(1) = (x=9.4, y=2, w=7.1, h=14.05)
93+
text.getCharBoundaries(2) = (x=16.5, y=2, w=12.7, h=14.05)
94+
text.getCharBoundaries(3) = null
95+
text.getCharBoundaries(4) = (x=2, y=16.05, w=8.45, h=16.1)
96+
text.getCharBoundaries(5) = (x=10.45, y=16.05, w=8.15, h=16.1)
97+
text.getCharBoundaries(6) = (x=18.6, y=16.05, w=14.5, h=16.1)
98+
text.getCharBoundaries(7) = null
99+
text.getCharBoundaries(8) = (x=2, y=32.15, w=5.25, h=10.05)
100+
text.getCharBoundaries(9) = (x=7.25, y=32.15, w=5.05, h=10.05)
101+
text.getCharBoundaries(10) = (x=12.3, y=32.15, w=9.05, h=10.05)
102+
text.getCharBoundaries(11) = null
103+
text.getCharBoundaries(12) = null
29 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)