2

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

Mohammad Sommakia
  • 1,773
  • 3
  • 15
  • 48
ucMedia
  • 4,105
  • 4
  • 38
  • 46

1 Answers1

2

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:

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/

  • Most editor apps with monospaces are not real monospace, inclunding courier font. . Exception is the app `Monospace` that uses a real monospace font. – Paulo Buchsbaum Oct 17 '19 at 00:12
  • 1
    Researching many fonts, I've discovered that `Lucida Sans Typewriter` in the `Microsoft Word` Mobilie is a real monospace font. – Paulo Buchsbaum Oct 17 '19 at 00:20