Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom font gives incorrect glyph for certain letter combinations in Android

I'm using a custom font in my Android project. For some reason when the text includes the letters IJ together, it gives me the following glyph:

enter image description here

This appears to be the glyph located at \uE2C5 of the PUA region of the font.

The individual I and J glyphs both exist in the font and I can get them to appear if I set the text to I J.

enter image description here

It's not an OpenType font (I don't think Android even supports OpenType rendering in custom fonts), so there shouldn't be anything like this happening. What is going on here?

The problem is reproducible with the following simple project:

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView textView = (TextView) findViewById(R.id.textview);
        Typeface tf = Typeface.createFromAsset(this.getAssets(), "MenksoftHawang.ttf");
        textView.setTypeface(tf);

        textView.setText("IJ");
    }
}

The font can be downloaded from here. Put it in the assets folder in the project.

like image 547
Suragch Avatar asked Mar 29 '17 09:03

Suragch


People also ask

How do I change glyphs of a font?

To access Edit view, you can either double click a glyph in Font view, or open a tab with View > Open Tab (Cmd-T). The selected glyphs are then opened in the Edit view, and the Text tool (T) is active.

How do I use glyph fonts in Android?

When you type sample text in fontcloud, you will see it in every font you have uploaded there. Similar to using WordMarkIt for viewing your installed fonts on a computer. Scroll down and choose your glyph, just tap on it to copy, then scroll back up and press to paste.

How do I use glyphs with fonts?

Scroll through the display of characters until you see the glyph you want to insert. If you selected an OpenType font, you can display a pop‑up menu of alternate glyphs by clicking and holding the glyph box. Double-click the character you want to insert. The character appears at the text insertion point.


1 Answers

There appears to be three solutions to this problem:

1. Programmatically disable the ligatures

You can disable the ligatures programmatically with setFontFeatureSettings (as suggested here) or setLetterSpacing (as suggested here). One disadvantage of both of these methods is that they are only available from API 21.

2. Edit the ligatures out of the font

You can use font editing software to fix or delete the ligature errors in the font. See this Q&A for how to do it in FontForge. A potential problem here is that the font copyright owners may not allow third parties to edit their fonts.

3. Use a different font

Different fonts are often available and that is true in this case. The same company that had the problematic TrueType font in the question also has an OpenType version of that font. The OpenType version does not seem to have the ligature errors. A disadvantage, though, is that it is significantly larger in size, which will make that app download size larger.

Notes

  • I had previously thought that there was no ligature rendering prior to Android 6.0. However, TrueType fonts do apparently support some basic ligatures and those are rendered in versions of Android prior to 6.0.
  • The following image from FontForge shows all the ligatures defined in the problematic font referenced in the question. enter image description here
like image 105
Suragch Avatar answered Oct 21 '22 18:10

Suragch