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.gdk_region_new(); int[] nRects = new int[1]; int [] rects = new int [1]; OS.gdk_region_get_rectangles(clipRgn, rects, nRects); GdkRectangle rect = new GdkRectangle(); int[] pointArray = new int[8]; double[] x = new double[1], y = new double[1]; for (int i=0; i<nRects[0]; i++) { OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof); x[0] = rect.x; y[0] = rect.y; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[0] = (int)Math.round(x[0]); pointArray[1] = (int)Math.round(y[0]); x[0] = rect.x + rect.width; y[0] = rect.y; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[2] = (int)Math.round(x[0]); pointArray[3] = (int)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] = (int)Math.round(x[0]); pointArray[5] = (int)Math.round(y[0]); x[0] = rect.x; y[0] = rect.y + rect.height; Cairo.cairo_matrix_transform_point(matrix, x, y); pointArray[6] = (int)Math.round(x[0]); pointArray[7] = (int)Math.round(y[0]); int  polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE); OS.gdk_region_union(newRgn, polyRgn); OS.gdk_region_destroy(polyRgn); } if (rects[0] != 0) OS.g_free(rects[0]); OS.gdk_region_destroy(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.gdk_region_new();		int[] nRects = new int[1];		int /*long*/[] rects = new int /*long*/[1];		OS.gdk_region_get_rectangles(clipRgn, rects, nRects);		GdkRectangle rect = new GdkRectangle();		int[] pointArray = new int[8];		double[] x = new double[1], y = new double[1];		for (int i=0; i<nRects[0]; i++) {			OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof);			x[0] = rect.x;			y[0] = rect.y;			Cairo.cairo_matrix_transform_point(matrix, x, y);			pointArray[0] = (int)Math.round(x[0]);			pointArray[1] = (int)Math.round(y[0]);			x[0] = rect.x + rect.width;			y[0] = rect.y;			Cairo.cairo_matrix_transform_point(matrix, x, y);			pointArray[2] = (int)Math.round(x[0]);			pointArray[3] = (int)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] = (int)Math.round(x[0]);			pointArray[5] = (int)Math.round(y[0]);			x[0] = rect.x;			y[0] = rect.y + rect.height;			Cairo.cairo_matrix_transform_point(matrix, x, y);			pointArray[6] = (int)Math.round(x[0]);			pointArray[7] = (int)Math.round(y[0]);			int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE);			OS.gdk_region_union(newRgn, polyRgn);			OS.gdk_region_destroy(polyRgn);		}		if (rects[0] != 0) OS.g_free(rects[0]);		OS.gdk_region_destroy(clipRgn);		data.clipRgn = newRgn;	}}