Skip to content

Commit

Permalink
tests: Improve edittext_getcharboundaries test
Browse files Browse the repository at this point in the history
This patch removes y precision constraint, as now Ruffle produces
output consistent with Flash Player, additionally some test cases
are added.
  • Loading branch information
kjarosh committed Oct 24, 2024
1 parent 1e0de46 commit 1cfb420
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 13 deletions.
27 changes: 16 additions & 11 deletions tests/tests/swfs/avm2/edittext_getcharboundaries/Test.as
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,35 @@ public class Test extends Sprite {
text.defaultTextFormat = tf;
addChild(text);

// TODO Add cases with multiple lines when leading is fixed.
testHtml("test\n");
testHtml("test");
testHtml("ay .,\n");
testHtml("x<font size='-2'>x<font size='+1'>x</font></font>");
testHtml("<li>i</li>", 2);
testHtml("<p align='right'>test</p>", 2);
testHtml("l1\nl2\n", 0, 2);
testHtml("l1\nl2\n", 0);
testHtml("<li>i</li><li>j</li>", 2);
testHtml("1\n2\n3\n4\n5", 0);
testHtml("<p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>", 0);

var tf = text.defaultTextFormat;
tf.leading = 0;
text.defaultTextFormat = tf;

testHtml("<p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>", 0);
}

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

testAt(-5, xPrecision, yPrecision);
testAt(-1, xPrecision, yPrecision);
testAt(-5, xPrecision);
testAt(-1, xPrecision);
for (var i = 0; i <= text.text.length; ++i) {
testAt(i, xPrecision, yPrecision);
testAt(i, xPrecision);
}
}

private function testAt(charIndex:int, xPrecision:int, yPrecision:int):void {
private function testAt(charIndex:int, xPrecision:int):void {
var bounds = text.getCharBoundaries(charIndex);
if (bounds != null) {
// TODO These precision-related calculations should be deleted.
Expand All @@ -56,9 +64,6 @@ public class Test extends Sprite {
if (xPrecision > 0) {
bounds.x = Math.ceil(bounds.x / xPrecision) * xPrecision;
}
if (yPrecision > 0) {
bounds.y = Math.floor(bounds.y / yPrecision) * yPrecision;
}
}
trace(" text.getCharBoundaries(" + charIndex + ") = " + bounds);
}
Expand Down
56 changes: 54 additions & 2 deletions tests/tests/swfs/avm2/edittext_getcharboundaries/output.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
Text: test\n
Text: test
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=4.3, h=12)
text.getCharBoundaries(1) = (x=6.3, y=2, w=6.75, h=12)
text.getCharBoundaries(2) = (x=13.05, y=2, w=5.7, h=12)
text.getCharBoundaries(3) = (x=18.75, y=2, w=4.3, h=12)
text.getCharBoundaries(4) = null
text.getCharBoundaries(5) = null
Text: ay .,\n
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
Expand Down Expand Up @@ -49,3 +48,56 @@ Text: l1\nl2\n
text.getCharBoundaries(4) = (x=5.05, y=18, w=6.85, h=12)
text.getCharBoundaries(5) = null
text.getCharBoundaries(6) = null
Text: <li>i</li><li>j</li>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=38, y=2, w=3.05, h=12)
text.getCharBoundaries(1) = null
text.getCharBoundaries(2) = (x=38, y=18, w=3.05, h=12)
text.getCharBoundaries(3) = null
text.getCharBoundaries(4) = null
Text: 1\n2\n3\n4\n5
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=6.85, h=12)
text.getCharBoundaries(1) = null
text.getCharBoundaries(2) = (x=2, y=18, w=6.85, h=12)
text.getCharBoundaries(3) = null
text.getCharBoundaries(4) = (x=2, y=34, w=6.85, h=12)
text.getCharBoundaries(5) = null
text.getCharBoundaries(6) = (x=2, y=50, w=6.85, h=12)
text.getCharBoundaries(7) = null
text.getCharBoundaries(8) = (x=2, y=66, w=6.85, h=12)
text.getCharBoundaries(9) = null
Text: <p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=7.4, h=14.05)
text.getCharBoundaries(1) = (x=9.4, y=2, w=7.1, h=14.05)
text.getCharBoundaries(2) = (x=16.5, y=2, w=12.7, h=14.05)
text.getCharBoundaries(3) = null
text.getCharBoundaries(4) = (x=2, y=20.05, w=8.45, h=16.1)
text.getCharBoundaries(5) = (x=10.45, y=20.05, w=8.15, h=16.1)
text.getCharBoundaries(6) = (x=18.6, y=20.05, w=14.5, h=16.1)
text.getCharBoundaries(7) = null
text.getCharBoundaries(8) = (x=2, y=40.15, w=5.25, h=10.05)
text.getCharBoundaries(9) = (x=7.25, y=40.15, w=5.05, h=10.05)
text.getCharBoundaries(10) = (x=12.3, y=40.15, w=9.05, h=10.05)
text.getCharBoundaries(11) = null
text.getCharBoundaries(12) = null
Text: <p><font size='+2'>xyM</font></p><p><font size='+4'>xyM</font></p><p><font size='-2'>xyM</font></p>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=7.4, h=14.05)
text.getCharBoundaries(1) = (x=9.4, y=2, w=7.1, h=14.05)
text.getCharBoundaries(2) = (x=16.5, y=2, w=12.7, h=14.05)
text.getCharBoundaries(3) = null
text.getCharBoundaries(4) = (x=2, y=16.05, w=8.45, h=16.1)
text.getCharBoundaries(5) = (x=10.45, y=16.05, w=8.15, h=16.1)
text.getCharBoundaries(6) = (x=18.6, y=16.05, w=14.5, h=16.1)
text.getCharBoundaries(7) = null
text.getCharBoundaries(8) = (x=2, y=32.15, w=5.25, h=10.05)
text.getCharBoundaries(9) = (x=7.25, y=32.15, w=5.05, h=10.05)
text.getCharBoundaries(10) = (x=12.3, y=32.15, w=9.05, h=10.05)
text.getCharBoundaries(11) = null
text.getCharBoundaries(12) = null
Binary file modified tests/tests/swfs/avm2/edittext_getcharboundaries/test.swf
Binary file not shown.

0 comments on commit 1cfb420

Please sign in to comment.