3

Android does not support the Urdu Nastaliq font properly (the word is broken up and the exact shape (Nastaliq) of the word is not made).

I have used Typeface for this as

TextView tx=(TextView)this.findViewById(R.id.tt);
tx.setTypeface(Typeface.createFromAsset(getAssets(),"TTF font Path"));

I am able to get the exact formating of the Nastaliq Font in java using the AWT package like

Font font = Font.createFont(Font.TRUETYPE_FONT, new File("Path for ttf file"));
Font dynamicFont32Pt =   font.deriveFont (32f);
JLabel textLabel = new JLabel(textMessage);
textLabel.setFont(dynamicFont32Pt);

But Android also does not support the AWT Package Properly (java.awt.Font.createFont() and deriveFont()), So we decided to make a render engine for the .ttf file for Urdu.

Now my question is-

  1. Can we get the urdu Font (properly) rendering in Android without needing a Rendering Engine? If not, then
  2. How can I read the .ttf file (All tables like 'glyp', 'head') in Android?
  3. How can I draw a TTF font, that is, a vector font that does not require a PNG?
gobernador
  • 5,659
  • 3
  • 32
  • 51
user1350695
  • 31
  • 1
  • 4

2 Answers2

2

The answer from the Extracting glyph-path information from ttf files question can interest you: basically, it points to the Batik library which has code to parse a TTF file in Java (to transform it to SVG).

Community
  • 1
  • 1
PhiLho
  • 40,535
  • 6
  • 96
  • 134
0

You should check my question How to use kerning pairs extracted from a TTF file to correctly show glyphs as Path2D in Java?. Instead of Batik, I recommend using Apache FOP. It is simple and easy to use. The advantage is that you read the font only once and you embed the Glyphs into your app. However, Apache FOP only works for TTF, not for OTF (it is possible too, but I am still working on that). Batik uses Java AWT to render strings. The problem is that your app needs to read the font file each time it runs. In the method I am suggesting you can use an embedded mini vectorized font, or you can use an embedded vectorized string for small texts. The problem of this approach is that widths only work properly in painting time. To be able to use the glyphs you recover from the font file using awt, you need to read the kerning pairs and widths directly from the file to be able to display the text properly. This is explained in the answers to the question. Also check the question How to read kerning pairs table from TTF file in Android?. The advantage of using vectorized glyphs is that your app is independent of font files and operating system.

You can see that I am using this system on Windows, but you can do the same for Android. Fonts are easier to deal with on Windows and most fonts there are TTF. In reality you can develop your vectorized font on Windows and just use the resulting class in Android. That's the beauty of this method. I generate my fonts using println and copying and pasting it in a new class file. I don't even bother in writing a file.