ET++: DevStrokeLine Examples

When a line is drawn in ET++, DevStrokeLink is called on the current Port. The Port abstraction separates the drawing interface from the implementation. As an example of the great power this provides, here are three implementations of DevStrokeLine in ET++ (DevStrokeLine2 is called by Port::DevStrokeLine() after it does some bookkeeping). The first draws the line in an XWindows window; the second adds the line to a Macintosh PICT file being generated, and the third adds the line to a Postscript file or printout being generated. All drawing in ET++ goes through this abstraction layer, so anything which can appear on the screen can appear in a printout or a graphics file, by changing the current port can using the same code.


void XWindowPort::DevStrokeLine2(int psz, const Rectangle&, GrLineCap,
		const Point &start, const Point &end)
{
	if (psz < 0)
		return;
	SetLine(psz);
	SetTS();
	XDrawLine(dpy, id, gc, start.x, start.y, end.x, end.y);
}

void MacPictPort::DevStrokeLine2(int psz, const Rectangle &r, GrLineCap,
					const Point &p1, const Point &p2)
{
	Merge(r);
	PutSize(psz);
	os->PutBigEndian(2, 0x0020);
	PutPoint(p1);
	PutPoint(p2);
}

void PostScriptPort::DevStrokeLine(int pensize, const Rectangle &r,
				GrLineCap cap, const Point &p1, const Point &p2)
{
	SetPenSize(pensize);
	Merge(r);
	Printf(pfp, "%p %p %d StrokeArrow\n", &p1, &p2, cap);
}

Back to the graphical layout description

Back to the main ET++ page