4

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 http://imagebin.ca/img/J1EB8DWc.jpg

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.

j0k
  • 22,600
  • 28
  • 79
  • 90
Casey
  • 6,166
  • 3
  • 35
  • 42

2 Answers2

5

Canvas is practically a wrapper around the Canvas of Skia (native graphics engine). Skia doesn't perform any BiDi/reshaping, it simply draws sequences of glyphs.

TextView, on the other way, uses a load of Android's text-related objects, among them Layout and derived classes which do simple (actually dumb) BiDi. Android's BiDi is very dumb that it can't even handle digits in RTL: 'طولي 180' is displayed 'طولي 081'.

Personally I don't trust Android's current BiDi, and would write my own Unicode-BiDi compliant class and use it if I need. I suggest you use manual BiDi in addition to the manual reshaping bro. Remember: First BiDi, then reshape!

Salam

Tareq Sha
  • 515
  • 4
  • 14
  • Do you have any suggestions for freely available BiDi implementations I could drop into my application? – Casey Mar 12 '10 at 16:26
  • I think the official unicode bidi document (http://unicode.org/reports/tr9/) includes suggested Java and C++ implementations, bet these include no optimizations which are necessary for a resource-limited devices such as phones – Tareq Sha Mar 13 '10 at 22:20
1

if you added single line attribute to textview ,you should delete this attribute and add maxLines="1"

mmfarzaneh
  • 381
  • 1
  • 11