computeRuns(null); if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); int line; int lineCount = runs.length; for (line=0; line<lineCount; line++) { if (lineY[line + 1] > y) break; } line = Math.min(line, runs.length - 1); x -= getLineIndent(line); StyleItem[] lineRuns = runs[line]; if (x >= lineWidth[line]) x = lineWidth[line] - 1; if (x < 0) x = 0; int width = 0; for (int i = 0; i < lineRuns.length; i++) { StyleItem run = lineRuns[i]; if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start); if (width + run.width > x) { int xRun = x - width; if (run.style != null && run.style.metrics != null) { GlyphMetrics metrics = run.style.metrics; if (metrics.width > 0) { if (trailing != null) { trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1; } return untranslateOffset(run.start + xRun / metrics.width); } } if (run.tab) { if (trailing != null) trailing[0] = x < (width + run.width / 2) ? 0 : 1; return untranslateOffset(run.start); } int cChars = run.length; int cGlyphs = run.glyphCount; int[] piCP = new int[1]; int[] piTrailing = new int[1]; if ((orientation & SWT.RIGHT_TO_LEFT) != 0) { xRun = run.width - xRun; } int advances = run.justify != 0 ? run.justify : run.advances; OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piCP, piTrailing); if (trailing != null) trailing[0] = piTrailing[0]; return untranslateOffset(run.start + piCP[0]); } width += run.width; } if (trailing != null) trailing[0] = 0; return untranslateOffset(lineOffset[line + 1]);
if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return getOffset (point.x, point.y, trailing) ;
public int getOffset (int x, int y, int[] trailing) {	checkLayout();	computeRuns(null);	if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);	int line;	int lineCount = runs.length;	for (line=0; line<lineCount; line++) {		if (lineY[line + 1] > y) break;	}	line = Math.min(line, runs.length - 1);	x -= getLineIndent(line);	StyleItem[] lineRuns = runs[line];	if (x >= lineWidth[line]) x = lineWidth[line] - 1;	if (x < 0) x = 0;	int width = 0;	for (int i = 0; i < lineRuns.length; i++) {		StyleItem run = lineRuns[i];		if (run.lineBreak && !run.softBreak) return untranslateOffset(run.start);		if (width + run.width > x) {			int xRun = x - width;			if (run.style != null && run.style.metrics != null) {				GlyphMetrics metrics = run.style.metrics;				if (metrics.width > 0) {					if (trailing != null) {						trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1;					}					return untranslateOffset(run.start + xRun / metrics.width);				}			}			if (run.tab) {				if (trailing != null) trailing[0] = x < (width + run.width / 2) ? 0 : 1;				return untranslateOffset(run.start);			}			int cChars = run.length;			int cGlyphs = run.glyphCount;			int[] piCP = new int[1];			int[] piTrailing = new int[1];			if ((orientation & SWT.RIGHT_TO_LEFT) != 0) {				xRun = run.width - xRun;			}			int advances = run.justify != 0 ? run.justify : run.advances;			OS.ScriptXtoCP(xRun, cChars, cGlyphs, run.clusters, run.visAttrs, advances, run.analysis, piCP, piTrailing);			if (trailing != null) trailing[0] = piTrailing[0];			return untranslateOffset(run.start + piCP[0]);		}		width += run.width;	}	if (trailing != null) trailing[0] = 0;	return untranslateOffset(lineOffset[line + 1]);}