TextLayout layout; int line; int lineOffset; int offsetInLine; String lineText;
public int getOffsetAtLocation(Point point) {	checkWidget();	TextLayout layout;	int line;	int lineOffset;	int offsetInLine;	String lineText;		if (point == null) {		SWT.error(SWT.ERROR_NULL_ARGUMENT);	}	// is y above first line or is x before first column?	if (point.y + verticalScrollOffset < 0 || point.x + horizontalScrollOffset < 0) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}		line = (getTopPixel() + point.y) / lineHeight;		// does the referenced line exist?	if (line >= content.getLineCount()) {		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}		lineText = content.getLine(line);	lineOffset = content.getOffsetAtLine(line);			int x = point.x - leftMargin + horizontalScrollOffset;	layout = renderer.getTextLayout(lineText, lineOffset);	Rectangle rect = layout.getLineBounds(0);	if (x > rect.x + rect.width) {		renderer.disposeTextLayout(layout);		SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	int[] trailing = new int[1];	offsetInLine = layout.getOffset(x, 0, trailing);	if (offsetInLine != lineText.length() - 1) {		offsetInLine = Math.min(lineText.length(), offsetInLine + trailing[0]);			}	renderer.disposeTextLayout(layout);	return lineOffset + offsetInLine;}