code: protected int getGoldenLabelHeight (Dimension d)
      {
          // compute the ratio of the one line (addin' the paddin')
          double lastratio = ((double) d.width + (PAD * 2)) /
                             ((double) d.height + (PAD * 2));
  
          // now try increasing the # of lines and seeing if we get closer to the golden ratio
          for (int lines=2; true; lines++) {
              double ratio = ((double) (d.width / lines) + (PAD * 2)) /
                                 ((double) (d.height * lines) + (PAD * 2));
              if (Math.abs(ratio - GOLDEN) < Math.abs(lastratio - GOLDEN)) {
                  // we're getting closer
                  lastratio = ratio;
              } else {
                  // we're getting further away, the last one was the one we want
                  return lines - 1;
              }
          }
      }
docs: Given the specified label dimensions, attempt to find the height that will give us the
  width/height ratio that is closest to the golden ratio.