From 79f65d040d72f778f66f8eefdaffb6acd9799a38 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Tue, 10 May 2005 07:59:48 +0000 Subject: Merge of the newly developped postscript code (still not fully functional). --- generic/Icon.c | 129 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 101 insertions(+), 28 deletions(-) (limited to 'generic/Icon.c') diff --git a/generic/Icon.c b/generic/Icon.c index 38c4ac9..5b9eae8 100644 --- a/generic/Icon.c +++ b/generic/Icon.c @@ -228,6 +228,57 @@ Query(ZnItem item, /* + * Compute the transformation to be used and the origin + * of the icon (upper left point in item coordinates). + */ +static ZnTransfo * +ComputeTransfoAndOrigin(ZnItem item, + ZnPoint *origin) +{ + IconItem icon = (IconItem) item; + int w, h; + ZnTransfo *t; + + ZnSizeOfImage(icon->image, &w, &h); + + /* + * The connected item support anchors, this is checked by configure. + */ + if (item->connected_item != ZN_NO_ITEM) { + ZnTransfo inv; + + item->connected_item->class->GetAnchor(item->connected_item, + icon->connection_anchor, + origin); + + /* GetAnchor return a position in device coordinates not in + * the item coordinate space. To compute the icon origin + * (upper left corner), we must apply the inverse transform + * to the ref point before calling anchor2origin. + */ + ZnTransfoInvert(item->transfo, &inv); + ZnTransformPoint(&inv, origin, origin); + /* + * The relevant transform in case of an attachment is the item + * transform alone. This is case of local coordinate space where + * only the translation is a function of the whole transform + * stack, scale and rotation are reset. + */ + t = item->transfo; + } + else { + origin->x = origin->y = 0; + t = item->wi->current_transfo; + } + + ZnAnchor2Origin(origin, (ZnReal) w, (ZnReal) h, icon->anchor, origin); + //origin->x = ZnNearestInt(origin->x); + //origin->y = ZnNearestInt(origin->y); + + return t; +} + +/* ********************************************************************************** * * ComputeCoordinates -- @@ -238,10 +289,11 @@ static void ComputeCoordinates(ZnItem item, ZnBool force) { - ZnWInfo *wi = item->wi; - IconItem icon = (IconItem) item; - int width, height, i; - ZnPoint pos, quad[4]; + //ZnWInfo *wi = item->wi; + IconItem icon = (IconItem) item; + int width, height, i; + ZnPoint quad[4]; + ZnTransfo *t; ZnResetBBox(&item->item_bounding_box); @@ -252,34 +304,16 @@ ComputeCoordinates(ZnItem item, return; } - if (icon->image != ZnUnspecifiedImage) { - ZnSizeOfImage(icon->image, &width, &height); - } - + ZnSizeOfImage(icon->image, &width, &height); + t = ComputeTransfoAndOrigin(item, quad); - /* - * The connected item support anchors, this is checked by - * configure. - */ - if (item->connected_item != ZN_NO_ITEM) { - ZnTransfo t; - - item->connected_item->class->GetAnchor(item->connected_item, - icon->connection_anchor, quad); - ZnTransfoInvert(wi->current_transfo, &t); - ZnTransformPoint(&t, quad, &pos); - } - else { - pos.x = pos.y = 0; - } - ZnAnchor2Origin(&pos, (ZnReal) width, (ZnReal) height, icon->anchor, quad); quad[1].x = quad[0].x; quad[1].y = quad[0].y + height; quad[2].x = quad[0].x + width; quad[2].y = quad[1].y; quad[3].x = quad[2].x; quad[3].y = quad[0].y; - ZnTransformPoints(wi->current_transfo, quad, icon->dev, 4); + ZnTransformPoints(t, quad, icon->dev, 4); for (i = 0; i < 4; i++) { icon->dev[i].x = ZnNearestInt(icon->dev[i].x); @@ -726,10 +760,49 @@ Pick(ZnItem item, * ********************************************************************************** */ -static void -PostScript(ZnItem item, - ZnBool prepass) +static int +PostScript(ZnItem item, + ZnBool prepass, + ZnBBox *area) { + ZnWInfo *wi = item->wi; + IconItem icon = (IconItem) item; + int w, h, result; + ZnPoint origin; + char path[500]; + + if (prepass || (icon->image == ZnUnspecifiedImage)) { + return TCL_OK; + } + + ZnSizeOfImage(icon->image, &w, &h); + + ComputeTransfoAndOrigin(item, &origin); + + sprintf(path, "/InitialTransform load setmatrix\n" + "[%.15g %.15g %.15g %.15g %.15g %.15g] concat\n" + "1 -1 scale\n" + "%.15g %.15g translate\n", + wi->current_transfo->_[0][0], wi->current_transfo->_[0][1], + wi->current_transfo->_[1][0], wi->current_transfo->_[1][1], + wi->current_transfo->_[2][0], wi->current_transfo->_[2][1], + origin.x, origin.y - h); + Tcl_AppendResult(wi->interp, path, NULL); + + if (ZnImageIsBitmap(icon->image)) { + if (Tk_PostscriptColor(wi->interp, wi->ps_info, + ZnGetGradientColor(icon->color, 0.0, NULL)) != TCL_OK) { + return TCL_ERROR; + } + result = ZnPostscriptBitmap(wi->interp, wi->win, wi->ps_info, + icon->image, 0, 0, w, h); + } + else { + result = Tk_PostscriptImage(ZnImageTkImage(icon->image), wi->interp, wi->win, + wi->ps_info, 0, 0, w, h, prepass); + } + + return result; } -- cgit v1.1