Skip to content

Commit 255b8ea

Browse files
onkrottorokati44
authored andcommitted
avm2: Implement clone() method for flash.text.engine classes
1 parent 0ef0e37 commit 255b8ea

File tree

21 files changed

+302
-0
lines changed

21 files changed

+302
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
11
package flash.text.engine {
22
[API("662")]
33
public final class EastAsianJustifier extends TextJustifier {
4+
private var _justificationStyle:String;
5+
private var _composeTrailingIdeographicSpaces:Boolean;
6+
47
public function EastAsianJustifier(locale:String = "ja", lineJustification:String = "allButLast", justificationStyle:String = "pushInKinsoku") {
58
super(locale, lineJustification);
9+
this.justificationStyle = justificationStyle;
10+
}
11+
12+
public function get justificationStyle():String {
13+
return this._justificationStyle;
14+
}
15+
16+
public function set justificationStyle(value:String):void {
17+
// TODO: Validate the argument
18+
this._justificationStyle = value;
19+
}
20+
21+
[API("674")]
22+
public function get composeTrailingIdeographicSpaces():Boolean {
23+
return this._composeTrailingIdeographicSpaces;
24+
}
25+
26+
[API("674")]
27+
public function set composeTrailingIdeographicSpaces(value:Boolean):void {
28+
this._composeTrailingIdeographicSpaces = value;
29+
}
30+
31+
override public function clone():TextJustifier {
32+
var copy = new EastAsianJustifier(this.locale, this.lineJustification, this.justificationStyle);
33+
copy.composeTrailingIdeographicSpaces = this.composeTrailingIdeographicSpaces;
34+
return copy;
635
}
736
}
837
}

core/src/avm2/globals/flash/text/engine/ElementFormat.as

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,17 @@ package flash.text.engine {
207207
this._typographicCase = value;
208208
}
209209

