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