Update: a newer version available here
As per my previous post here, I’ve made some improvements to my method for proper Arabic rendering in a dynamic TextField using ActionScript 2.0.
An ActionSctipt 3.0 version available here
Many thanks to all reviewers, your comments were very helpful bringing this version available, now you can use and test my new parseArabic method ..
Requirements:
- Dynamic TextField
- HTML Enabled TextField
- Pre-Defined TextFormat
- Arabic Fonts must include a complete Arabic Presentation Forms-B (glyphs from FE70 to FEFE according to the Unicode Standard 5.2)
Features Supported:
- 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).
- Arabic Ligatures.
- Word Wrapping.
- Bi-Directional text.
- HTML Text.
- Loading External text.
Features Not Supported:
- Arabic Diacritics.
Fixed Bugs:
- Correct Arabic Ligatures with/without embedding fonts
- Correct Brackets Directions
- Clean Line-Breaks
Here is an example works with this external XML file:
download the above example here
Note:
When you try to select and copy the above text into a static TextField it will display Arabic properly as well, just another benefit of this method, but if you paste the copied text into any other text editor you will see an alien version instead!
100 100 ya 3am el 7ag allah yenawar
thanks a bunch
Asim Kh
Hi, Thanks for such a nice post. If i have to change arabic font then how can do it.
In order to use custom fonts, basically you need to embed those fonts first, then you define the font name for the TextFormat parameter, for example:
good work.
thank you
Man I LOVE YOU!!
You’re the best … now I can load arabic text from a database.
Cheers
Sure, all you need to do is to connect and read your Arabic text from MySql and send it back to Flash, for example:
PHP (getArabic.php):
ActionScript 2.0:
Any time
Thanks so much for this post your really brilliant.
by the way I noticed a bug with the number ٤ and ٦ when I write them in arabic in the xml and when I replaced them with 4 & 6 it’s worked I’m just telling you because u did a great job and you should know if there is any bug.
Thanks again
i am not into flash at all, so i am very sorry that i didn’t understand what is this all about.
can you tell me, in layman term, if this is some workaround to get flash objects render Arabic sanely, i mean a patch users do once that affects every object executed, or it is a library for flash developers to include in their projects so that it will be able to display Arabic scripts correctly ?
if the former, can you explain for dumb user, in details, what to do ?
many thanks in advance
@Khaled
Well, it’s not a patch that affects every object, also not quite a library for flash ..
Basically it’s a String Parsing method (custom AS based function), which analyze and re-order Arabic glyphs in a proper manner with correct rendering on windows, mac and linux, furthermore, it supports custom fonts ..
Regular TextField in Flash does not understands right-to-left languages, so it can not map custom fonts, no word wrapping and even breaks the string on mac machines ..
I did not hack into Flash or use third-party techniques to solve this, all I did is simply instruct Flash to render Arabic language manually using ActionScript by finding and replacing Arabic characters with its correct forms from unicode charts, my method has nothing to do with any special features added to ActionScript (since version 1.0) or to Flash Player (since version 5), it’s just a workaround ..
I left my solution absolutely free and open for anyone who can understand my approach and build similar methods for other right-to-left languages, even update my own for better usage ..
I hope I’ve helped understanding what this is all about
@Rabah
I think it’s a Font issue, I use unicode charts for Arabic Presentation Forms-B (glyphs from FE70 to FEFE according to the Unicode Standard 5.2), may be this is your issue, can you try one of these fonts and tell me if you still have the same bug? (those fonts has full representation Form-B)
Thank you for your compliment
salman
First of All, Thanks for this great source. However I am facing wrapping problem in full screen mode! It shows starting words of sentence in 2nd line and in case of long test (in full screen) wrapping issue is remain same as happens in flash normally. Any Idea Why it is behave like this.
FYI: I’m reseting width of my text field for full screen thru AS. However your script works fine normal mode.
hey man, it works perfectly with the database, just one thing.
1 newline does 3 newlines.
didn’t really get what was happening in your function, but tried to comment:
input = input.split(“\n”).join(“”);
input = input.split(“\r”).join(“”);
which fixed it but messed everything else!
so any idea?
ok I managed to find a work around which seems to be working till now
seems 1 new line in my input produces “\r\n”
which while being split each becomes a br and results in 2 newlines in flash.
so I just removed one of the joins and now it works!
input = input.split(“\r”).join(“”);
and leave \n alone
Ahmed, I tried to contact you via email. Maybe you are too busy, so I will post my investigations here as comment.
First of all: Thank you very much for this great AS2 class. I do not know anything about Arabian characters or grammar, but I think I found bugs and possible enhancements:
1) Fix double line breaks (@Ammar: That could fix your problems)
Add
Line input = input.split(“\r\n”).join(“\n”);
after the comment “// strip hard lines-breaks”
2) Fix wrong line breaks (Ahmed: I sent you a test fla via email):
Replace:
if (temp._width<tag._width-tagFormat.leftMargin-tagFormat.rightMargin) {
By:
if (temp._width<tag._width-(tagFormat.leftMargin ? tagFormat.leftMargin : 0)- (tagFormat.rightMargin ? tagFormat.rightMargin : 0)) {
3) Improve "hasDigitsOrLatin"-loop:
Add a "break" command when a latinChars was found (just for performance).
—-
Two thinks I am confused about:
1) There are some if-Statements like "if (tag.embedFonts) { …": I do not understand why embedded fonts should be processed in a different way than not-embedded text formats. In my tests with NOT-embedded text formats I replaced all if conditions with true (like "if (true ||tag.embedFonts) {") to handle NOT-embedded text format like the embedded ones (otherwise the algorithm did not work properly for me).
2) What about upper case letters in the definition:
var latinChars:String = "abcdefghijklmnopqrstuvwxyz1234567890″?
The latinChars string is used with indexof and, imho, indexof is case sensitive and I do not see any reason why lower case latin characters should differ from upper case ones.
Jan
Dear sir,
I’ve a weak background about scripts…
The issue I face is I’m a Mac user and the flash player doesn’t support the Arabic words written in flash forms such as YouTube … etc.
Is this script going to be helpful in this case? and how to use it :$
best regards
Yousif
@Jan
Many thanks to you for your contribution, that was very efficient ..
About the embedFonts condition you find confusing, actually I don’t quite understand why Flash treats embedded fonts differently in terms of character metrics, I found that by try and error, not based on any information regarding Arabic vs. Flash, for example, when I try to detect characters width for wrapping it behaves differently based on embedFonts property, that’s why I do recommend to always embed Arabic Fonts, this way you should get proper Arabic rendering ..
If you can find me an explanation about embedFonts and Arabic glyphs in Flash it would be great ..
Thanks again for your updates to this method
@Yousif
This method definitely renders Arabic characters properly on Mac, but I don’t think you can force the embedded YouTube Flash Player to use this method for Arabic rendering, unless you can find a way to load videos directly from YouTube (without using their player), in this case you can build you own player using this method, only by then you can have proper Arabic rendering in your own player
@Salman
@Ammar
@Jan
@Yousif
My apologies for such late reply, it’s true that I have been busy recently ..this new version, you’re still welcome to review and comment on this one
I did my best to cover all your issues in
Taher
I’m a mac user, trying to resolve the arabic text issue of AIR. Tweet Deck & Youtube arabic text.
How can I use your solution?
@Taher
Pre-compiled apps like YouTube player or any similar components can not directly integrated with this solution, but ..
For an instance, you can build your own YouTube Player using their API, in this case you can use this solution for sure ..
Amir Farouk
Hi there, Thanks for the great work, but i have an issue,When the text is too long text wrapping happens at the start of the sentence not the end of it. How can i fix that.thanks,Amir