{"id":703,"date":"2009-08-20T18:50:39","date_gmt":"2009-08-20T11:50:39","guid":{"rendered":"http:\/\/blog.bebensiganteng.com\/?p=8"},"modified":"2016-03-14T08:03:50","modified_gmt":"2016-03-14T08:03:50","slug":"arabic-flash","status":"publish","type":"post","link":"https:\/\/rahmat-hidayat.com\/?p=703","title":{"rendered":"Arabic Flash"},"content":{"rendered":"<p>The first time I came to Dubai I had to do the inevitable, grueling with bidirectional text with dubious deadlines, at first I was shocked, appalled, and frustrated with flash, here&#8217;s a software which has been established for a decade but still couldn&#8217;t manage how to parse a proper Arabic yet Arabic is one most spoken language in the world you can imagine how massive the market is.<\/p>\n<p>But after the 4th <a href=\"http:\/\/en.wikipedia.org\/wiki\/K%C3%BCbler-Ross_model\">stages of grief<\/a> I have finally come to accept flash weaknesses and tried to explore new circumvention.<\/p>\n<p>There is a licensed parser out <a href=\"http:\/\/www.arabicode.com\/ar\/flaraby\/swf\/\">there<\/a> but like a cat I&#8217;m curious.<\/p>\n<div class=\"full-image\">\n<object width=\"600\" height=\"400\"><param name=\"movie\" value=\"http:\/\/labs.bebensiganteng.com\/flash\/arabicdecoder\/Default.swf\"><\/param><param name=\"allowFullScreen\" value=\"false\"><\/param><param name=FlashVars VALUE=\"xmlPath=http:\/\/labs.bebensiganteng.com\/flash\/arabicdecoder\/Arabic.xml\"><\/param><param name=\"allowscriptaccess\" value=\"always\"><\/param><embed src=\"http:\/\/labs.bebensiganteng.com\/flash\/arabicdecoder\/Default.swf\" type=\"application\/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" FlashVars=\"xmlPath=http:\/\/labs.bebensiganteng.com\/flash\/arabicdecoder\/Arabic.xml\" width=\"600\" height=\"400\"><\/embed><\/object>\n<\/div>\n<p>As you can see although is not perfect, because it doesn&#8217;t support embedded Text (and only for windows) so if you don&#8217;t have any Arabic language supported you wont be able to view the proper sentences also it only supports a few major fonts which has Unicode Arabic glyph, such as Tahoma and Times Roman. But despite all the flaws I had finally managed to have dynamic Arabic text directly feeding the Flash TextField.<\/p>\n<p>How the Arabic is parsed, in a nutshell, is simply just inverting the letter order, basically when you add an Arabic text in Flash, it will ignore that as an bidirectional text. To  illustrate plainly in English &#8220;how are you&#8221; in flash will be parsed as &#8220;uoy era woh&#8221;, below are the core function which I&#8217;ve used to reversed the order.<\/p>\n<pre class=\"brush: as3; title: ; notranslate\" title=\"\">package com.arabicDecoderAS3.core {\r\n\t\r\n\t\/**\r\n\t* ...\r\n\t* @author Rahmat Hidayat\r\n\t*\/\r\n\t\r\n\timport com.arabicDecoderAS3.tools.*;\r\n\timport com.arabicDecoderAS3.data.Constant;\r\n\t\r\n\tpublic class Decoder {\r\n\t\t\r\n\t\tprotected var _count:int = 0;\r\n\t\t\r\n\t\tprotected var _currValue:*;\r\n\t\tprotected var _prevValue:*;\r\n\t\t\r\n\t\tpublic function Decoder() \r\n\t\t{\r\n\t\t\t\r\n\t\t}\r\n\t\t\r\n\t\tprivate function restructureString(aTarget:Array):Array\r\n\t\t{\r\n\t\t\tvar aSentence:Array = [];\t\t\t\r\n\t\t\t\t\t\t\r\n\t\t\tfor(var i:int = 0; i &amp;lt; aTarget.length; i++)\r\n\t\t\t{\t\t\t\t\r\n\t\t\t\tif(ASCIIChecker.isLatin(aTarget[i].charCodeAt(0))) \r\n\t\t\t\t{\r\n\t\t\t\t\t_currValue = (aTarget[i].charCodeAt(0) == 32 &amp;amp;amp;&amp;amp;amp; _currValue != -1) ? Constant.SPACE : aTarget[i].charCodeAt(0);\r\n\t\t\t\t\t\r\n\t\t\t\t\taSentence.unshift(aTarget[i].charCodeAt(0));\t\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\treturn aSentence;\t\t\t\t\r\n\t\t\t\t}\t\t\t\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t_currValue \t= -1;\r\n\t\t\t\t\t_count \t\t= 0;\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\taSentence.push(aTarget[i].charCodeAt(0));\t\t\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn aSentence;\r\n\t\t}\r\n\r\n\t\tprivate function rebuildText(aTarget:Array):String\r\n\t\t{\r\n\t\t\tvar sResult:String \t= '';\r\n\t\t\t\t\t\r\n\t\t\tfor(var i:int = 0; i &amp;lt; aTarget.length; i++)\r\n\t\t\t{\t\t\t\t\t\t\r\n\t\t\t\tfor(var j:int = 0; j &amp;lt; aTarget[i].length; j++)\r\n\t\t\t\t{\t\t\t\r\n\t\t\t\t\tif (ASCIIChecker.isLatin(aTarget[i][j])) sResult += String.fromCharCode(Constant.RLM);\r\n\t\t\t\t\t\r\n\t\t\t\t\t(aTarget[i][j] == Constant.SPACE) ? sResult += String.fromCharCode(32) : sResult += String.fromCharCode(aTarget[i][j]);\t\t\t\/\/Temporary Solution, for what?? \t\t\t\t\t\r\n\t\t\t\t}\t\t\t\t\t\r\n\t\t\t}\t\r\n\t\t\t\r\n\t\t\treturn sResult;\t\t\t\r\n\t\t}\r\n\t\t\r\n\/\/ EXECUTION\r\n\/\/ -------------------------------------------\r\n\r\n\t\t\/**\r\n\t\t * \r\n\t\t * @param\taTarget: is the splitted string\r\n\t\t * @return\r\n\t\t *\/\r\n\t\tpublic function getCode(aTarget:Array):String\r\n\t\t{\t\t\t\r\n\t\t\tvar aTemp:Array \t= [];\r\n\t\t\tvar aResult:Array \t= [];\r\n\t\t\tvar n:int;\r\n\t\t\t\t\r\n\t\t\twhile(aTarget.length &amp;gt; 0)\r\n\t\t\t{\t\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\taTemp \t= restructureString(aTarget);\r\n\t\t\t\tn \t\t= aTemp.length;\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\tif (ASCIIChecker.isNumber(_currValue) || ASCIIChecker.isLetter(_currValue) || _currValue == Constant.SPACE )\t\/\/ SPACE still a hack\r\n\t\t\t\t{\t\t\t\t\t\t\r\n\t\t\t\t\t(_count == 0) ? _count = IndexChecker.getIndex(aResult, _prevValue) : _count++;\r\n\t\t\t\t\r\n\t\t\t\t\tif (_count != -1) \r\n\t\t\t\t\t{\r\n\t\t\t\t\t\t\/\/ This when we reversed the Latin text\r\n\t\t\t\t\t\taResult = aResult.splice(0, _count + 1).concat(new Array([ _currValue ])).concat(aResult);\t\r\n\t\t\t\t\t}\r\n\t\t\t\t\telse\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\taResult.unshift(aTemp);\t\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\taResult.unshift(aTemp);\t\r\n\t\t\t\t}\t\t\t\t\t\r\n\t\t\t\t\r\n\t\t\t\taTarget.splice(0, n);\r\n\t\t\t\t\r\n\t\t\t\t_prevValue = _currValue;\t\t\t\t\t\r\n\t\t\t\r\n\t\t\t}\r\n\t\t\t\r\n\t\t\treturn rebuildText(aResult);\r\n\t\t}\r\n\t\t\r\n\t\t\r\n\t}\r\n\t\r\n}<\/pre>\n<p>The other significant elements are the ASCIIChecker and English reversing-reversal, Tahoma for example has a complete array of glyphs and the Latin glyphs are addressed in the range of decimal order of 32-255 as for Arabic glyphs it will be addressed in Unicode order, using a simple ASCIIChecker we can segregate the Latin character from the Arabic character.<\/p>\n<p>And the last element is the English reversing-reversal ( it&#8217;s a funny name I know ) which is simply reversing the Latin words back to its correct order.<\/p>\n<p>But again without embedding the ultimate solution cannot be achieve and due to my lack of knowledge in Arabic I&#8217;ve reached the cul de sac of Arabic Flash, because embedding Arabic is highly possible but the problem is Arabic fonts are encoded differently from Unicode fonts. One example is the AXT font, by dissecting the character code it can be found that it does not employ Unicode to wrap the Arabic glyphs which is why windows fail to translate this as a bidirectional text.<\/p>\n<p>I really want to make this Arabic parser as an open source project, if anybody could help me perfecting this -at least until Adobe unleash a real parser- hop in and join my band wagon.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first time I came to Dubai I had to do the inevitable, grueling with bidirectional text with dubious deadlines, at first I was shocked, appalled, and frustrated with flash, here&#8217;s a software which has been established for a decade but still couldn&#8217;t manage how to parse a proper Arabic yet Arabic is one most [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,31],"tags":[73,96,97],"_links":{"self":[{"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/posts\/703"}],"collection":[{"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=703"}],"version-history":[{"count":1,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions"}],"predecessor-version":[{"id":1626,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=\/wp\/v2\/posts\/703\/revisions\/1626"}],"wp:attachment":[{"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=703"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=703"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahmat-hidayat.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=703"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}