How to draw RTL text (Arabic) onto a Bitmap and have it ordered properly?

Posted by Casey on Stack Overflow See other posts from Stack Overflow or by Casey
Published on 2009-09-13T11:18:47Z Indexed on 2010/03/28 7:53 UTC
Read the original article Hit count: 359

Filed under:
|
|

I'm trying to draw Arabic text onto a Bitmap for display:

Bitmap img = Bitmap.createBitmap( (int) f+100, 300, Config.RGB_565);
Canvas c = new Canvas();
c.setBitmap(  img );
mFace = Typeface.createFromAsset(getAssets(),"DejaVuSansCondensed.ttf");
mPaint.setTypeface(mFace);
content = "????";
content = ArabicUtilities.reshape( content );
System.out.println("Drawing text: " + content);
c.drawText(content, 30, 30, mPaint);

The ArabicUtilities class is a tool to reshape the unicode text so the letters are connected. see: http://github.com/agawish/Better-Arabic-Reshaper/

However, the bitmap that is generated looks like this:

alt text

When it should look like ????

I believe the issue is because, unlike a TextView, the Bitmap class is not BiDi aware, so it draws the letters from left to write.

Try as I might, I can't figure out how to draw the text in the correct order.

© Stack Overflow or respective owner

Related posts about android

Related posts about bidi