Skip to content

Commit

Permalink
tests: Add avm2/edittext_getcharboundaries_missing_glyphs test
Browse files Browse the repository at this point in the history
This test verifies how getCharBoundaries() work when glyphs are missing.
  • Loading branch information
kjarosh committed Dec 12, 2024
1 parent a78cd11 commit ff00d12
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;

[SWF(width="400", height="400")]
public class Test extends Sprite {
[Embed(source="TestFont.ttf", fontName="TestFont", embedAsCFF="false", unicodeRange="U+0061-U+0066")]
private var TestFont: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 = 380;
text.height = 380;
text.multiline = true;
text.embedFonts = true;
addChild(text);

testHtml("<font face='Unknown Font'>x y</font>");
testHtml("<font face='TestFont'>x y</font>");
testHtml("<font face='TestFont'>abcd ab</font>");

text.wordWrap = true;
testHtml("<p align='justify'><font size='30' face='TestFont'>ab ab abababababa</font></p>");
testHtml("<p align='justify'><font size='30' face='TestFont'>ab ab abababababab</font></p>");
}

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

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

private function testAt(charIndex:int):void {
var bounds = text.getCharBoundaries(charIndex);
trace(" text.getCharBoundaries(" + charIndex + ") = " + bounds);
}
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Text: <font face='Unknown Font'>x y</font>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = null
text.getCharBoundaries(1) = null
text.getCharBoundaries(2) = null
text.getCharBoundaries(3) = null
Text: <font face='TestFont'>x y</font>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = null
text.getCharBoundaries(1) = null
text.getCharBoundaries(2) = null
text.getCharBoundaries(3) = null
Text: <font face='TestFont'>abcd ab</font>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=9.6, h=12)
text.getCharBoundaries(1) = (x=11.6, y=2, w=9.6, h=12)
text.getCharBoundaries(2) = null
text.getCharBoundaries(3) = null
text.getCharBoundaries(4) = null
text.getCharBoundaries(5) = (x=21.2, y=2, w=9.6, h=12)
text.getCharBoundaries(6) = (x=30.8, y=2, w=9.6, h=12)
text.getCharBoundaries(7) = null
Text: <p align='justify'><font size='30' face='TestFont'>ab ab abababababa</font></p>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=24, h=30)
text.getCharBoundaries(1) = (x=26, y=2, w=24, h=30)
text.getCharBoundaries(2) = null
text.getCharBoundaries(3) = (x=50, y=2, w=24, h=30)
text.getCharBoundaries(4) = (x=74, y=2, w=24, h=30)
text.getCharBoundaries(5) = null
text.getCharBoundaries(6) = (x=98, y=2, w=24, h=30)
text.getCharBoundaries(7) = (x=122, y=2, w=24, h=30)
text.getCharBoundaries(8) = (x=146, y=2, w=24, h=30)
text.getCharBoundaries(9) = (x=170, y=2, w=24, h=30)
text.getCharBoundaries(10) = (x=194, y=2, w=24, h=30)
text.getCharBoundaries(11) = (x=218, y=2, w=24, h=30)
text.getCharBoundaries(12) = (x=242, y=2, w=24, h=30)
text.getCharBoundaries(13) = (x=266, y=2, w=24, h=30)
text.getCharBoundaries(14) = (x=290, y=2, w=24, h=30)
text.getCharBoundaries(15) = (x=314, y=2, w=24, h=30)
text.getCharBoundaries(16) = (x=338, y=2, w=24, h=30)
text.getCharBoundaries(17) = null
text.getCharBoundaries(18) = null
Text: <p align='justify'><font size='30' face='TestFont'>ab ab abababababab</font></p>
text.getCharBoundaries(-5) = null
text.getCharBoundaries(-1) = null
text.getCharBoundaries(0) = (x=2, y=2, w=24, h=30)
text.getCharBoundaries(1) = (x=26, y=2, w=24, h=30)
text.getCharBoundaries(2) = (x=50, y=2, w=280, h=30)
text.getCharBoundaries(3) = (x=330, y=2, w=24, h=30)
text.getCharBoundaries(4) = (x=354, y=2, w=24, h=30)
text.getCharBoundaries(5) = null
text.getCharBoundaries(6) = (x=2, y=32, w=24, h=30)
text.getCharBoundaries(7) = (x=26, y=32, w=24, h=30)
text.getCharBoundaries(8) = (x=50, y=32, w=24, h=30)
text.getCharBoundaries(9) = (x=74, y=32, w=24, h=30)
text.getCharBoundaries(10) = (x=98, y=32, w=24, h=30)
text.getCharBoundaries(11) = (x=122, y=32, w=24, h=30)
text.getCharBoundaries(12) = (x=146, y=32, w=24, h=30)
text.getCharBoundaries(13) = (x=170, y=32, w=24, h=30)
text.getCharBoundaries(14) = (x=194, y=32, w=24, h=30)
text.getCharBoundaries(15) = (x=218, y=32, w=24, h=30)
text.getCharBoundaries(16) = (x=242, y=32, w=24, h=30)
text.getCharBoundaries(17) = (x=266, y=32, w=24, h=30)
text.getCharBoundaries(18) = null
text.getCharBoundaries(19) = null
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
num_ticks = 1

0 comments on commit ff00d12

Please sign in to comment.