int  clipRgn = data.clipRgn; if (clipRgn != 0) { double[] matrix = new double[]{1, 0, 0, 1, 0, 0}; Cairo.cairo_get_matrix(cairo, matrix); Cairo.cairo_matrix_invert(matrix); int  newRgn = OS.XCreateRegion();  XRectangle rect = new XRectangle(); OS.XClipBox(clipRgn, rect); short[] pointArray = new short[8]; double[] x = new double[1], y = new double[1]; x[0] = rect.x; y[0] = rect.y; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[0] = (short)Math.round(x[0]); pointArray[1] = (short)Math.round(y[0]); x[0] = rect.x + rect.width; y[0] = rect.y; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[2] = (short)Math.round(x[0]); pointArray[3] = (short)Math.round(y[0]); x[0] = rect.x + rect.width; y[0] = rect.y + rect.height; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[4] = (short)Math.round(x[0]); pointArray[5] = (short)Math.round(y[0]); x[0] = rect.x; y[0] = rect.y + rect.height; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[6] = (short)Math.round(x[0]); pointArray[7] = (short)Math.round(y[0]); int  polyRgn = OS.XPolygonRegion(pointArray, pointArray.length / 2, OS.EvenOddRule); OS.XUnionRegion(handle, polyRgn, handle); OS.XDestroyRegion(polyRgn); OS.XDestroyRegion(clipRgn); data.clipRgn = newRgn; }
public void setTransform(Transform transform) {	if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);	if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);	if (data.cairo == 0 && transform == null) return;	initCairo();	int /*long*/ cairo = data.cairo;	if (transform != null) {		Cairo.cairo_set_matrix(cairo, transform.handle);	} else {		Cairo.cairo_identity_matrix(cairo);	}	//TODO - round off problems	int /*long*/ clipRgn = data.clipRgn;	if (clipRgn != 0) {		double[] matrix = new double[]{1, 0, 0, 1, 0, 0};		Cairo.cairo_get_matrix(cairo, matrix);		Cairo.cairo_matrix_invert(matrix);		int /*long*/ newRgn = OS.XCreateRegion();		//TODO - get rectangles from region instead of clip box		XRectangle rect = new XRectangle();		OS.XClipBox(clipRgn, rect);		short[] pointArray = new short[8];		double[] x = new double[1], y = new double[1];		x[0] = rect.x;		y[0] = rect.y;		Cairo.cairo_matrix_transform_point(matrix, x, y);		pointArray[0] = (short)Math.round(x[0]);		pointArray[1] = (short)Math.round(y[0]);		x[0] = rect.x + rect.width;		y[0] = rect.y;		Cairo.cairo_matrix_transform_point(matrix, x, y);		pointArray[2] = (short)Math.round(x[0]);		pointArray[3] = (short)Math.round(y[0]);		x[0] = rect.x + rect.width;		y[0] = rect.y + rect.height;		Cairo.cairo_matrix_transform_point(matrix, x, y);		pointArray[4] = (short)Math.round(x[0]);		pointArray[5] = (short)Math.round(y[0]);		x[0] = rect.x;		y[0] = rect.y + rect.height;		Cairo.cairo_matrix_transform_point(matrix, x, y);		pointArray[6] = (short)Math.round(x[0]);		pointArray[7] = (short)Math.round(y[0]);		int /*long*/ polyRgn = OS.XPolygonRegion(pointArray, pointArray.length / 2, OS.EvenOddRule);		OS.XUnionRegion(handle, polyRgn, handle);		OS.XDestroyRegion(polyRgn);		OS.XDestroyRegion(clipRgn);		data.clipRgn = newRgn;	}}