Skip to main content

Open-Source Arabic Parsing v1.5

(4 votes, average: 5.00 out of 5)

Update: a newer version available here

Now you can integrate my parser into your library as open-source under GNU GPL license ..

ActionSctipt 2.0 version available here
ActionSctipt 3.0 version available here

Features Supported:

  1. 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).
  2. Arabic Ligatures.
  3. Word Wrapping.
  4. Bi-Directional text.
  5. HTML Text.
  6. Loading External text on run-time.
  7. Windows/Mac/Linux support.
  8. Arabic enabled input fields using actionscript method (createArabicInput) with the help of javascript (arabicinput.js) beta

Features Not Supported:

  1. Arabic Diacritics (not necessarily for reading Arabic language in general, arabs are using diacritics mostly for writing Quran, and in that case diacritics are not the only missing feature, there’re many other ligatures cases in Arabic used for Quran writing).

You can use the old example found here, just replace the StringUtils.as class file ..

20 thoughts to “Open-Source Arabic Parsing v1.5”

  1. Dear IDX,

    First of all i would like to thank for this generous utility for arabic support,

    So far, i have used your utility for all flash player 8 and its work well, now i got stuck as i have one project done with support of flash player 6 when i tried this utility with flash 6 i got an error on line 138 infact you have define there to use static depth() but i am not much familiar with AS much, kindly help what i have to change to make this useful with flash6 thanks a lot in advance

  2. am using textArea component for arabic text and getting error? is it possible to fix it?

    import com.xvisage.utils.StringUtils;

    var utils:StringUtils;
    var format:TextFormat;

    utils = new StringUtils();
    utils.wrapFactor = .98;

    format = new TextFormat();
    format.color = 0x333333;
    format.font = “Arial”;
    format.size = 14;
    format.align = “right”;

    output.textField.mouseEnabled = false;
    output.editable = false;
    output.setStyle(“upSkin”,Sprite);

    var xmlData:XML = new XML();
    xmlData.ignoreWhitespace = true;

    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, showXML);

    var xmlPath:String = “arb.xml”;
    xmlLoader.load(new URLRequest(xmlPath));

    function showXML(e:Event):void {
    xmlData = new XML(e.target.data);
    output.htmlText = utils.parseArabic(xmlData.text(), output, format);
    output.setStyle(“textFormat”, format);
    }

  3. @Asim

    Try this:

    import com.xvisage.utils.StringUtils;
     
    var utils:StringUtils;
    var format:TextFormat;
     
    utils = new StringUtils();
    utils.wrapFactor = .98; // optional value for Mac use only
     
    format = new TextFormat();
    format.color = 0x333333;
    format.font = "Arial";
    format.size = 14;
    format.align = "right";
     
    output.textField.mouseEnabled = false;
    output.editable = false;
    output.setStyle("upSkin",Sprite);
     
    // the following 2 lines for proper Font embedding to the TextArea
    // note that the actual font "Arial" need to be embedded
    output.setStyle("embedFonts",true);
    output.textField.embedFonts = true;
     
    // the following line for adjusting the inner textField width
    output.textField.width = output.width;
     
    var xmlData:XML = new XML();
    xmlData.ignoreWhitespace = true; 
     
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE, showXML);
    var xmlPath:String = "arb.xml";
    xmlLoader.load(new URLRequest(xmlPath));
     
    function showXML(e:Event):void {
    	xmlData = new XML(e.target.data);
    	// we need to pass the inner textField instead
    	output.htmlText = utils.parseArabic(xmlData.text(), output.textField, format);
    	// setting TextFormat for the TextArea using styles insead
    	output.setStyle("textFormat", format);
    }
  4. @Hassan

    The wrapFactor used to limit the amount of words per line for specific fonts combination, it’s an optional value with a default of 1.0 which is the max. value as well ..
    In other words, you can use values less than 1.0 only, that factor will not increase the amount of words per line, it will reduce them instead ..
    Looks like you’re having a new issue here, try to comment the lines responsible for line breaks:

    AS2: from line 702 to line 711
    AS3: from line 678 to line 687

    And use the following code snippet instead:

    AS2:

    if (Math.ceil(temp._width)>=(tag._width*wrapFactor)-(format.leftMargin ? Number(format.leftMargin) : 0)-(format.rightMargin ? Number(format.rightMargin) : 0)) {
    	measureLine = true;
    }

    AS3:

    if (Math.ceil(temp.width)>=tag.width-(format.leftMargin ? Number(format.leftMargin) : 0)-(format.rightMargin ? Number(format.rightMargin) : 0)) {
    	measureLine = true;
    }
  5. Hey there,

    First of all, thanks for a brilliant piece of work! I have found it incredibly useful.

    In my project I need to implement text input fields, I am aware that you have this functionality but cannot seem to find a working example on this site. The fla from the v3 link won’t open in my version of flash.

    Could post a link to the files I need?

    Many thanks

    G

  6. Hello there,

    First of all, let me thank you for the amazing effort. It really makes life easy for many of us!

    I just have a bit of problem. I’m going to use it for Persian and when I do I find some letters detached. I can send you an example. I would greatly appreciate it if you could take a look at it.

  7. Hi there,

    I tried NOT to embed the font and use a truetype font. It works fine with the font “Traditional Arabic” in your example! But if I use something else like “Arabic Typesetting Standard” or “Arial Unicode MS Standard” nothing shows up. What’s the problem?

  8. First off, thank you so much for your contribution. It has really helped a lot.

    Do you know of any way I can convert an AS1 file to arabic?

    Thanx

  9. It appears that symbols are a problem. Inverted Commas and Brackets appear incorrectly. Full Stops and Comma’s, when used at the end of a sentence, still preview on the right, instead of the left.

  10. Hey there,

    I just stumbled upon your Arabic Parsing class, and I have to say this is really awesome stuff !! You really made my day/month/year. Thank you so much for your effort.

    I’m wondering if you’ll keep working to improve the rendering of text without font embedding.

    Thanks again 🙂

  11. Hi,

    I want to say thank you for this great script, it made my life a lot easier!

    But i have one problem. I have a large ammount of text in arabic, about 300 pages. It all shows correctly, except arabic numbers. In teh text the numbers are in arabic. But in the text i have the numbers are allready in the correct order, but this script puts them reversed. For exemple, 2010 becomes 0102 in the arabic text.

    Is there any way to correct this?

    Thanks in advance.

  12. Hi,

    I have already Action script as enclosed to load data from XML as fade out.

    I am using a movie object called newsMC

    I have already embedded arabic font as Font 1: Arial, Arabic

    The original action script is as follow.
    var counter:Number = 0;
    var delay:Number = 100;
    var xmlData:XML = new XML();
    var mainElement:XML = new XML();
    newsMC.newsText._alpha = 0;

    function fadeout() {
    if (newsMC.newsText._alpha = mainElement.childNodes.length)
    counter = 0;
    newsMC.newsText.text = mainElement.childNodes[counter++].firstChild.nodeValue;
    } else
    newsMC.newsText._alpha -= 5;
    }

    xmlData.ignoreWhite = true;
    xmlData.onLoad = function(){
    mainElement = this.firstChild;
    setInterval(fadeout, delay);

    }
    xmlData.load(“ticker.xml”);

    ________

    As I am new to flash, I have difficulty to use your script instead of that one.

  13. @Ramin

    You’re most welcome, but unfortunately I did not consider Persian and Urdu in this class, but I will very soon, when I do I may contact you for testing and making sure that Persian language is in fact displaying correctly, if you don’t mind of course ..
    Thanks again ..

    @Jochen

    Sorry for such late response, glad to know you did resolve your issue ..

    @Gen

    AS1 version could be done definitely, I will release this one very soon ..
    For the ending symbols issue, I will do my best to figure this out and release an updated version soon enough ..

    @Mohammed

    Thank you for your kind words, I believe that this solution actually working without embedding fonts, but it will throw many weird formatting if you use any, I’ll keep you informed when this issue is resolved ..

    @Erwin

    Oh .. this shouldn’t be happening, can you please send me an example with a sample of your text and fonts used?

    @Emam

    You need to embed the fonts in order to apply alpha transparency tweening ..

  14. Thank you, I’m looking forward to it.

    Actually I already edited the class to fix my problem and fit my needs. I had to change some part of the code. If you are interested, I can send you my copy.

Leave a Reply

Your email address will not be published. Required fields are marked *