Supporting complex text layout with OpenType fonts in Android

柔情痞子 提交于 2019-11-26 23:26:14

问题


What I would like

I would like to put an OpenType font in my assets folder and use Typeface.createFromAsset to render Unicode text in my Android application for a language that uses complex text layout (CTL).

Background

I want to do this for traditional Mongolian script, but it is the same issue (so I hear) for other languages like Thai, Arabic, Indic languages, and many minority languages. An OpenType font already includes the information necessary to properly display the text. The problem is that not all software supports OpenType rendering. Some do, but others don't. From what I can gather, Android didn't used to, but maybe now does?

My question

Android Lollipop is out now. Is there any support for OpenType fonts in Android?

If there is still nothing easy, then what is the process? I have heard of things like Pango and Harfbuzz (which claims to work with Android) but I haven't found any simple instructions or tutorials for how to implement them. The closest thing I have found is an Indic text renderer, but it is far from easy to understand.

Related questions on StackOverflow

These questions show that there is interest in this topic, but in my opinion they haven't been satisfactorily answered. Some of them are also outdated. I want to know if there is a current solution.

  • Use OpenType font features in Android
  • Display interception and support non-latin or complex scripting language in Andorid
  • CTL (Complex Text Language) support in Android (sic)
  • Indic Language Support for SDK but not PhoneGap
  • HarfBuzz getting started
  • indic-text-renderer using harfbuzz and freetype

What I have tried

I have written my own rendering engine to display traditional Mongolian Unicode text. But writing a rendering engine for a specific language is reinventing the wheel if there are already OpenType fonts available. Also, it is not easily adaptable to other languages.


回答1:


If you want to use Harfbuzz to do this, I have written a simple guide to implementing a text shaper using Harfbuzz: http://www.simon-cozens.org/content/duffers-guide-fontconfig-and-harfbuzz

That should get you from font selection to knowing which glyphs should be used and where to put them in the output.




回答2:


I have no experience with Mongolian in particular, but Lollipop finally introduced Paint.setFontFeatureSettings() which takes a string that follows the CSS format, providing "low-level control over OpenType font features"!



来源:https://stackoverflow.com/questions/27539237/supporting-complex-text-layout-with-opentype-fonts-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!