content: package com.allen.comparsechart.util;
  
  import android.graphics.Paint;
  import android.graphics.Rect;
  
  /**
   * 作者: allen on 15/11/18.
   */
  public class Util {
      private Util() {
      }
  
      /**
       * calculates the approximate width of a text, depending on a demo text
       * avoid repeated calls (e.g. inside drawing methods)
       *
       * @param paint
       * @param demoText
       * @return
       */
      public static int calcTextWidth(Paint paint, String demoText) {
          return (int) paint.measureText(demoText);
      }
      /**
       * calculates the approximate height of a text, depending on a demo text
       * avoid repeated calls (e.g. inside drawing methods)
       *
       * @param paint
       * @param demoText
       * @return
       */
      public static int calcTextHeight(Paint paint, String demoText) {
  
          Rect r = new Rect();
          paint.getTextBounds(demoText, 0, demoText.length(), r);
          return r.height();
      }
  
      public static float getLineHeight(Paint paint) {
          Paint.FontMetrics metrics = paint.getFontMetrics();
          return metrics.descent - metrics.ascent;
      }
  
      public static float getLineSpacing(Paint paint) {
          Paint.FontMetrics metrics = paint.getFontMetrics();
          return metrics.ascent - metrics.top + metrics.bottom;
      }
  }
  