Skip to content

Commit 367538a

Browse files
committed
tests: Add avm2/edittext_get_char_index_at_point test
This test verifies the behavior of getCharIndexAtPoint().
1 parent 69b80c0 commit 367538a

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
package {
2+
import flash.display.Sprite;
3+
import flash.display.Bitmap;
4+
import flash.display.BitmapData;
5+
import flash.text.TextField;
6+
import flash.text.TextFormat;
7+
import flash.geom.Rectangle;
8+
import flash.utils.ByteArray;
9+
10+
[SWF(width="400", height="400")]
11+
public class Test extends Sprite {
12+
[Embed(source="TestFont.ttf", fontName="TestFont", embedAsCFF="false", unicodeRange="U+0061-U+0064")]
13+
private var TestFont:Class;
14+
15+
private var colors: Array = [
16+
0xFFFF0000,
17+
0xFF00FF00,
18+
0xFF0000FF,
19+
0xFFFFFF00,
20+
0xFF00FFFF,
21+
0xFFFF00FF,
22+
0xFFFFFFFF,
23+
];
24+
25+
private var text1: TextField;
26+
27+
public function Test() {
28+
var t1: TextField = newTextField();
29+
t1.htmlText = "a\n<font size='30'>aa</font>\n<textformat leading='-10'>aaa</textformat>\naa";
30+
renderMap(t1);
31+
32+
var t2: TextField = newTextField(t1);
33+
t2.height = 50;
34+
t2.htmlText = "";
35+
renderMap(t2);
36+
37+
var t3: TextField = newTextField(t2);
38+
t3.height = 50;
39+
t3.type = "input";
40+
t3.htmlText = "";
41+
renderMap(t3);
42+
43+
var t4: TextField = newTextField(t3);
44+
t4.type = "input";
45+
t4.htmlText = "a<font size='25'>a<font size='20'>a<font size='10'>a<font size='20'>a<font size='15'>a</font></font></font></font></font>";
46+
renderMap(t4);
47+
48+
var t5: TextField = newTextField(null, t4);
49+
t5.height = 50;
50+
t5.htmlText = "\n";
51+
renderMap(t5);
52+
53+
var t6: TextField = newTextField(t5, t4);
54+
t6.height = 50;
55+
t6.type = "input";
56+
t6.htmlText = "\n";
57+
renderMap(t6);
58+
59+
var t7: TextField = newTextField(t6, t4);
60+
t7.height = 50;
61+
t7.htmlText = "a\n<textformat leading='-70'>aaa</textformat>\na";
62+
renderMap(t7);
63+
64+
var t8: TextField = newTextField(t7, t4);
65+
t8.htmlText = "\n\na\na";
66+
renderMap(t8);
67+
68+
var t9: TextField = newTextField(null, t8);
69+
t9.height = 60;
70+
t9.htmlText = "\n\n\n\n\n\n\n\n";
71+
t9.scrollV = 3;
72+
renderMap(t9);
73+
74+
var t10: TextField = newTextField(t9, t8);
75+
t10.htmlText = "<textformat leading='0'>a</textformat>\n<textformat leading='5'>a</textformat>\n<textformat leading='15'>a</textformat>\na\n";
76+
renderMap(t10);
77+
78+
var t11: TextField = newTextField(t10, t8);
79+
t11.height = 30;
80+
t11.htmlText = "aaaaaaaaaaaaaaaaaaaaaaaaaa";
81+
t11.scrollH = 50;
82+
trace("scrollh = " + t11.scrollH);
83+
trace("maxscrollh = " + t11.maxScrollH);
84+
renderMap(t11);
85+
86+
var t12: TextField = newTextField(t11, t8);
87+
t12.htmlText = "aaaaaaaaaaaaaaaaaaaaaaaaaa\n\naaaaaaaaaaaaaaaaaaaaaaaaaa";
88+
t12.scrollH = 50;
89+
trace("scrollh = " + t12.scrollH);
90+
trace("maxscrollh = " + t12.maxScrollH);
91+
renderMap(t12);
92+
93+
var t13: TextField = newTextField(t8, t4);
94+
t13.height = 50;
95+
t13.htmlText = "<p align='justify'>a a a aaaa</p>";
96+
t13.wordWrap = true;
97+
renderMap(t13);
98+
}
99+
100+
private function newTextField(lastY: TextField = null, lastX: TextField = null):TextField {
101+
var tf = new TextFormat();
102+
tf.font = "TestFont";
103+
tf.size = 20;
104+
tf.leading = 2;
105+
106+
var field: TextField = new TextField();
107+
field.x = 10;
108+
field.y = 10;
109+
if (lastX != null) {
110+
field.x = lastX.x + lastX.width + 12;
111+
}
112+
if (lastY != null) {
113+
field.y = lastY.y + lastY.height + 12;
114+
}
115+
field.embedFonts = true;
116+
field.border = true;
117+
field.defaultTextFormat = tf;
118+
field.width = 100;
119+
field.height = 100;
120+
return field;
121+
}
122+
123+
private function renderMap(field: TextField, resolution: Number = 2.0):void {
124+
addChild(field);
125+
var w = resolution * (field.width + 10);
126+
var h = resolution * (field.height + 10);
127+
var data:BitmapData = new BitmapData(w, h);
128+
var pixels: ByteArray = new ByteArray();
129+
130+
for (var y = 0; y < h; ++y) {
131+
for (var x = 0; x < w; ++x) {
132+
var ix = field.getCharIndexAtPoint(x / resolution - 5, y / resolution - 5);
133+
134+
var color;
135+
if (ix == -1) {
136+
color = 0xFF000000;
137+
} else {
138+
color = colors[ix % colors.length];
139+
}
140+
pixels.writeUnsignedInt(color);
141+
}
142+
}
143+
144+
pixels.position = 0;
145+
data.setPixels(new Rectangle(0, 0, w, h), pixels);
146+
var bitmap:Bitmap = new Bitmap(data);
147+
bitmap.scaleX = 1 / resolution;
148+
bitmap.scaleY = 1 / resolution;
149+
bitmap.x = field.x - 5;
150+
bitmap.y = field.y - 5;
151+
addChild(bitmap);
152+
}
153+
}
154+
}
1.56 KB
Binary file not shown.
4.19 KB
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
scrollh = 50
2+
maxscrollh = 320
3+
scrollh = 50
4+
maxscrollh = 320
3.05 KB
Binary file not shown.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
num_ticks = 1
2+
3+
[image_comparisons.output]
4+
tolerance = 0
5+
6+
[player_options]
7+
with_renderer = { optional = false, sample_count = 4 }
8+
viewport_dimensions = { width = 800, height = 800, scale_factor = 1.0 }

0 commit comments

Comments
 (0)