210+
public function clone():ElementFormat {
211+
var fd = this.fontDescription ? this.fontDescription.clone() : null;
212+
return new ElementFormat(
213+
fd, this.fontSize, this.color, this.alpha, this.textRotation,
214+
this.dominantBaseline, this.alignmentBaseline, this.baselineShift, this.kerning,
215+
this.trackingRight, this.trackingLeft, this.locale, this.breakOpportunity,
216+
this.digitCase, this.digitWidth, this.ligatureLevel, this.typographicCase
217+
);
218+
}
219+
220+
210221
public function getFontMetrics():FontMetrics {
211222
stub_method("flash.text.engine.ElementFormat", "getFontMetrics");
212223
var emBox:Rectangle = new Rectangle(0, _fontSize * -0.8, _fontSize, _fontSize);

core/src/avm2/globals/flash/text/engine/FontDescription.as

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package flash.text.engine {
22
import __ruffle__.stub_method;
3+
import __ruffle__.stub_getter;
4+
import __ruffle__.stub_setter;
35

46
[API("662")]
57
public final class FontDescription {
@@ -19,6 +21,8 @@ package flash.text.engine {
1921

2022
private var _cffHinting:String;
2123

24+
private var _locked:Boolean;
25+
2226
public function FontDescription(fontName:String = "_serif", fontWeight:String = "normal", fontPosture:String = "normal",
2327
fontLookup:String = "device", renderingMode:String = "cff", cffHinting:String = "horizontalStem") {
2428
this.fontName = fontName;
@@ -104,6 +108,23 @@ package flash.text.engine {
104108
this._cffHinting = value;
105109
}
106110

111+
public function get locked():Boolean {
112+
stub_getter("flash.text.engine.FontDescription", "locked");
113+
return this._locked;
114+
}
115+
116+
public function set locked(locked:Boolean):void {
117+
stub_setter("flash.text.engine.FontDescription", "locked");
118+
this._locked = locked;
119+
}
120+
121+
public function clone():FontDescription {
122+
return new FontDescription(
123+
this.fontName, this.fontWeight, this.fontPosture,
124+
this.fontLookup, this.renderingMode, this.cffHinting
125+
);
126+
}
127+
107128
public static function isFontCompatible(fontName: String, fontWeight: String, fontPosture: String): Boolean {
108129
stub_method("flash.text.engine.FontDescription", "isFontCompatible");
109130
return false;

core/src/avm2/globals/flash/text/engine/SpaceJustifier.as

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,13 @@ package flash.text.engine {
4242
public function set optimumSpacing(value:Number):void {
4343
this._optimumSpacing = value;
4444
}
45+
46+
override public function clone():TextJustifier {
47+
var copy = new SpaceJustifier(this.locale, this.lineJustification, this.letterSpacing);
48+
copy.minimumSpacing = this.minimumSpacing;
49+
copy.maximumSpacing = this.maximumSpacing;
50+
copy.optimumSpacing = this.optimumSpacing;
51+
return copy;
52+
}
4553
}
4654
}

core/src/avm2/globals/flash/text/engine/TextJustifier.as

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
package flash.text.engine {
22
import flash.utils.getQualifiedClassName;
3+
import __ruffle__.stub_getter;
4+
import __ruffle__.stub_setter;
5+
36

47
[API("662")]
58
public class TextJustifier {
69
private var _lineJustification:String = null;
10+
private var _locale:String = "en";
711
public function TextJustifier(locale:String, lineJustification:String) {
812
// TODO: Is there a better way to do this?
913
if (getQualifiedClassName(this) === "flash.text.engine::TextJustifier") {
1014
throw new ArgumentError("Error #2012: TextJustifier$ class cannot be instantiated.", 2012);
1115
}
1216

17+
// TODO: Validate locale
18+
this._locale = locale;
1319
this.lineJustification = lineJustification;
1420
}
1521

@@ -21,6 +27,11 @@ package flash.text.engine {
2127
this._lineJustification = value;
2228
}
2329

30+
public function get locale():String {
31+
stub_getter("flash.text.engine.TextJustifier", "locale");
32+
return this._locale;
33+
}
34+
2435
public function clone():TextJustifier {
2536
return null;
2637
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// mxmlc -o test.swf -debug Test.as
2+
package {
3+
import flash.display.MovieClip;
4+
public class Test extends MovieClip {
5+
public function Test() {
6+
}
7+
}
8+
}
9+
10+
import flash.text.engine.EastAsianJustifier;
11+
var eaj:EastAsianJustifier = new EastAsianJustifier();
12+
13+
var eaj2:EastAsianJustifier = eaj.clone() as EastAsianJustifier;
14+
15+
trace("trace(eaj.locale == eaj2.locale);");
16+
trace(eaj.locale == eaj2.locale);
17+
trace("trace(eaj.lineJustification == eaj2.lineJustification);");
18+
trace(eaj.lineJustification == eaj2.lineJustification);
19+
trace("trace(eaj.justificationStyle == eaj2.justificationStyle);");
20+
trace(eaj.justificationStyle == eaj2.justificationStyle);
21+
trace("trace(eaj.composeTrailingIdeographicSpaces == eaj2.composeTrailingIdeographicSpaces);");
22+
trace(eaj.composeTrailingIdeographicSpaces == eaj2.composeTrailingIdeographicSpaces);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trace(eaj.locale == eaj2.locale);
2+
true
3+
trace(eaj.lineJustification == eaj2.lineJustification);
4+
true
5+
trace(eaj.justificationStyle == eaj2.justificationStyle);
6+
true
7+
trace(eaj.composeTrailingIdeographicSpaces == eaj2.composeTrailingIdeographicSpaces);
8+
true
1.01 KB
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
num_frames = 1
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// mxmlc -o test.swf -debug Test.as
2+
package {
3+
import flash.display.MovieClip;
4+
public class Test extends MovieClip {
5+
public function Test() {
6+
}
7+
}
8+
}
9+
10+
import flash.text.engine.FontDescription;
11+
import flash.text.engine.ElementFormat;
12+
var ef:ElementFormat = new ElementFormat(new FontDescription());
13+
14+
var ef2:ElementFormat = ef.clone();
15+
16+
trace("trace(ef.fontDescription.fontName == ef2.fontDescription.fontName);");
17+
trace(ef.fontDescription.fontName == ef2.fontDescription.fontName);
18+
trace("trace(ef.fontDescription.fontWeight == ef2.fontDescription.fontWeight);");
19+
trace(ef.fontDescription.fontWeight == ef2.fontDescription.fontWeight);
20+
trace("trace(ef.fontDescription.fontPosture == ef2.fontDescription.fontPosture);");
21+
trace(ef.fontDescription.fontPosture == ef2.fontDescription.fontPosture);
22+
trace("trace(ef.fontDescription.fontLookup == ef2.fontDescription.fontLookup);");
23+
trace(ef.fontDescription.fontLookup == ef2.fontDescription.fontLookup);
24+
trace("trace(ef.fontDescription.renderingMode == ef2.fontDescription.renderingMode);");
25+
trace(ef.fontDescription.renderingMode == ef2.fontDescription.renderingMode);
26+
trace("trace(ef.fontDescription.cffHinting == ef2.fontDescription.cffHinting);");
27+
trace(ef.fontDescription.cffHinting == ef2.fontDescription.cffHinting);
28+
29+
trace("trace(ef.fontSize == ef2.fontSize);");
30+
trace(ef.fontSize == ef2.fontSize);
31+
trace("trace(ef.color == ef2.color);");
32+
trace(ef.color == ef2.color);
33+
trace("trace(ef.alpha == ef2.alpha);");
34+
trace(ef.alpha == ef2.alpha);
35+
trace("trace(ef.textRotation == ef2.textRotation);");
36+
trace(ef.textRotation == ef2.textRotation);
37+
trace("trace(ef.dominantBaseline == ef2.dominantBaseline);");
38+
trace(ef.dominantBaseline == ef2.dominantBaseline);
39+
trace("trace(ef.alignmentBaseline == ef2.alignmentBaseline);");
40+
trace(ef.alignmentBaseline == ef2.alignmentBaseline);
41+
trace("trace(ef.baselineShift == ef2.baselineShift);");
42+
trace(ef.baselineShift == ef2.baselineShift);
43+
trace("trace(ef.kerning == ef2.kerning);");
44+
trace(ef.kerning == ef2.kerning);
45+
trace("trace(ef.trackingRight == ef2.trackingRight);");
46+
trace(ef.trackingRight == ef2.trackingRight);
47+
trace("trace(ef.trackingLeft == ef2.trackingLeft);");
48+
trace(ef.trackingLeft == ef2.trackingLeft);
49+
trace("trace(ef.locale == ef2.locale);");
50+
trace(ef.locale == ef2.locale);
51+
trace("trace(ef.breakOpportunity == ef2.breakOpportunity);");
52+
trace(ef.breakOpportunity == ef2.breakOpportunity);
53+
trace("trace(ef.digitCase == ef2.digitCase);");
54+
trace(ef.digitCase == ef2.digitCase);
55+
trace("trace(ef.digitWidth == ef2.digitWidth);");
56+
trace(ef.digitWidth == ef2.digitWidth);
57+
trace("trace(ef.ligatureLevel == ef2.ligatureLevel);");
58+
trace(ef.ligatureLevel == ef2.ligatureLevel);
59+
trace("trace(ef.typographicCase == ef2.typographicCase);");
60+
trace(ef.typographicCase == ef2.typographicCase);

0 commit comments

Comments
 (0)