int (@NotNull FontMetrics fontMetrics, @NotNull String str) { if (myCharWidthFunction == null) { return myCharWidth * str.codePointCount(0, str.length()); } float width = 0; int pos = 0; while (pos < str.length()) { width += myCharWidthFunction.applyAsDouble(str.codePointAt(pos)); pos = str.offsetByCodePoints(pos, 1); } return Math.round(width); }