String (@NotNull String text, @NotNull FontMetrics metrics, int width) { int min = 0, max = text.length(); while (true) { int pos = min + (max - min) / 2; String str = text.substring(0, pos); if (pos == min) return str; if (isFit(str, metrics, width)) { min = pos; } else { max = pos; } } }