Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Monospace doesn't behave as a fixed-pitch

As you can see in the screenshot below the two different strings with the same length not drawn with the same width on the canvas. I'm using a monospaced typeface, so isn't it promised to be drawn with the same width? Is that because of the kerning?

Typeface.create(Typeface.MONOSPACE,Typeface.NORMAL)

enter image description here

like image 512
ucMedia Avatar asked Oct 29 '25 13:10

ucMedia


1 Answers

This is a well-known kerning issue with monosapce font on Android. It looks like this is a quite old topic.

Some people have already faced this problem:

Android Monospace fonts aren't fixed width - 2013-06-11

Are Android monospace fonts actually fixed size? - 2016-06-22

Android monospace space ( ) width is different than character width - 2017-03-02

The issue also occurred in mobile web environment:

Font monospace Android 2.3 - 2013-07-11

where problem explained with missing glyph:

https://github.com/googlefonts/noto-fonts/issues/617

Solutions:

Option 1.:

Looking for an alternative fixed-width font might be the easiest way. Some helpful links to find one:

  • https://1stwebdesigner.com/free-monospaced-fonts/
  • https://www.fontsquirrel.com/ https://www.dafont.com/
  • https://www.urbanfonts.com/free-fonts.htm
  • https://www.1001freefonts.com/

Option 2.:

You can override text drawing using Spans. This post may help you: https://stackoverflow.com/a/53452941/5823014

Option 3.:

You can modify the monospace font file to fix kerning. This online tool can be useful: http://www.glyphrstudio.com/online/

like image 192
János Sicz-Mesziár Avatar answered Nov 01 '25 02:11

János Sicz-Mesziár