3

Is there any way to use OpenType font features (small caps, old style figures, etc.) in Android? Something like a custom TextView would be ideal.

fhucho
  • 31,862
  • 40
  • 125
  • 178
  • You marked the answer below as solving your problem. Could you add some more details for what you did either here or on the link I gave in my comment to the answer? – Suragch Dec 22 '14 at 11:18
  • I now accepted a new answer, have a look at it. – fhucho Jan 01 '15 at 12:42

2 Answers2

3

As of api level 21, Paint now supports OpenType font features.

dcow
  • 7,228
  • 3
  • 41
  • 65
  • The documentation doesn't tell much. Have you used this yet? – Suragch Jan 01 '15 at 13:48
  • @Suragch no, but it points to the [W3 css font-feature documentation](http://dev.w3.org/csswg/css-fonts/#propdef-font-feature-settings) which I found pretty useful. – dcow Jan 05 '15 at 18:42
1

Outdated, look at dcow's answer instead

I don't think Android provide such API but you may use WebView, specially the new KitKat Chrome WebView would be nice if is not supported on older WebView. A sample that you can see a opentype feature setting difference via preinstalled Droid Arabic Naskh font: <div style="-webkit-font-feature-settings: 'rlig' 0">لا</div>

Otherwise I guess you should dive into JNI compiling Harfbuzz/Freetype and may Cairo for rendering glyph outlines if there is not any other way for it. Have a look at some HarfBuzz examples, you may be able to port it to your Android application. Depends on what you need other than configuring opentype features (layout, line wrapping) you may require compiling ICU4C or Pango and other libraries, but that would be very large dependency just for a mobile app of-course.

Ebrahim Byagowi
  • 8,152
  • 4
  • 55
  • 71
  • I am interested in both the Webview and Harffbuzz options. If you can expand any more here is a question I just asked: http://stackoverflow.com/questions/27539237/supporting-complex-text-layout-with-opentype-fonts-in-android – Suragch Dec 22 '14 at 11:15