如何将 RTL 文本(阿拉伯语)绘制到位图上并使其正确排序?

发布于 2024-08-04 12:48:29 字数 1017 浏览 2 评论 0原文

我正在尝试将阿拉伯文本绘制到位图上进行显示:

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 类是一个用于重塑 unicode 文本以便将字母连接起来的工具。请参阅:http://github.com/aawish/Better-Arabic-Reshaper/

但是,生成的位图如下所示:

alt text http://imagebin.ca/img/ J1EB8DWc.jpg

当它看起来像 из рий 时,

我相信问题是因为,不像TextView,Bitmap 类不支持 BiDi,因此它从左侧绘制字母进行书写。

尽我所能,我无法弄清楚如何以正确的顺序绘制文本。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

街道布景 2024-08-11 12:48:29

Canvas 实际上是 Skia(原生图形引擎)Canvas 的包装。 Skia 不执行任何 BiDi/重塑,它只是绘制字形序列。

另一方面,TextView 使用大量 Android 文本相关对象,其中包括 Layout 和派生类,它们执行简单(实际上是愚蠢的)BiDi。 Android 的 BiDi 非常愚蠢,它甚至无法处理 RTL 中的数字:“180”显示为“081”。

就我个人而言,我不信任 Android 当前的 BiDi,并且会编写自己的 Unicode-BiDi 兼容类并在需要时使用它。我建议你除了手动整形之外还使用手动 BiDi 兄弟。记住:先BiDi,再重塑!

萨拉姆

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

若水般的淡然安静女子 2024-08-11 12:48:29

如果你给textview添加了单行属性,你应该删除这个属性并添加 maxLines="1"

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文