如何绘制RTL文本(阿拉伯文)到一个位图,并将它妥善有序? [英] How to draw RTL text (Arabic) onto a Bitmap and have it ordered properly?

查看:388
本文介绍了如何绘制RTL文本(阿拉伯文)到一个位图,并将它妥善有序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提请阿拉伯文字到一个位图显示:

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);

该ArabicUtilities类是一个工具,以便字母连接到重塑UNI code文本。请参阅: http://github.com/agawish/Better-Arabic-Reshaper/

不过,这会产生类似下面这样的位图:

However, the bitmap that is generated looks like this:

当它应该看起来像يجري

我相信这个问题是因为,不像的TextView 中, Bitmap类是不是比迪知道,所以它吸引的字母从左至右书写。

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.

推荐答案

画布实际上是一个围绕Skia的画布(私有图形引擎)的包装。 Skia的不执行任何比迪/整形,它只是吸引字形序列。

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的,对其他的方式,采用了Android的文本相关的对象的负载,其中包括布局和派生类里面做简单的(实际上是愚蠢的)比迪。 Android的比迪是非常愚蠢的,它甚至不能处理的数字在RTL:طولي180'显示'طولي081

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'.

我个人不相信Android的电流比迪,并会写我自己的统一code-比迪兼容类,并使用它,如果我需要。我建议你​​除了手动整形兄弟使用手动比迪。切记:一是比迪,然后重塑

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!

萨拉姆

这篇关于如何绘制RTL文本(阿拉伯文)到一个位图,并将它妥善有序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