title: How to fit font into pixel size in Java? How to convert pixels to points?
body: <p>I need to create font of a givens size in pixels.</p>
  
  <p>Java's <code>Font</code> class constructor requires font size expressed in points. Points are physical length while pixels are digitizes. So I need <code>dpi</code>.</p>
  
  <p>It is said in manual, that this value is contained inside <code>FontRenderContext.getTransform()</code>.</p>
  
  <p>I found, that in my case, scaling is one, i.e. pixels = points.</p>
  
  <p>Unfortunately, creating font of size 100 creates bigger image.</p>
  
  <p>For example, code below </p>
  
  <pre><code>    BufferedImage ans = new BufferedImage(width, height, imageType);
      Font font = new Font(fontName,fontStyle,height);
  
      Graphics2D g2 = ans.createGraphics();
  
      g2.setFont(font);
  
      FontMetrics fm = g2.getFontMetrics();
      FontRenderContext frc = g2.getFontRenderContext();
  
      System.out.println("height=" + height);
      System.out.println("frc.getTransform()=" +frc.getTransform());
      System.out.println("g2.getTransform()=" +g2.getTransform());
      System.out.println("fm.getAscent()+fm.getDescent()="+fm.getAscent()+"+"+fm.getDescent()+"="+(fm.getAscent()+fm.getDescent()));
  
  
      g2.drawString(str, 0, fm.getAscent());
  </code></pre>
  
  <p>gives</p>
  
  <pre><code>height=100
  frc.getTransform()=AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
  g2.getTransform()=AffineTransform[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]
  fm.getAscent()+fm.getDescent()=93+20=113
  </code></pre>
  
  <p>How to fit?</p>