title: Monospace Font: Increase textsize based on device size
body: <p>I have an app that must show a printing-screen preview for an zebra printer.
  The data to be printed is pure-text and it there are a maximum of 80 characters in one line.</p>
  
  <p>The preview is pure android: text views in a vertical linear layout, one text view per line and monospace font. The rendering works. For my phone i have set the font size to 7dp, and the 80 characters fit on the screen in portrait mode.</p>
  
  <p>Now, is there a way to calculate the text size to fit exactly 80 characters on one line and being device size independant?</p>
  
  <p>I tried the following to calculate the text size and text scale:</p>
  
  <pre><code>private void CalculateTextSizeAndScale(int numberOfChars, out float textSize, out float textScale)
  {
      var text = new string('M', numberOfChars);
      var paint = new Paint
      {
          TextSize = 100f,
          TextScaleX = 1f
      };
      paint.SetTypeface(Typeface.Monospace);
  
      var width = paint.MeasureText(text);
      textSize = _screenWidth / width * 100f;
  
      paint.TextSize = textSize;
      paint.TextScaleX = 1f;
  
      width = paint.MeasureText(text);
      textScale = _screenWidth / width;
  }
  </code></pre>
  
  <p>This seems correct for some screen resolution. It works perfectly for my android phone in portrait mode, but is totally wrong for landscape mode.</p>
  
  <p>I use Display.GetMetrics to retrieve the screen width.</p>
  
  <p>Here is a screen shot on my android phone</p>
  
  <p>Portrait Phone
  <a href="https://i.stack.imgur.com/q8Eap.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q8Eap.png" alt="portrait phone"></a></p>
  
  <p>Landscape Phone
  <a href="https://i.stack.imgur.com/9PBSf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9PBSf.png" alt="landscape phone"></a></p>
  
  <p>Now, on my tablet, it looks different</p>
  
  <p>Portrait Tablet
  <a href="https://i.stack.imgur.com/uaH8A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uaH8A.png" alt="portrait tablet"></a></p>
  
  <p>Landscape Tablet
  <a href="https://i.stack.imgur.com/nFthQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nFthQ.png" alt="landscape tablet"></a></p>