Skip to content

Commit

Permalink
tests: Add avm2/edittext_autosize_height test
Browse files Browse the repository at this point in the history
This test verifies how autosize sets heights of text fields.
  • Loading branch information
kjarosh committed Nov 24, 2024
1 parent d63214f commit 64a67ac
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
83 changes: 83 additions & 0 deletions tests/tests/swfs/avm2/edittext_autosize_height/Test.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;

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

private var nextY: int = 0;
private var nextX: int = 0;

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

newTextField("left", false, "<p></p><p>abab</p><p>ab</p>");
newTextField("left", true, "<p></p><p>abab</p><p>ab</p>");
newTextField("center", false, "<p></p><p>abab</p><p>ab</p>");
newTextField("center", true, "<p></p><p>abab</p><p>ab</p>");
newTextField("right", false, "<p></p><p>abab</p><p>ab</p>");
newTextField("right", true, "<p></p><p>abab</p><p>ab</p>");

nextY = 0;
nextX = 100;
newTextField("left", false, "<p>abab</p><p>ab</p><p></p>");
newTextField("left", true, "<p>abab</p><p>ab</p><p></p>");
newTextField("center", false, "<p>abab</p><p>ab</p><p></p>");
newTextField("center", true, "<p>abab</p><p>ab</p><p></p>");
newTextField("right", false, "<p>abab</p><p>ab</p><p></p>");
newTextField("right", true, "<p>abab</p><p>ab</p><p></p>");

nextY = 0;
nextX = 200;
newTextField("left", false, "<p>abab</p>");
newTextField("left", true, "<p>abab</p>");
newTextField("left", false, "");
newTextField("left", true, "");
newTextField("left", false, "<p></p>");
newTextField("left", true, "<p></p>");

nextY = 0;
nextX = 300;
newTextField("right", false, "<p></p>");
newTextField("right", true, "<p></p>");
newTextField("center", false, "<p></p>");
newTextField("center", true, "<p></p>");
newTextField("left", false, "<p></p><p></p>");
newTextField("left", true, "<p></p><p></p>");

nextY = 0;
nextX = 400;
newTextField("left", true, "<p>abab abab abab abab abab</p>");
newTextField("left", true, "<p>abab abab abab abab abab</p><p></p>");
newTextField("left", true, "abab abab abab abab abab");
newTextField("right", true, "<p>abab abab abab abab abab</p>");
newTextField("right", true, "<p>abab abab abab abab abab</p><p></p>");
newTextField("right", true, "abab abab abab abab abab");
}

private function newTextField(autosize: String, wordWrap: Boolean, htmlText: String):void {
var text = new TextField();
text.multiline = true;
text.wordWrap = wordWrap;
text.border = true;
text.x = nextX;
text.y = nextY;
nextY += 62;
text.width = 100;
text.height = 60;
text.embedFonts = true;
var tf = new TextFormat();
tf.font = "TestFont";
tf.size = 10;
tf.leading = 5;
text.defaultTextFormat = tf;
text.htmlText = htmlText;
text.autoSize = autosize;
trace("(w, h) = (" + text.textWidth + ", " + text.textHeight + ")");
addChild(text);
}
}
}
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions tests/tests/swfs/avm2/edittext_autosize_height/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 40)
(w, h) = (32, 15)
(w, h) = (32, 15)
(w, h) = (0, 0)
(w, h) = (0, 0)
(w, h) = (0, 15)
(w, h) = (0, 15)
(w, h) = (0, 15)
(w, h) = (0, 15)
(w, h) = (0, 15)
(w, h) = (0, 15)
(w, h) = (0, 25)
(w, h) = (0, 25)
(w, h) = (96, 25)
(w, h) = (96, 40)
(w, h) = (96, 25)
(w, h) = (96, 25)
(w, h) = (96, 40)
(w, h) = (96, 25)
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/tests/swfs/avm2/edittext_autosize_height/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
num_ticks = 1

[image_comparisons.output]
tolerance = 128

[player_options]
with_renderer = { optional = false, sample_count = 4 }

0 comments on commit 64a67ac

Please sign in to comment.