Adjust text size based on length of text

To be clear, this is a solution for:

not:

For that second solution, one way is to try making an altered copy of your overflow detector

boolean isTextOverflow(String txt, float x, float y, float w, float h, float tsize, float leading)

…and instead of returning true / false, returns a value textHeight:

float textHeight(String txt, float x, float y, float w, float h, float tsize, float leading) {
  // ...
}

Note that this works much like isTextOverflow, and returns the total height for the full text block when laid out – it is not the visible height of a single line. @micycle has a great explainer thread on precisely calculating visible line height.