Skip to content

Commit 70a5700

Browse files
committed
text: Fix HTML align for native HTML fields with text
Turns out that for SWF8+, align of an HTML field with text is not ignored.
1 parent 1530a74 commit 70a5700

File tree

7 files changed

+44
-2
lines changed

7 files changed

+44
-2
lines changed

core/src/html/text_format.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,18 @@ impl TextFormat {
154154
context: &mut UpdateContext<'_>,
155155
) -> Self {
156156
let encoding = swf_movie.encoding();
157+
let swf_version = swf_movie.version();
157158
let movie_library = context.library.library_for_movie_mut(swf_movie);
158159
let font = et.font_id().and_then(|fid| movie_library.get_font(fid));
159160
let font_class = et
160161
.font_class()
161162
.map(|s| s.decode(encoding).into_owned())
162163
.or_else(|| font.map(|font| WString::from_utf8(font.descriptor().name())))
163164
.unwrap_or_else(|| WString::from_utf8("Times New Roman"));
164-
let align = if et.is_html() {
165+
let align = if et.is_html() && (swf_version < 8 || et.initial_text().is_none()) {
165166
// For some reason, when HTML is enabled in the SWF tag, align is
166-
// always left. This does not apply to dynamically enabling HTML.
167+
// always left, unless there's initial text and the SWF version is 8+.
168+
// This does not apply to enabling HTML dynamically.
167169
Some(swf::TextAlign::Left)
168170
} else {
169171
et.layout().map(|l| l.align)

tests/tests/swfs/avm1/edittext_html_align_swf7/output.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,50 @@ Default text formats:
33
center
44
left
55
left
6+
left
67
Indent:
78
10
89
10
910
10
11+
10
1012
Left margin:
1113
10
1214
10
1315
10
16+
10
1417
Right margin:
1518
10
1619
10
1720
10
21+
10
1822
Leading:
1923
5
2024
5
2125
5
26+
5
2227
Actual text formats:
2328
Align:
2429
center
2530
left
2631
left
32+
left
2733
Indent:
2834
10
2935
10
3036
10
37+
10
3138
Left margin:
3239
10
3340
10
3441
10
42+
10
3543
Right margin:
3644
10
3745
10
3846
10
47+
10
3948
Leading:
4049
5
4150
5
4251
5
52+
5

tests/tests/swfs/avm1/edittext_html_align_swf7/test.as

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,51 @@ trace(" Align:");
99
trace(" " + text1.getNewTextFormat().align);
1010
trace(" " + text2.getNewTextFormat().align);
1111
trace(" " + text3.getNewTextFormat().align);
12+
trace(" " + text4.getNewTextFormat().align);
1213
trace(" Indent:");
1314
trace(" " + text1.getNewTextFormat().indent);
1415
trace(" " + text2.getNewTextFormat().indent);
1516
trace(" " + text3.getNewTextFormat().indent);
17+
trace(" " + text4.getNewTextFormat().indent);
1618
trace(" Left margin:");
1719
trace(" " + text1.getNewTextFormat().leftMargin);
1820
trace(" " + text2.getNewTextFormat().leftMargin);
1921
trace(" " + text3.getNewTextFormat().leftMargin);
22+
trace(" " + text4.getNewTextFormat().leftMargin);
2023
trace(" Right margin:");
2124
trace(" " + text1.getNewTextFormat().rightMargin);
2225
trace(" " + text2.getNewTextFormat().rightMargin);
2326
trace(" " + text3.getNewTextFormat().rightMargin);
27+
trace(" " + text4.getNewTextFormat().rightMargin);
2428
trace(" Leading:");
2529
trace(" " + text1.getNewTextFormat().leading);
2630
trace(" " + text2.getNewTextFormat().leading);
2731
trace(" " + text3.getNewTextFormat().leading);
32+
trace(" " + text4.getNewTextFormat().leading);
2833

2934
trace("Actual text formats:");
3035
trace(" Align:");
3136
trace(" " + text1.getTextFormat(0, 1).align);
3237
trace(" " + text2.getTextFormat(0, 1).align);
3338
trace(" " + text3.getTextFormat(0, 1).align);
39+
trace(" " + text4.getTextFormat(0, 1).align);
3440
trace(" Indent:");
3541
trace(" " + text1.getTextFormat(0, 1).indent);
3642
trace(" " + text2.getTextFormat(0, 1).indent);
3743
trace(" " + text3.getTextFormat(0, 1).indent);
44+
trace(" " + text4.getTextFormat(0, 1).indent);
3845
trace(" Left margin:");
3946
trace(" " + text1.getTextFormat(0, 1).leftMargin);
4047
trace(" " + text2.getTextFormat(0, 1).leftMargin);
4148
trace(" " + text3.getTextFormat(0, 1).leftMargin);
49+
trace(" " + text4.getTextFormat(0, 1).leftMargin);
4250
trace(" Right margin:");
4351
trace(" " + text1.getTextFormat(0, 1).rightMargin);
4452
trace(" " + text2.getTextFormat(0, 1).rightMargin);
4553
trace(" " + text3.getTextFormat(0, 1).rightMargin);
54+
trace(" " + text4.getTextFormat(0, 1).rightMargin);
4655
trace(" Leading:");
4756
trace(" " + text1.getTextFormat(0, 1).leading);
4857
trace(" " + text2.getTextFormat(0, 1).leading);
4958
trace(" " + text3.getTextFormat(0, 1).leading);
59+
trace(" " + text4.getTextFormat(0, 1).leading);
62 Bytes
Binary file not shown.

tests/tests/swfs/avm1/edittext_html_align_swf8/output.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,50 @@ Default text formats:
33
center
44
center
55
left
6+
center
67
Indent:
78
10
89
10
910
10
11+
10
1012
Left margin:
1113
10
1214
10
1315
10
16+
10
1417
Right margin:
1518
10
1619
10
1720
10
21+
10
1822
Leading:
1923
5
2024
5
2125
5
26+
5
2227
Actual text formats:
2328
Align:
2429
center
2530
center
2631
left
32+
center
2733
Indent:
2834
10
2935
10
3036
10
37+
10
3138
Left margin:
3239
10
3340
10
3441
10
42+
10
3543
Right margin:
3644
10
3745
10
3846
10
47+
10
3948
Leading:
4049
5
4150
5
4251
5
52+
5

tests/tests/swfs/avm1/edittext_html_align_swf8/test.as

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,41 +9,51 @@ trace(" Align:");
99
trace(" " + text1.getNewTextFormat().align);
1010
trace(" " + text2.getNewTextFormat().align);
1111
trace(" " + text3.getNewTextFormat().align);
12+
trace(" " + text4.getNewTextFormat().align);
1213
trace(" Indent:");
1314
trace(" " + text1.getNewTextFormat().indent);
1415
trace(" " + text2.getNewTextFormat().indent);
1516
trace(" " + text3.getNewTextFormat().indent);
17+
trace(" " + text4.getNewTextFormat().indent);
1618
trace(" Left margin:");
1719
trace(" " + text1.getNewTextFormat().leftMargin);
1820
trace(" " + text2.getNewTextFormat().leftMargin);
1921
trace(" " + text3.getNewTextFormat().leftMargin);
22+
trace(" " + text4.getNewTextFormat().leftMargin);
2023
trace(" Right margin:");
2124
trace(" " + text1.getNewTextFormat().rightMargin);
2225
trace(" " + text2.getNewTextFormat().rightMargin);
2326
trace(" " + text3.getNewTextFormat().rightMargin);
27+
trace(" " + text4.getNewTextFormat().rightMargin);
2428
trace(" Leading:");
2529
trace(" " + text1.getNewTextFormat().leading);
2630
trace(" " + text2.getNewTextFormat().leading);
2731
trace(" " + text3.getNewTextFormat().leading);
32+
trace(" " + text4.getNewTextFormat().leading);
2833

2934
trace("Actual text formats:");
3035
trace(" Align:");
3136
trace(" " + text1.getTextFormat(0, 1).align);
3237
trace(" " + text2.getTextFormat(0, 1).align);
3338
trace(" " + text3.getTextFormat(0, 1).align);
39+
trace(" " + text4.getTextFormat(0, 1).align);
3440
trace(" Indent:");
3541
trace(" " + text1.getTextFormat(0, 1).indent);
3642
trace(" " + text2.getTextFormat(0, 1).indent);
3743
trace(" " + text3.getTextFormat(0, 1).indent);
44+
trace(" " + text4.getTextFormat(0, 1).indent);
3845
trace(" Left margin:");
3946
trace(" " + text1.getTextFormat(0, 1).leftMargin);
4047
trace(" " + text2.getTextFormat(0, 1).leftMargin);
4148
trace(" " + text3.getTextFormat(0, 1).leftMargin);
49+
trace(" " + text4.getTextFormat(0, 1).leftMargin);
4250
trace(" Right margin:");
4351
trace(" " + text1.getTextFormat(0, 1).rightMargin);
4452
trace(" " + text2.getTextFormat(0, 1).rightMargin);
4553
trace(" " + text3.getTextFormat(0, 1).rightMargin);
54+
trace(" " + text4.getTextFormat(0, 1).rightMargin);
4655
trace(" Leading:");
4756
trace(" " + text1.getTextFormat(0, 1).leading);
4857
trace(" " + text2.getTextFormat(0, 1).leading);
4958
trace(" " + text3.getTextFormat(0, 1).leading);
59+
trace(" " + text4.getTextFormat(0, 1).leading);
62 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)