{"id":963,"date":"2012-07-10T16:57:39","date_gmt":"2012-07-10T14:57:39","guid":{"rendered":"http:\/\/ixdc.net\/blog\/?page_id=963"},"modified":"2018-05-05T03:56:56","modified_gmt":"2018-05-05T01:56:56","slug":"arabic","status":"publish","type":"page","link":"https:\/\/ixdc.net\/blog\/arabic\/","title":{"rendered":"Arabic Parsing"},"content":{"rendered":"<p>An Arabic parsing script for proper Arabic readability on Flash Player 8 and 9 without the use of Adobe Text Layout Framework, runs on the client-side with no need to migrating older projects for Flash Player 10 ..<\/p>\n<p>You can change Font, Color, Size, .., etc freely using your software.<br \/>\n<span id=\"info-ar\" style=\"display:inline-block; width:500px; text-align:right;\"><br \/>\n\u064a\u0645\u0643\u0646\u0643 \u062a\u063a\u064a\u064a\u0631 \u0627\u0644\u062e\u0637\u060c \u0627\u0644\u0644\u0648\u0646\u060c \u0627\u0644\u062d\u062c\u0645\u060c ..\u060c \u0627\u0644\u062e \u0628\u0645\u0646\u062a\u0647\u0649 \u0627\u0644\u062d\u0631\u064a\u0629 \u0645\u0646 \u062e\u0644\u0627\u0644 \u0627\u0644\u0628\u0631\u0646\u0627\u0645\u062c \u0627\u0644\u062e\u0627\u0635 \u0628\u0643<br \/>\n<\/span><\/p>\n<p><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"500\" height=\"440\" codebase=\"https:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"scale\" value=\"noscale\" \/><param name=\"base\" value=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/flash\/\" \/><param name=\"src\" value=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/flash\/arabicinput.swf\" \/><embed type=\"application\/x-shockwave-flash\" width=\"500\" height=\"440\" src=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/flash\/arabicinput.swf\" base=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/flash\/\" scale=\"noscale\"><\/embed><\/object><\/p>\n<p><b>Latest Version: 3.2<\/b><\/p>\n<p>You can integrate my parser into your library as open-source under <a href=\"https:\/\/www.gnu.org\/copyleft\/gpl.html\" target=\"_blank\">GNU GPL<\/a> license.<\/p>\n<blockquote><p>\n<i>ActionSctipt 2.0 open-source files available <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/parsearabic_as2_v3.2.zip\" target=\"_self\">here<\/a><\/i><br \/>\n<i>ActionSctipt 3.0 open-source files available <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/parsearabic_as3_v3.2.zip\" target=\"_self\">here<\/a><\/i><br \/>\n<i>Action Input source files available <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/arabicinput_as2.zip\" target=\"_self\">here<\/a><\/i><br \/>\n<i>Action for iOS source files available <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/arabic_ios.zip\" target=\"_self\">here<\/a><\/i>\n<\/p><\/blockquote>\n<p><b>Older Versions:<\/b><\/p>\n<blockquote><p>\n<a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/parsearabic_as2_v1.9.zip\" target=\"_self\">1.9 (AS2)<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/themes\/ixdc\/arabic\/parsearabic_as3_v1.9.zip\" target=\"_self\">1.9 (AS3)<\/a><br \/><a href=\"http:\/\/ixdc.net\/blog\/2011\/04\/08\/open-source-arabic-parsing-v1-8\/\" target=\"_self\">1.8<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2011\/03\/31\/open-source-arabic-parsing-v1-7\/\" target=\"_self\">1.7<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2011\/03\/21\/open-source-arabic-parsing-v1-6\/\" target=\"_self\">1.6<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2010\/07\/12\/open-source-arabic-parsing-v1-5\/\" target=\"_self\">1.5<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2010\/05\/29\/actionscript-2-0-arabic-parsing-v1-4\/\" target=\"_self\">1.4<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2010\/05\/23\/actionscript-2-0-arabic-parsing-v1-3\/\" target=\"_self\">1.3<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2010\/03\/26\/actionscript-2-0-arabic-parsing-v1-2\/\" target=\"_self\">1.2<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2010\/01\/26\/actionscript-2-0-arabic-parsing-v1-1\/\" target=\"_self\">1.1<\/a>, <a href=\"http:\/\/ixdc.net\/blog\/2009\/12\/21\/arabic-text-in-actionscript-2-0\/\" target=\"_self\">1.0<\/a>\n<\/p><\/blockquote>\n<p><b>ActionSctipt 2.0 Usage:<\/b><\/p>\n<pre lang=\"actionscript\">\r\nimport net.ixdc.utils.StringUtils;\r\nvar utils:StringUtils = new StringUtils();\r\nutils.wrapFactor = .8; \/\/ optional\r\n\r\nvar format:TextFormat = new TextFormat();\r\nformat.font = \"Arial\";\r\nformat.size = 14;\r\nformat.align = \"right\";\r\nformat.rightMargin = 4;\r\n\r\nvar output:TextField = this.createTextField(\"output\", 1, 10, 10, Stage.width-20, format.size);\r\noutput.autoSize = true;\r\noutput.embedFonts = true;\r\noutput.wordWrap = true;\r\noutput.multiline = true;\r\noutput.html = true;\r\n\r\nvar xml:XML = new XML();\r\nxml.ignoreWhite = true;\r\nxml.onLoad = function(done:Boolean) {\r\n\tif (done) {\r\n\t\toutput.htmlText = utils.parseArabic(this.firstChild.firstChild.nodeValue, output._width, format);\r\n\t}\r\n}\r\nxml.load(\"arabic.xml\");\r\n<\/pre>\n<p><b>ActionSctipt 3.0 Usage:<\/b><\/p>\n<pre lang=\"actionscript\">\r\npackage {\r\n\timport flash.display.Sprite;\r\n\timport flash.events.Event;\r\n\timport flash.net.URLLoader;\r\n\timport flash.net.URLRequest;\r\n\timport flash.text.TextField;\r\n\timport flash.text.TextFieldAutoSize;\r\n\timport flash.text.TextFormat;\r\n\timport flash.events.MouseEvent;\r\n\timport net.ixdc.utils.StringUtils;\r\n\tpublic class ProperArabicTextAS3 extends Sprite {\r\n\t\tpublic var utils:StringUtils;\r\n\t\tpublic var format:TextFormat;\r\n\t\tpublic var output:TextField;\r\n\t\tpublic function ProperArabicTextAS3() {\r\n\t\t\tutils = new StringUtils();\r\n\t\t\tutils.wrapFactor = .8; \/\/ optional\r\n\t\t\toutput = new TextField();\r\n\t\t\toutput.width = stage.stageWidth-20;\r\n\t\t\toutput.autoSize = TextFieldAutoSize.LEFT;\r\n\t\t\toutput.embedFonts = true;\r\n\t\t\toutput.wordWrap = true;\r\n\t\t\toutput.multiline = true;\r\n\t\t\taddChild(output);\r\n\t\t\tformat = new TextFormat();\r\n\t\t\tformat.font = \"Arial\";\r\n\t\t\tformat.size = 14;\r\n\t\t\tformat.align = \"right\";\r\n\t\t\tformat.rightMargin = 4;\r\n\t\t\tvar xmlLoader:URLLoader = new URLLoader();\r\n\t\t\txmlLoader.addEventListener(Event.COMPLETE, showXML);\r\n\t\t\txmlLoader.load(new URLRequest(\"arabic.xml\"));\r\n\t\t}\r\n\t\tpublic function showXML(event:Event):void {\r\n\t\t\tXML.ignoreWhitespace = true; \r\n\t\t\tvar arabic:XML = new XML(event.target.data);\r\n\t\t\toutput.htmlText = utils.parseArabic(arabic.text(), output.width, format);\r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p><b>Sample XML:<\/b><\/p>\n<pre lang=\"xml\">\r\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<arabic>\r\n\t<![CDATA[\u0627\u0644\u0647\u062f\u0641 \u0645\u0646 \u0644\u0639\u0628\u0629 \u0627\u0644\u0643\u0644\u0645\u0627\u062a \u0627\u0644\u0645\u062a\u0642\u0627\u0637\u0639\u0629 \u0647\u0648 \u0645\u0644\u0621 \u0627\u0644\u0645\u0631\u0628\u0639\u0627\u062a \u0627\u0644\u0628\u064a\u0636\u0627\u0621\u060c \u0648\u062a\u0634\u0643\u064a\u0644 \u0627\u0644\u0643\u0644\u0645\u0627\u062a \u0623\u0648 \u0627\u0644\u0639\u0628\u0627\u0631\u0627\u062a\u060c \u0639\u0646 \u0637\u0631\u064a\u0642 \u062d\u0644 \u0627\u0644\u0642\u0631\u0627\u0626\u0646 \u0627\u0644\u062a\u064a \u062a\u0624\u062f\u064a \u0625\u0644\u0649 \u0625\u062c\u0627\u0628\u0627\u062a. \u0648\u0627\u0644\u0645\u0631\u0628\u0639\u0627\u062a \u0627\u0644\u0633\u0648\u062f\u0627\u0621 \u062a\u0633\u062a\u062e\u062f\u0645 \u0644\u0641\u0635\u0644 \u0627\u0644\u0643\u0644\u0645\u0627\u062a \u0623\u0648 \u0627\u0644\u0639\u0628\u0627\u0631\u0627\u062a. \u0648\u064a\u0648\u0636\u0639 \u0644\u0643\u0644 \u0635\u0641 \u0623\u0648 \u0639\u0645\u0648\u062f \u0631\u0642\u0645\u060c \u062b\u0645 \u064a\u0643\u062a\u0628 \u0623\u0645\u0627\u0645 \u0627\u0644\u0631\u0642\u0645 \u0645\u0627 \u064a\u0634\u0627\u0628\u0647 \u0627\u0644\u0643\u0644\u0645\u0629 \u0627\u0644\u0645\u0637\u0644\u0648\u0628 \u0643\u062a\u0627\u0628\u062a\u0647\u0627 \u0641\u064a \u0627\u0644\u0645\u0631\u0628\u0639\u0627\u062a\u060c \u0648\u062a\u062d\u0648\u064a \u0627\u0644\u0645\u062c\u0644\u0627\u062a \u0623\u0646\u0648\u0627\u0639\u0627 \u0645\u0646 \u0647\u0630\u0647 \u0627\u0644\u0644\u0639\u0628\u0629\u061b \u0641\u0645\u0646\u0647\u0627 \u0633\u0647\u0644 \u0648\u0622\u062e\u0631 \u0635\u0639\u0628\u060c \u0648\u0627\u0644\u0643\u0644\u0645\u0627\u062a \u0627\u0644\u0645\u062a\u0642\u0627\u0637\u0639\u0629 \u0641\u064a \u0645\u062c\u0644\u0629 \u0645\u0639\u064a\u0646\u0629 \u062a\u062a\u0628\u0639 \u0623\u0633\u0644\u0648\u0628 \u064a\u062e\u062a\u0644\u0641 \u0639\u0646 \u0627\u0644\u0623\u062e\u0631\u0649\u060c \u062a\u0628\u0639\u0627 \u0644\u0623\u0633\u0644\u0648\u0628 \u0627\u0644\u0644\u063a\u0629 \u0627\u0644\u0645\u0633\u062a\u0639\u0645\u0644\u0629 \u0648\u0627\u0644\u0628\u0644\u062f\u060c \u0648\u062a\u0642\u0648\u0645 \u0627\u0644\u0645\u062c\u0644\u0627\u062a \u0648\u0627\u0644\u0635\u062d\u0641 \u0628\u0648\u0636\u0639 \u0647\u0630\u0647 \u0627\u0644\u0644\u0639\u0628\u0629 \u0644\u062a\u0633\u0644\u064a\u0629 \u0627\u0644\u0642\u0631\u0627\u0621. \u0638\u0647\u0631\u062a \u0623\u0648\u0644 \u0644\u0639\u0628\u0629 \u0644\u0644\u0643\u0644\u0645\u0627\u062a \u0627\u0644\u0645\u062a\u0642\u0627\u0637\u0639\u0629 \u0641\u064a \u0635\u062d\u064a\u0641\u0629 newyork world \u0648\u0630\u0644\u0643 \u0641\u064a 21 \u062f\u064a\u0633\u0645\u0628\u0631 \u0639\u0627\u0645 1913\u060c \u0648\u0623\u0635\u0628\u062d\u062a \u0645\u0646 \u0627\u0644\u0623\u0644\u0639\u0627\u0628 \u0627\u0644\u0631\u0627\u0626\u062c\u0629 \u0641\u064a \u0627\u0644\u0648\u0644\u0627\u064a\u0627\u062a \u0627\u0644\u0645\u062a\u062d\u062f\u0629\u060c \u0648\u0645\u0646\u0647\u0627 \u0627\u0646\u062a\u0642\u0644\u062a \u0625\u0644\u0649 \u0628\u0642\u064a\u0629 \u062f\u0648\u0644 \u0627\u0644\u0639\u0627\u0644\u0645\u060c \u0648\u0628\u0645\u062e\u062a\u0644\u0641 \u0627\u0644\u0644\u063a\u0627\u062a\u060c \u0648\u0643\u0627\u0646 \u0623\u0648\u0644 \u0645\u0646 \u0623\u062f\u062e\u0644\u0647\u0627 \u0625\u0644\u0649 \u0627\u0644\u0635\u062d\u0627\u0641\u0629 \u0647\u0648 \u0622\u0631\u062b\u0631 \u0648\u064a\u0646.]]>\r\n<\/arabic>\r\n<\/pre>\n<p><em>Features Supported:<\/em><\/p>\n<ol>\n<li>Embedding Fonts (just put a dynamic textfield on-stage and select at least Basic Latin (95 glyphs) and Arabic (1088 glyphs) from the Character Embedding menu).<\/li>\n<li>Arabic Ligatures.<\/li>\n<li>Arabic Diacritics. (<i>Fonts must support diacritics<\/i>)<\/li>\n<li>Word Wrapping.<\/li>\n<li>Bi-Directional text.<\/li>\n<li>HTML Text. (<i>Optional using <span style=\"color:#EF6596;\">StringUtils<\/span> class, otherwise, kindly use the light version with <span style=\"color:#EF6596;\">ArabicLight<\/span> class, both classes are included in the sample files above<\/i>)<\/li>\n<li>Loading External text on run-time.<\/li>\n<li>Windows\/Mac\/Linux support.<\/li>\n<li>Arabic enabled input fields using actionscript method (createArabicInput) with the help of javascript (arabicinput.js) <em>beta<\/em><\/li>\n<li>Urdu support.<\/li>\n<\/ol>\n<p><em>Requirements:<\/em><\/p>\n<ol>\n<li>Dynamic TextField.<\/li>\n<li>HTML enabled TextField.<\/li>\n<li>pre-assigned TextFormat.<\/li>\n<li>Arabic fonts. <i>must have Form-B unicode representations<\/i><\/li>\n<li>Urdu fonts. <i>must have Form-A unicode representations<\/i><\/li>\n<\/ol>\n<p><em>Properties:<\/em><\/p>\n<ol>\n<li>data: for referencing original input string.<\/li>\n<li>wrapFactor: optional reduction value (Mac only) for wrapping correction when using bi-directional text  (default = 0.9).<\/li>\n<li>htmlLines: array of spliced text block HTML lines.<\/li>\n<li>embedFonts: boolean (default = true).<\/li>\n<li>hindiNumeralsOnly: boolean (default = false).<\/li>\n<\/ol>\n<p><em>Omitted Properties:<\/em><\/p>\n<ol>\n<li>latinOnly<\/li>\n<li>americanFormat<\/li>\n<\/ol>\n<p>For the font embedding and reducing file size, you can use shared fonts, and port those from a different server, follow <a href=\"http:\/\/ixdc.net\/blog\/2010\/07\/08\/arabic-parsing-and-shared-fonts\/\" target=\"_self\">this<\/a> guide ..<\/p>\n<h3>Detailed Case Study<\/h3>\n<p><b>Problem:<\/b><\/p>\n<p>\nWell, this issue is a very old one, I\u2019ve always experienced annoying problems each time I try to render Arabic text on run-time using Flash and ActionScript 2.0, Flash doesn\u2019t support right-to-left languages, and when it comes to Arabic, we are talking about proper characters joining and word wrapping.\n<\/p>\n<p><b>Analysis of Alternatives:<\/b><\/p>\n<p>\nI never stopped tracking this specific issue to find any new solution has been developed somewhere, for a long time I can only find <a href=\"https:\/\/www.arabicode.com\/\" target=\"_blank\">this<\/a> paid solution.<\/p>\n<p>The guy one had it perfectly solved, he was having his solution implemented using ActionScript 2.0 at some point earlier, but he stopped publishing that and left his latest version only, which works with ActionScript 3.0.<\/p>\n<p>Recently, Adobe has announced that they finally support right-to-left languages along with bi-directional and complex script ones, only using ActionScript 3.0 and it requires Flash Player 10 or above, they even have an open source framework called Text Layout Framework, it\u2019s perfect actually, it should put an end to this issue, but ..<\/p>\n<p>I have my own objections; I made my quick test <a href=\"http:\/\/ixdc.net\/blog\/wp-content\/uploads\/2009\/12\/arabic_as2\/arabic_as3.zip\" target=\"_self\">here<\/a> to check their new technique.<\/p>\n<p>Arabic text is finally rendered properly, but why we have to add so many childs to our display list from different TextLines and TextBlocks instead of a single TextField?<br \/>\nAlso we have to set a max width, and I couldn\u2019t find a way to scroll through text without using a custom scroller and masking the text just like any other MovieClip or DisplayObject, personally, I find this much complicated solution just to display simple Arabic string properly!<\/p>\n<p>On the other hand, there are others who developed complex solutions developed in ActionScript 2.0 for Arabic speakers, and they\u2019re definitely facing hell to convince their clients to migrate their projects to ActionScript 3.0, an easy solution for ActionScript 2.0 would save the day.<\/p>\n<p>I do like ActionScript 2.0 a lot more, not just for handling text easily, also for one other important reason, which is memory Management!<br \/>\nActionScript 3.0 new DisplayList structure has many features yes, but it kills innovation by relaying objects disposal to Flash Player\u2019s Garbage Collector alone, there\u2019s no supported way to destroy objects manually during run-time, unlike ActionSciript 2.0, and I find that an extremely rough obstacle when using ActionScript 3.0.\n<\/p>\n<p><b>Implementation:<\/b><\/p>\n<p>\nIn a nutshell, ActionScript 2.0 used to refuse right-to-left languages, so we can\u2019t embed fonts, wrap text properly, and when it comes to Arabic text we also see our characters splitted which is inappropriate for Arabic readers, the old solution for this was loading text encoded in UTF-8 from external text\/xml files, and still no word wrapping, and on Mac machines Arabic letters still splitted, we can align text but its direction still not right-to-left.<\/p>\n<p>So, logically, I know that I have to construct my Arabic text manually, to achieve that I had to analyze Arabic rules for character joining with all its special cases, and then find a way to force its direction to be left-to-right, and the word wrapping part is not that hard after all, this is basically what I did actually!<\/p>\n<p>My only problem was in finding a way to inject all proper Arabic characters with its unique cases, for a long time I found that very difficult, Flash doesn\u2019t allow me to copy those from other text processing tools, and of course there\u2019s no way to type each character a lone in different cases using keyboard.<\/p>\n<p>Finally, I found a way to do that, and it was very simple, I found the following charts at <a href=\"https:\/\/www.unicode.org\/charts\/\" target=\"_blank\">Unicode<\/a> official website.<\/p>\n<p>That\u2019s it! Now I can instruct ActionScript 2.0 to handle my Arabic characters properly, by looping through the input string and replacing each Arabic character with it\u2019s proper glyph according to it\u2019s position within each word with a few conditions to maintain Arabic Grammar.<\/p>\n<p>The task is basically easy, but when turning that to a complete bi-directional solution, things got a little bit complicated, but it the results were very good.\n<\/p>\n<p><b>Results:<\/b><\/p>\n<p>\nMy favorite justification is for one of my clients, <a href=\"https:\/\/hafez.com.eg\/\" target=\"_blank\">Hafez Avocats<\/a>.<br \/>\nData-driven, Multilingual, and Flash-based website developed in ActionScript 2.0 using this solution, the performance is stunning.<\/p>\n<p>A JavaScript <a href=\"http:\/\/ixdc.net\/blog\/2011\/01\/12\/arabic-web-fonts-on-ios-resolved\/\" target=\"_self\">version<\/a> of this solution to resolve custom Arabic fonts on mobile Safari for iOS.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An Arabic parsing script for proper Arabic readability on Flash Player 8 and 9 without the use of Adobe Text Layout Framework, runs on the client-side with no need to migrating older projects for Flash Player 10 .. You can change Font, Color, Size, .., etc freely using your software. \u064a\u0645\u0643\u0646\u0643 \u062a\u063a\u064a\u064a\u0631 \u0627\u0644\u062e\u0637\u060c \u0627\u0644\u0644\u0648\u0646\u060c \u0627\u0644\u062d\u062c\u0645\u060c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-963","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/pages\/963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/comments?post=963"}],"version-history":[{"count":65,"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/pages\/963\/revisions"}],"predecessor-version":[{"id":1217,"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/pages\/963\/revisions\/1217"}],"wp:attachment":[{"href":"https:\/\/ixdc.net\/blog\/wp-json\/wp\/v2\/media?parent=963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}