Skip to content

Commit cc53017

Browse files
committed
tests: Add avm2/edittext_stylesheet_custom_tag test
1 parent 5614a0a commit cc53017

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package {
2+
import flash.display.*;
3+
import flash.text.*;
4+
5+
public class Test extends Sprite {
6+
private var style:StyleSheet;
7+
8+
public function Test() {
9+
runTests();
10+
}
11+
12+
function runTests() {
13+
resetStyle();
14+
runHtmlTests();
15+
}
16+
17+
function resetStyle() {
18+
style = new StyleSheet();
19+
}
20+
21+
function runHtmlTests() {
22+
var colorRed:Object = new Object();
23+
colorRed.color = 0xFF0000;
24+
var colorBlue:Object = new Object();
25+
colorBlue.color = 0xFF;
26+
style.setStyle("red", colorRed);
27+
style.setStyle("blue", colorBlue);
28+
runHtmlTest('<red>r</red>');
29+
runHtmlTest('<blue>b</blue>');
30+
runHtmlTest('<blue>b<red>r</red></blue>');
31+
runHtmlTest('<red>r<blue>b</blue></red>');
32+
resetStyle();
33+
34+
var classRedBold:Object = new Object();
35+
classRedBold.color = "#FF0000";
36+
classRedBold.fontWeight = "bold";
37+
var colorBlue:Object = new Object();
38+
colorBlue.color = 0xFF;
39+
style.setStyle("red", classRedBold);
40+
style.setStyle("blue", colorBlue);
41+
runHtmlTest('<red>r</red>');
42+
runHtmlTest('<blue>b</blue>');
43+
runHtmlTest('<blue>b<red>r</red></blue>');
44+
runHtmlTest('<red>r<blue>b</blue></red>');
45+
resetStyle();
46+
}
47+
48+
function runHtmlTest(html: String) {
49+
var text = newTextField();
50+
text.styleSheet = style;
51+
52+
trace("======================================");
53+
trace(" Setting HTML: " + escape(html));
54+
text.htmlText = html;
55+
trace(" HTML get: " + escape(text.htmlText));
56+
trace(" Text get: " + escape(text.text));
57+
printTextRuns(text.getTextRuns());
58+
text.styleSheet = null;
59+
trace(" Style reset: " + escape(text.htmlText));
60+
printTextRuns(text.getTextRuns());
61+
}
62+
63+
private function printTextRuns(runs: Array) {
64+
trace(" Text runs (" + runs.length + "):");
65+
for each (var run in runs) {
66+
trace(" from " + run.beginIndex + " to " + run.endIndex + ": " + describeTextFormat(run.textFormat));
67+
}
68+
}
69+
70+
private function describeTextFormat(tf: TextFormat): String {
71+
return "size=" + tf.size +
72+
", blockIndent=" + tf.blockIndent +
73+
", font=" + tf.font +
74+
", align=" + tf.align +
75+
", leading=" + tf.leading +
76+
", display=" + tf.display +
77+
", kerning=" + tf.kerning +
78+
", leftMargin=" + tf.leftMargin +
79+
", rightMargin=" + tf.rightMargin +
80+
", color=" + tf.color +
81+
", bold=" + tf.bold +
82+
", italic=" + tf.italic +
83+
", bullet=" + tf.bullet +
84+
", underline=" + tf.underline;
85+
}
86+
87+
private function escape(string: String): String {
88+
return string.replace(/\n/g, "\\n").replace(/\r/g, "\\r");
89+
}
90+
91+
private function newTextField(): TextField {
92+
var text = new TextField();
93+
text.defaultTextFormat = new TextFormat("FontName", 10);
94+
return text;
95+
}
96+
}
97+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
======================================
2+
Setting HTML: <red>r</red>
3+
HTML get: <red>r</red>
4+
Text get: r\r
5+
Text runs (1):
6+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
7+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">r</FONT></P>
8+
Text runs (1):
9+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
10+
======================================
11+
Setting HTML: <blue>b</blue>
12+
HTML get: <blue>b</blue>
13+
Text get: b\r
14+
Text runs (1):
15+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
16+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">b</FONT></P>
17+
Text runs (1):
18+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
19+
======================================
20+
Setting HTML: <blue>b<red>r</red></blue>
21+
HTML get: <blue>b<red>r</red></blue>
22+
Text get: br\r
23+
Text runs (1):
24+
from 0 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
25+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">br</FONT></P>
26+
Text runs (1):
27+
from 0 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
28+
======================================
29+
Setting HTML: <red>r<blue>b</blue></red>
30+
HTML get: <red>r<blue>b</blue></red>
31+
Text get: rb\r
32+
Text runs (1):
33+
from 0 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
34+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">rb</FONT></P>
35+
Text runs (1):
36+
from 0 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
37+
======================================
38+
Setting HTML: <red>r</red>
39+
HTML get: <red>r</red>
40+
Text get: r\r
41+
Text runs (1):
42+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
43+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#FF0000" LETTERSPACING="0" KERNING="0"><B>r</B></FONT></P>
44+
Text runs (1):
45+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
46+
======================================
47+
Setting HTML: <blue>b</blue>
48+
HTML get: <blue>b</blue>
49+
Text get: b\r
50+
Text runs (1):
51+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
52+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">b</FONT></P>
53+
Text runs (1):
54+
from 0 to 2: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
55+
======================================
56+
Setting HTML: <blue>b<red>r</red></blue>
57+
HTML get: <blue>b<red>r</red></blue>
58+
Text get: br\r
59+
Text runs (2):
60+
from 0 to 1: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
61+
from 1 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
62+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#000000" LETTERSPACING="0" KERNING="0">b<FONT COLOR="#FF0000"><B>r</B></FONT></FONT></P>
63+
Text runs (2):
64+
from 0 to 1: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=false, italic=false, bullet=false, underline=false
65+
from 1 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
66+
======================================
67+
Setting HTML: <red>r<blue>b</blue></red>
68+
HTML get: <red>r<blue>b</blue></red>
69+
Text get: rb\r
70+
Text runs (2):
71+
from 0 to 1: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
72+
from 1 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=true, italic=false, bullet=false, underline=false
73+
Style reset: <P ALIGN="LEFT"><FONT FACE="FontName" SIZE="10" COLOR="#FF0000" LETTERSPACING="0" KERNING="0"><B>r</B><FONT COLOR="#000000"><B>b</B></FONT></FONT></P>
74+
Text runs (2):
75+
from 0 to 1: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=16711680, bold=true, italic=false, bullet=false, underline=false
76+
from 1 to 3: size=10, blockIndent=0, font=FontName, align=left, leading=0, display=block, kerning=false, leftMargin=0, rightMargin=0, color=0, bold=true, italic=false, bullet=false, underline=false
2.06 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_ticks = 1

0 commit comments

Comments
 (0)