[WIP] Open source RTL support for Android

Search This thread

dudyk

Member
Mar 15, 2010
42
0
I am working on an open source RTL support for Android and I need help testing...

I have attached a normal app (that should work on any Android 1.5 and up) that runs my method before calling drawText.
The purpose is to make drawText call to it so it will support BiDi.

It reads a file called /sdcard/test.txt from which it gets the test string.
It does not support newlines.

Try it and tell me what you think.

The reason I don't publish the source yet is because knowing how it works would prevent it from being tested properly.

I hope I'm putting this in the right forum...
 

Attachments

  • biditest.apk
    9.1 KB · Views: 399

TheAgent1982

Senior Member
Sep 3, 2007
783
35
Hebrew Supported...

Is it also, support the font for Hebrew?

Because in ver 2.1, the have Hebrew but sometimes you see square or ? signs.
 

afriza

Member
Feb 18, 2010
14
3
biditest with Android 2.2 FroYo (FRF50) Arabic test.txt

I tested with Android 2.2 FroYo (FRF50)

without /sdcard/test.txt and with my own text

I don't know about the Hebrew, the Arabic text are not joined (re-shaped) correctly
 

Attachments

  • biditest.jpg
    biditest.jpg
    18.9 KB · Views: 309
  • biditest-arabic.jpg
    biditest-arabic.jpg
    22.5 KB · Views: 430
  • test.txt
    69 bytes · Views: 70
Last edited:

torusJKL

Member
Oct 6, 2009
28
6
Thanks for writing an open source BiDi support.

I did a very short test:

1. It did not render the whole line of text.
2. It looks like it has problems when switching from one language to another. E.g. the closing bracket after the hebrew word is rendered as open.

I attached the original text files and screen shots.
In addition I attache a screen shot of TxtPad Light and how it is rendered there.

TheAgent1982 said:
Is it also, support the font for Hebrew?

Because in ver 2.1, the have Hebrew but sometimes you see square or ? signs.
This might be a problem of character encoding.
I did a test with a UTF-8 file and a Hebrew ISO 8859-8. The first rendered the letters correct but the second showed only question marks. (See picture)

As alternative keyboard I recommend using either AnySoftKeyboard or SmartKeyboard.
 

Attachments

  • test_utf8.txt
    82 bytes · Views: 30
  • test_hebrew_iso-8859-8.txt
    49 bytes · Views: 33
  • BiDiTest_Utf-8.png
    BiDiTest_Utf-8.png
    12.3 KB · Views: 193
  • BiDiTest_Hebrew_ISO-8859-8.png
    BiDiTest_Hebrew_ISO-8859-8.png
    13.9 KB · Views: 218
  • BiDi_TxtPadLight.png
    BiDi_TxtPadLight.png
    58.6 KB · Views: 230

ClassicalDude

Senior Member
Sep 14, 2007
64
33
Dear Dudy,

Will your fix work for 2.1 as well? Can you give directions how to apply it to other ROMs? I own an HTC Desire, and would love to implement the fix. So far I just have the common StaticLayout fix.

Thanks,

Ron

EDIT: More specifically, it would be great if you can tell us which files to take from the CM update with the help of baksmali and smali in order to graft them into other distros. That's the way I implanted StaticLayout.smali in MoDaCo roms.
 
Last edited:

dudyk

Member
Mar 15, 2010
42
0
CM 5.0.8 is 2.1. It should apply to any 2.1/2.2 rom, just take my 4 commits from CM's git from framework base repository.
 

ClassicalDude

Senior Member
Sep 14, 2007
64
33
CM 5.0.8 is 2.1. It should apply to any 2.1/2.2 rom, just take my 4 commits from CM's git from framework base repository.

Thanks for the reply, Dudy. I'll be more specific about what I am trying to do: I am trying to pull the files with your patches from the CM-5.0.8 ROM without compiling anything.

With the StaticLayout fix, I used baksmali and smali to disassemble the classes.dex from framework.jar and replace StaticLayout.smali. This worked.

