From 796f2e827ff77ae631498bead4be5022f2af3e1a Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Fri, 29 Nov 2024 16:27:36 +0100 Subject: [PATCH] tests: Add avm2/edittext_get_char_index_at_point test This test verifies the behavior of getCharIndexAtPoint(). --- .../edittext_get_char_index_at_point/Test.as | 154 ++++++++++++++++++ .../TestFont.ttf | Bin 0 -> 1600 bytes .../output.expected.png | Bin 0 -> 4290 bytes .../output.txt | 4 + .../edittext_get_char_index_at_point/test.swf | Bin 0 -> 3121 bytes .../test.toml | 8 + 6 files changed, 166 insertions(+) create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/Test.as create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/TestFont.ttf create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.expected.png create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.txt create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/test.swf create mode 100644 tests/tests/swfs/avm2/edittext_get_char_index_at_point/test.toml diff --git a/tests/tests/swfs/avm2/edittext_get_char_index_at_point/Test.as b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/Test.as new file mode 100644 index 0000000000000..8bae59a39aeb4 --- /dev/null +++ b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/Test.as @@ -0,0 +1,154 @@ +package { +import flash.display.Sprite; +import flash.display.Bitmap; +import flash.display.BitmapData; +import flash.text.TextField; +import flash.text.TextFormat; +import flash.geom.Rectangle; +import flash.utils.ByteArray; + +[SWF(width="400", height="400")] +public class Test extends Sprite { + [Embed(source="TestFont.ttf", fontName="TestFont", embedAsCFF="false", unicodeRange="U+0061-U+0064")] + private var TestFont:Class; + + private var colors: Array = [ + 0xFFFF0000, + 0xFF00FF00, + 0xFF0000FF, + 0xFFFFFF00, + 0xFF00FFFF, + 0xFFFF00FF, + 0xFFFFFFFF, + ]; + + private var text1: TextField; + + public function Test() { + var t1: TextField = newTextField(); + t1.htmlText = "a\naa\naaa\naa"; + renderMap(t1); + + var t2: TextField = newTextField(t1); + t2.height = 50; + t2.htmlText = ""; + renderMap(t2); + + var t3: TextField = newTextField(t2); + t3.height = 50; + t3.type = "input"; + t3.htmlText = ""; + renderMap(t3); + + var t4: TextField = newTextField(t3); + t4.type = "input"; + t4.htmlText = "aaaaaa"; + renderMap(t4); + + var t5: TextField = newTextField(null, t4); + t5.height = 50; + t5.htmlText = "\n"; + renderMap(t5); + + var t6: TextField = newTextField(t5, t4); + t6.height = 50; + t6.type = "input"; + t6.htmlText = "\n"; + renderMap(t6); + + var t7: TextField = newTextField(t6, t4); + t7.height = 50; + t7.htmlText = "a\naaa\na"; + renderMap(t7); + + var t8: TextField = newTextField(t7, t4); + t8.htmlText = "\n\na\na"; + renderMap(t8); + + var t9: TextField = newTextField(null, t8); + t9.height = 60; + t9.htmlText = "\n\n\n\n\n\n\n\n"; + t9.scrollV = 3; + renderMap(t9); + + var t10: TextField = newTextField(t9, t8); + t10.htmlText = "a\na\na\na\n"; + renderMap(t10); + + var t11: TextField = newTextField(t10, t8); + t11.height = 30; + t11.htmlText = "aaaaaaaaaaaaaaaaaaaaaaaaaa"; + t11.scrollH = 50; + trace("scrollh = " + t11.scrollH); + trace("maxscrollh = " + t11.maxScrollH); + renderMap(t11); + + var t12: TextField = newTextField(t11, t8); + t12.htmlText = "aaaaaaaaaaaaaaaaaaaaaaaaaa\n\naaaaaaaaaaaaaaaaaaaaaaaaaa"; + t12.scrollH = 50; + trace("scrollh = " + t12.scrollH); + trace("maxscrollh = " + t12.maxScrollH); + renderMap(t12); + + var t13: TextField = newTextField(t8, t4); + t13.height = 50; + t13.htmlText = "

a a a aaaa

"; + t13.wordWrap = true; + renderMap(t13); + } + + private function newTextField(lastY: TextField = null, lastX: TextField = null):TextField { + var tf = new TextFormat(); + tf.font = "TestFont"; + tf.size = 20; + tf.leading = 2; + + var field: TextField = new TextField(); + field.x = 10; + field.y = 10; + if (lastX != null) { + field.x = lastX.x + lastX.width + 12; + } + if (lastY != null) { + field.y = lastY.y + lastY.height + 12; + } + field.embedFonts = true; + field.border = true; + field.defaultTextFormat = tf; + field.width = 100; + field.height = 100; + return field; + } + + private function renderMap(field: TextField, resolution: Number = 2.0):void { + addChild(field); + var w = resolution * (field.width + 10); + var h = resolution * (field.height + 10); + var data:BitmapData = new BitmapData(w, h); + var pixels: ByteArray = new ByteArray(); + + for (var y = 0; y < h; ++y) { + for (var x = 0; x < w; ++x) { + var ix = field.getCharIndexAtPoint(x / resolution - 5, y / resolution - 5); + + var color; + if (ix == -1) { + color = 0xFF000000; + } else { + color = colors[ix % colors.length]; + } + pixels.writeUnsignedInt(color); + } + } + + pixels.position = 0; + data.setPixels(new Rectangle(0, 0, w, h), pixels); + var bitmap:Bitmap = new Bitmap(data); + bitmap.scaleX = 1 / resolution; + bitmap.scaleY = 1 / resolution; + bitmap.x = field.x - 5; + bitmap.y = field.y - 5; + addChild(bitmap); + } +} +} diff --git a/tests/tests/swfs/avm2/edittext_get_char_index_at_point/TestFont.ttf b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/TestFont.ttf new file mode 100644 index 0000000000000000000000000000000000000000..761128c1eb3c323d499229f8c34f7523983545de GIT binary patch literal 1600 zcmcgsOK4L;6g~4kX-ma^u!vA)9v1tdO<$5?t7K8s#!nGNLlIHzYnmp3{CG*Fbs;WA zL|loe3lYJc*n%MFJ}zB|t1e1cF6>g=RN|SJX>Gd@x^W)EoO|xQGw03R83+LTaStY@ z6N%)-H_u=80-+wV-Dl5CB+!Kew40TE>FRKF>h#FD9KThYr+ zA+Zr(<`%9;V;xRMZ>-~}BU--KYR0qQbB=LMZ*x#}JS&DcrrcOnoxjUnRuxG^U&QGO ze5wF=Yu|1iki;pC1#56#V}lAGX>6hgs~THq76&!9(I&<<4w0Wx6=JDc9A|G}fp(-c zHn{FxjZK`x6OApj3tM9wM}*WkME){Pql7XR;Uk9(vZz9$k8}2OjKXCf;r*1DWStin zlPA7F>@%;TZt&?+dC|{hvQ^oa>X%VBIx;9Hy+ST8FL-{b!iXf&46P!;lp;qY)0JwX zR3y4WSBATi4`#%bbY?#9`Pd3oDLy08ftoP&NStKfJ!ON9A%Y={vTrJfS|(BQGiezO zyYi&mT$(Tz85$i@djF|#ifj9np9{oGDsZ`qQldUgrTt2-RFtk83A-+d-O9H8EKg0} v)cSiW)YZlDZ{sV(6E|4R6AJO}8@dAcs`9;8mr~6kbk}pNS$!mSzL$RhFdoS* literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.expected.png b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.expected.png new file mode 100644 index 0000000000000000000000000000000000000000..2fa5264b5930b2738c96a191f384e797ab3ad4bd GIT binary patch literal 4290 zcmd5-*--n_eF#`J8f|S062&54S53qu7Li-9jHiOxNNrUfE05Zf`m8mhVrQ-G%C%;r#xuc4Q|!N6kyqopz=EaqOtcR5mss0cQTB z%>K687#E{1@Rjna19j6!S{25l&Nu*Ygxz8w5K)=v2oqo&ON0hG$=HRw`&-j9^pg+v z-JNoY{S?$<)KZK@kCqy)O0R(v)IL~1L{d@u6BE!SfRW|F8r6Y2o$Q*vB<}C{vq-3Z zRi@C}_lM7%=Mc?VzP%`mdKc{)56i)?;043|FWpIrdc44X z;S1V68?gEHc{>znOR2=*T`omh3D-vuHf!p=GrJ*LwF>~KF~UHCsU&GasY8b9Nl}W3 zDy8Mrg6sLJ^SlKyS&K}Ut*3H>Ywm|4qk z!NJzbYpO!I_6tNK(u%cwDo>tr1~Nf$QnwEzkP=ArpS0JS9ptR$jl z>ZnL*Y_QTayXCHD8)zLo7w-U2RS;0hsOtw*?=R}fBLn898#fj+-ZZFaOu#rk{fQi) z&0U+&LM(AAN(3PNYJDM~E-v)IQOzoQ-!NW*MaPz2F~ zKuxPR$8V_PX%2u6gSwu!ujAd_gkbyz$Eqh0sx9NpIFq?%cdfoqQtAP*!fI>r*|L=c&GCgVF*ECK}HRfSv`?I+&n%!gH1o{ap?H4_N z*1D!?+LXy2+sK*slJVSG>`}>nc!2Q(WR1Ne?XK5F^}qWK%+w>x%h}zf^vUPGpL(|X UN=4)j>aGXjdm=)rUWqIC7q(h-CIA2c literal 0 HcmV?d00001 diff --git a/tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.txt b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.txt new file mode 100644 index 0000000000000..ec394db79555f --- /dev/null +++ b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/output.txt @@ -0,0 +1,4 @@ +scrollh = 50 +maxscrollh = 320 +scrollh = 50 +maxscrollh = 320 diff --git a/tests/tests/swfs/avm2/edittext_get_char_index_at_point/test.swf b/tests/tests/swfs/avm2/edittext_get_char_index_at_point/test.swf new file mode 100644 index 0000000000000000000000000000000000000000..391b45738878f3f3461b9a6dfddaeff46498ceac GIT binary patch literal 3121 zcmV-149@dIS5qk>6#xKu0j*d~Y#YZFo|*lb-6bVamc-bS9n&#m#WBStDOt8;Ns(e% zv6aMjEXQ^dGs-NvE7Im)mMe=&nnrMfG$@LqN!qkWw<&t-sl5j%&;sqDpd_@p8a?I4 z&9xWx&5)F+I!;j_v}b4L%{On~`{vEeTUAic1BCvK&_Rsmdk-Rn-tYSwBQ)h^oylwS z3z1r}P^wNsZ+bZAd6h}iTw7a=-Gt*o*Yd&Vv;zq%xJ?uvv5%(G`Mm+wVV6R}7tks52-%cWB$r@mt;S`t{@ z8PpwGJ#_iX$kn-}rJGl-&7*n`guuSveCTUw3Y{lAJ3Fr%5)7$OY<$jmqCcphe+rBg>uP51f~q4XHjGv!VLBN4beX#`gcVC0?5eN@qcab z{!h_S9(@d12+g9yZM!z7kMUgQg|ARyvU0ALS&J-gYpWKRk*=4PqgGxYL$5aUgEu0V?Kk6|lJ&Qb-pci8s4@~ zz*Tn&#Jf5LsYeh(N7LYz-QQYaBMz?ancU&fnQwJSF$`uf&1n57oIK@1;YRISbqK5W z5%R6DrmcHMJci=rqc~;^vd8{fwp~;_mt}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