title: Android canvas drawText y-position of text
body: <p>I'm using a Canvas to create a Drawable with some background and some text. The drawable is used as a compound drawable inside an EditText.</p>
  
  <p>The text is drawn via drawText() on the canvas, but I do have an issue with the y-position of the drawn text in some cases. In those cases parts of some characters are cut off (see image links).</p>
  
  <p><em>Characters without positioning issue:</em> </p>
  
  <p><a href="http://i50.tinypic.com/zkpu1l.jpg">http://i50.tinypic.com/zkpu1l.jpg</a> </p>
  
  <p><em>Characters with positioning issue, text contains 'g', 'j', 'q', etc.:</em></p>
  
  <p><a href="http://i45.tinypic.com/vrqxja.jpg">http://i45.tinypic.com/vrqxja.jpg</a></p>
  
  <p>You can find a code snippet to reproduce the issue below. </p>
  
  <p>Does any expert know how to determine the proper offset for the y position?</p>
  
  <pre><code>public void writeTestBitmap(String text, String fileName) {
     // font size
     float fontSize = new EditText(this.getContext()).getTextSize();
     fontSize+=fontSize*0.2f;
     // paint to write text with
     Paint paint = new Paint(); 
     paint.setStyle(Style.FILL);  
     paint.setColor(Color.DKGRAY);
     paint.setAntiAlias(true);
     paint.setTypeface(Typeface.SERIF);
     paint.setTextSize((int)fontSize);
     // min. rect of text
     Rect textBounds = new Rect();
     paint.getTextBounds(text, 0, text.length(), textBounds);
     // create bitmap for text
     Bitmap bm = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888);
     // canvas
     Canvas canvas = new Canvas(bm);
     canvas.drawARGB(255, 0, 255, 0);// for visualization
     // y = ?
     canvas.drawText(text, 0, textBounds.height(), paint);
  
     try {
        FileOutputStream out = new FileOutputStream(fileName);
        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
     } catch (Exception e) {
        e.printStackTrace();
     }
  }
  </code></pre>