When I look at the page github.com/dudyk/android_frameworks_base/commit/1b0aca31c3e03a5a323276cd15a8df4203a1792c - the one with your commits (is that the right one?) I cannot figure out all the files that I would need to replace. Sorry, I am not a programmer...

I can pretty much figure out that all the files preceeded by core/java/android/ will be found with their exact names in the classes.dex from framework.jar. But I have no idea where to locate the compiled files that resulted from AndroidGraphics2D, the three Canvas files and the ResourceTypes.

If you can point me at the right direction I'll be able to convert a script that was used for the StaticLayout fix so that anyone with a Mac or Linux would be able to easily implement your fix to any none-odexed distro.

Thanks so much in advance!
 
Last edited:

ClassicalDude

Senior Member
Sep 14, 2007
64
33
Dear Dudy, I really need your help.

Back in the old days (a month ago), before your wonderful work, the best fix we had was Omri Baumer's StaticLayout fix. I was able to use the baksmali and the smali utilities to extract the smali file from framework.jar of CM, and graft it into ANY phone. Another user on the iAndroid forums created a script that automated everything.

I wanted to do the same with your fix. So I compiled a vanilla 2.1 and then applied only your patches, manually, and recompiled. I used baksmali to disassemble all the framework files, and discovered that the changed files were:

android/graphics/Canvas.smali
android/graphics/Canvas$EdgeType.smali
android/graphics/Canvas$VertexMode.smali
android/text/Layout.smali
android/text/SpannableStringBuilder.smali
android/text/Styled.smali
android/widget/TextView$CharWrapper.smali

The two additional Canvas files were tagged as changed, but no textual difference is evident. So altogether we are talking about 5 files that ideally would be easily grafted into ANY device running 2.1, without recompilation.

The problem was that the new Canvas.smali file caused boot loops on my HTC Desire. Logcat caught this:

Code:
D/AndroidRuntime(  103): --- registering native functions ---
W/dalvikvm(  103): Unable to register: not native: Landroid/graphics/Canvas;.drawText (Ljava/lang/String;FFLandroid/graphics/Paint;)V
E/JNIHelp (  103): RegisterNatives failed for 'android/graphics/Canvas'
E/AndroidRuntime(  103): Unable to register all android natives

This did NOT happen when I tried the vanilla Canvas.smali. So it must be something in your patches. If you can help me figure out how to fix this, your fix will be easily implemented into any un-odexed 2.1 device. The script is all reworked and ready... Just this problem needs ironing out.

Thanks so much - for your wonderful work, and for taking the time to read this.

Ron
 

dudyk

Member
Mar 15, 2010
42
0
I wanted to do the same with your fix. So I compiled a vanilla 2.1 and then applied only your patches, manually, and recompiled. I used baksmali to disassemble all the framework files, and discovered that the changed files were:

android/graphics/Canvas.smali
android/graphics/Canvas$EdgeType.smali
android/graphics/Canvas$VertexMode.smali
android/text/Layout.smali
android/text/SpannableStringBuilder.smali
android/text/Styled.smali
android/widget/TextView$CharWrapper.smali

The two additional Canvas files were tagged as changed, but no textual difference is evident. So altogether we are talking about 5 files that ideally would be easily grafted into ANY device running 2.1, without recompilation.

The problem was that the new Canvas.smali file caused boot loops on my HTC Desire. Logcat caught this:

Code:
D/AndroidRuntime(  103): --- registering native functions ---
W/dalvikvm(  103): Unable to register: not native: Landroid/graphics/Canvas;.drawText (Ljava/lang/String;FFLandroid/graphics/Paint;)V
E/JNIHelp (  103): RegisterNatives failed for 'android/graphics/Canvas'
E/AndroidRuntime(  103): Unable to register all android natives

This did NOT happen when I tried the vanilla Canvas.smali. So it must be something in your patches. If you can help me figure out how to fix this, your fix will be easily implemented into any un-odexed 2.1 device. The script is all reworked and ready... Just this problem needs ironing out.

