lmar = -x1; rmar = x1 + w - d.width; tmar = -y1; bmar = y1 + h - d.height;
lmar = -src.dx - x1; rmar = -src.dx + x1 + w - d.width; tmar = -src.dy - y1; bmar = -src.dy + y1 + h - d.height;
void CopyArea(vWindow src, int x1, int y1, int w, int h, int x2, int y2) {    // check for source portions outside window bounds    Dimension d = src.c.getSize();    int lmar, rmar, tmar, bmar;    lmar = -x1;			// amount outside left edge    rmar = x1 + w - d.width;	// amount outside right edge    tmar = -y1;			// amount outside top edge    bmar = y1 + h - d.height;	// amount outside bottom edge    // adjust bounds for any positive margins; truncate negative margins to 0    if (lmar > 0) {	x1 += lmar;	x2 += lmar;	w -= lmar;    } else {	lmar = 0;    }    if (rmar > 0) {	w -= rmar;    } else {	rmar = 0;    }    if (tmar > 0) {	y1 += tmar;	y2 += tmar;	h -= tmar;    } else {	tmar = 0;    }    if (bmar > 0) {	h -= bmar;    } else {	bmar = 0;    }    // copy source region, if anything remains    if (w > 0 && h > 0) {	if (xormode) {	    b.setPaintMode();	    a.setPaintMode();	}	// remaining source area is within bounds of window	if (src == this) {	    b.copyArea(x1, y1, w, h, x2 - x1, y2 - y1);	} else {	    b.drawImage(src.c.i, x2, y2, x2+w, y2+h, x1, y1, x1+w, y1+h, null);	}	a.drawImage(c.i, x2, y2, x2 + w, y2 + h,	    x2 + dx, y2 + dy, x2 + w + dx, y2 + h + dy, null);    }    // erase areas "copied" from outside window bounds    if (lmar + rmar + tmar + bmar > 0) {	wColor bgsave = bg;	bg = src.bg;	if (lmar > 0) {	    EraseArea(x2 - lmar, y2 - tmar, lmar, tmar + h + bmar);	}	if (rmar > 0) {	    EraseArea(x2 + w, y2 - tmar, rmar, tmar + h + bmar);	}	if (tmar > 0) {	    EraseArea(x2, y2 - tmar, w, tmar);	}	if (bmar > 0) {	    EraseArea(x2, y2 + h, w, bmar);	}	bg = bgsave;    }    if (xormode) {	b.setXORMode(bg);	a.setXORMode(bg);    }}