Java Code Examples for org.eclipse.swt.SWT#PATH_MOVE_TO

The following examples show how to use org.eclipse.swt.SWT#PATH_MOVE_TO . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: nebula   File: SvgLoader.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static int parseLine(SvgContainer container, char[] ca, int start, int end) {
	end = findClosingTag(ca, start, end);
	if(end != -1) {
		int endAttrs = closer(ca, start, end);
		SvgShape element = new SvgShape(container, getAttrValue(ca, start, endAttrs, ATTR_ID));
		element.pathData = new PathData();
		element.pathData.types = new byte[2];
		element.pathData.points = new float[4];
		element.pathData.types[0] = (byte)SWT.PATH_MOVE_TO;
		element.pathData.points[0] = parseFloat(getAttrValue(ca, start, endAttrs, ATTR_X1), 0);
		element.pathData.points[1] = parseFloat(getAttrValue(ca, start, endAttrs, ATTR_Y1), 0);
		element.pathData.types[1] = (byte)SWT.PATH_LINE_TO;
		element.pathData.points[2] = parseFloat(getAttrValue(ca, start, endAttrs, ATTR_X2), 0);
		element.pathData.points[3] = parseFloat(getAttrValue(ca, start, endAttrs, ATTR_Y2), 0);
		parseFill(element, ca, start, endAttrs);
		parseStroke(element, ca, start, endAttrs);
	}
	return end;
}
 
Example 2
Source Project: nebula   File: SvgLoader.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static int parsePolygon(SvgContainer container, char[] ca, int start, int end) {
	end = findClosingTag(ca, start, end);
	if(end != -1) {
		int endAttrs = closer(ca, start, end);
		SvgShape element = new SvgShape(container, getAttrValue(ca, start, endAttrs, ATTR_ID));
		float[] linePoints = parsePoints(getAttrValue(ca, start, endAttrs, ATTR_POINTS));
		element.pathData = new PathData();
		element.pathData.types = new byte[1+(linePoints.length/2)];
		element.pathData.points = new float[linePoints.length];
		element.pathData.types[0] = (byte)SWT.PATH_MOVE_TO;
		element.pathData.points[0] = linePoints[0];
		element.pathData.points[1] = linePoints[1];
		int i = 2, j = 1;
		while(i < linePoints.length-1) {
			element.pathData.types[j++] = (byte)SWT.PATH_LINE_TO;
			element.pathData.points[i] = linePoints[i++];
			element.pathData.points[i] = linePoints[i++];
		}
		element.pathData.types[element.pathData.types.length-1] = (byte)SWT.PATH_CLOSE;
		parseFill(element, ca, start, endAttrs);
		parseStroke(element, ca, start, endAttrs);
		element.transform = getTransform(ca, getAttrValueRange(ca, start, endAttrs, ATTR_TRANSFORM));
	}
	return end;
}
 
Example 3
Source Project: nebula   File: SvgLoader.java    License: Eclipse Public License 2.0 6 votes vote down vote up
private static int parsePolyline(SvgContainer container, char[] ca, int start, int end) {
	end = findClosingTag(ca, start, end);
	if(end != -1) {
		int endAttrs = closer(ca, start, end);
		SvgShape element = new SvgShape(container, getAttrValue(ca, start, endAttrs, ATTR_ID));
		float[] linePoints = parsePoints(getAttrValue(ca, start, endAttrs, ATTR_POINTS));
		element.pathData = new PathData();
		element.pathData.types = new byte[linePoints.length/2];
		element.pathData.points = new float[linePoints.length];
		element.pathData.types[0] = (byte)SWT.PATH_MOVE_TO;
		element.pathData.points[0] = linePoints[0];
		element.pathData.points[1] = linePoints[1];
		int i = 2, j = 1;
		while(i < linePoints.length-1) {
			element.pathData.types[j++] = (byte)SWT.PATH_LINE_TO;
			element.pathData.points[i] = linePoints[i++];
			element.pathData.points[i] = linePoints[i++];
		}
		parseFill(element, ca, start, endAttrs);
		parseStroke(element, ca, start, endAttrs);
		element.transform = getTransform(ca, getAttrValueRange(ca, start, endAttrs, ATTR_TRANSFORM));
	}
	return end;
}
 
Example 4
Source Project: gef   File: SWT2AWT.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Converts an SWT {@link PathData} into an equivalent AWT
 * {@link PathIterator}.
 * 
 * @param pathData
 *            the {@link PathData} to convert.
 * @param windingRule
 *            the winding rule to use when constructing the
 *            {@link PathIterator}, i.e. one of {@link SWT#FILL_WINDING} or
 *            {@link SWT#FILL_EVEN_ODD}.
 * @return a new {@link PathIterator} representing the same path
 */
public static PathIterator toAWTPathIterator(PathData pathData, int windingRule) {
	if (windingRule != SWT.FILL_WINDING && windingRule != SWT.FILL_EVEN_ODD) {
		throw new IllegalArgumentException(
				"Unsupported winding rule. Must be one of SWT.FILL_WINDING or SWT.FILL_EVEN_ODD");
	}
	Path2D.Double path = new Path2D.Double(
			windingRule == SWT.FILL_EVEN_ODD ? Path2D.WIND_EVEN_ODD : Path2D.WIND_NON_ZERO);
	int j = 0;
	byte[] types = pathData.types;
	float[] points = pathData.points;
	double x, y, x2, y2, x3, y3;
	for (int i = 0; i < types.length; i++) {

		switch (types[i]) {
		case SWT.PATH_MOVE_TO:
			x = points[j++];
			y = points[j++];
			path.moveTo(x, y);
			break;
		case SWT.PATH_LINE_TO:
			x = points[j++];
			y = points[j++];
			path.lineTo(x, y);
			break;
		case SWT.PATH_QUAD_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			path.quadTo(x, y, x2, y2);
			break;
		case SWT.PATH_CUBIC_TO:
			x = points[j++];
			y = points[j++];
			x2 = points[j++];
			y2 = points[j++];
			x3 = points[j++];
			y3 = points[j++];
			path.curveTo(x, y, x2, y2, x3, y3);
			break;
		case SWT.PATH_CLOSE:
			path.closePath();
			break;
		default:
			break;
		}
	}
	return path.getPathIterator(null);
}