Thanks so much - for your wonderful work, and for taking the time to read this.

Ron

My changes add a native method (a C++ one) to the sources, from what I know, it is in the dex file, but maybe smali's files do not extract it, or extract it differently.
I never tried to disassemble files in android and reassemble them, so I have no idea how to help you besides describing the changes to you.

P.S.
Do you think that HebVillian is using my fix this way? I believe that I'm the first to fix this for ROMs above 2.0 (BTW, it's in the froyo branch of CM as well).
 
Last edited:

ClassicalDude

Senior Member
Sep 14, 2007
64
33
I don't know about HebVillain. The maker of the rom was made aware of the way I patched StaticLayout, so it may well be. Perhaps he also read your thread and applied the actual patches...

I noticed that in one of your commits:
http://github.com/dudyk/android_fra...0aca31c3e03a5a323276cd15a8df4203a1792c#diff-5

You added "native" to drawText. It is exactly the function in that line that is throwing the error on boot - about not being native. I tried recompiling with that particular change reversed, but it did not make a difference. Can you investigate the matter? Perhaps the way the Nexus 1 boots is different than that of other devices, and the checks are not as strict. If this is indeed a code problem, perhaps it needs to be addressed for the patch to be viable for other devices.

Take everything I say with a grain of salt - I am no programmer. Just following what I read and understand.
 
Last edited:

ClassicalDude

Senior Member
Sep 14, 2007
64
33
I have no idea if this helps, but googling the words
android registernatives
results in quite a few technical posts complaining about similar problems...
 

ClassicalDude

Senior Member
Sep 14, 2007
64
33
I am sorry for being a nag. But I hope I am getting closer to the source of the problem.

The Android emulator was able to boot up just fine with the patches applied. The logcat stated at the beginning of the runtime:
Code:
D/AndroidRuntime(   29): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime(   29): CheckJNI is ON
I/        (   30): ServiceManager: 0xad08
D/AudioHardwareInterface(   30): setMode(NORMAL)
I/CameraService(   30): CameraService started: pid=30

The very same smali files, when applied to the HTC Desire's framework, generated the native error I quoted before. But logcat shows that the beginning of its runtime is indeed different:
Code:
D/AndroidRuntime(  197): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
D/AndroidRuntime(  197): CheckJNI is OFF
D/dalvikvm(  197): Precise GC configured ON
D/dalvikvm(  197): creating instr width table
I/dalvikvm(  197): mlock: /data/dalvik-cache/system@framework@core.jar@classes.dex, fd=7

So - how do we make the Desire, or any other device, turn on CheckJNI and turn off precise GC?

EDIT: In one of CM's change logs it was written that Precise GC was turned off because of its memory consumption. I am just assuming that this is indeed the cause for my problems. How can we check it?
 
Last edited:

ClassicalDude

Senior Member
Sep 14, 2007
64
33
CheckJNI and Precise GC don't matter.

Repatched and recompiled 2.2 source. The emulator runs beautifully with or without JNI checks. My HTC desire, with a 2.2 rom, still complains about the same function not being native.

The port dudyk did to Omri Baumer's patch works partially - the numbers are not reversed, but the whole line is aligned to the left (with hebrew text appearing to the left of the number, instead of the right).

I have no idea what else to do or to check.
 

PapaDocta

Senior Member
Jun 4, 2004
1,393
160
i tried the latest cm6 nightly build and still it won't align Arabic RTL correctly.. it aligns it as LTR and there no reshaping as well....
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    كس أم أسرائيل
    1

    لوسمحت اخي انا مقدر غيرتك لكن يجب ان ترتقي وتترفع عن التلفظ بمثل تلك الكلمات
    وليكن الرسول محمد صلى الله عليه وسلم قدوة لك في حسن الخلق و اسلوب التعامل مع عامة الناس

    اصلحك الله