int (char[] text, int offset, int endOffset, double x, double clipX, WidthProvider widthProvider) { double newX = x; int breakOffset = offset; while (breakOffset < endOffset) { int nextOffset = breakOffset + 1; newX += widthProvider.getWidth(text, breakOffset, nextOffset - breakOffset, newX); if (newX > clipX) { return breakOffset; } breakOffset = nextOffset; } return breakOffset; }