Example #1
0
DPSContext XDPSGetSharedContext(Display *display)
{
    DisplayInfo d = LookupDisplayInfo(display);
    ContextInfo c;
    DPSContext context;

    if (d->extensionPresent == ext_no) return NULL;

    if (d->defaultContext != NULL) context = d->defaultContext;
    else {
	context = XDPSCreateSimpleContext(display,
					  None, None, 0, 0,
					  DPSDefaultTextBackstop,
					  DPSDefaultErrorProc, NULL);
	if (context != NULL) {
	    c = AllocContextInfo(context);
	    d->defaultContext = context;
	    c->displayInfo = d;
	    (void) _XDPSSetComponentInitialized(context, dps_init_bit_share);
	    _DPSSInstallDPSlibDict(context);
	    (void) XDPSSetContextDepth(context,
				       DefaultScreenOfDisplay(display),
				       DefaultDepth(display,
						    DefaultScreen(display)));
	}
    }

    if (context == NULL) d->extensionPresent = ext_no;
    else d->extensionPresent = ext_yes;

    return context;
}
Example #2
0
void XDPSRegisterContext(DPSContext context, Bool makeSharedContext)
{
    Display *display;
    Bool inited;
    ContextInfo c;
    
    /* Get the display */
    (void) XDPSXIDFromContext(&display, context);

    if (makeSharedContext) {	/* Install as shared ctxt for this display */
        c = LookupContext(display, context);
	c->displayInfo->defaultContext = context;
    } else {			/* Just add to the context list */
        c = LookupContext(display, context);
    }

    c->displayInfo->extensionPresent = ext_yes;

    (void) _XDPSTestComponentInitialized(context, dps_init_bit_share, &inited);
    if (!inited) {
	(void) _XDPSSetComponentInitialized(context, dps_init_bit_share);
	_DPSSInstallDPSlibDict(context);
    }
}
Example #3
0
int XDPSImageFileIntoDrawable(
    DPSContext context,
    Screen *screen,
    Drawable dest,
    FILE *file,
    int drawableHeight,
    int drawableDepth,
    XRectangle *bbox,
    int xOffset, int yOffset,
    double pixelsPerPoint,
    Bool clear, Bool createMask,
    Bool waitForCompletion,
    Bool *doneFlag)
{
#define BUFSIZE 256
#define EXECLEN 6
    char buf[BUFSIZE];
    static char eobuf[] = "\n$Adobe$DPS$Lib$Dict /execSuccess true put\n\
stop\n\
Magic end of data line )))))))))) 99#2 2#99 <xyz> // 7gsad,32h4ghNmndFgj2\n";
    XDPSStandardColormap maskMap;
    XDPSStandardColormap rgbMap;
    unsigned int flags = 0;
    int status;
    Bool inited;
    DPSPointer cookie;
    int doublings;
    int ms;
    XDPSStatusProc oldProc;
    unsigned long startReqNum = 0, endReqNum;

    if (screen == NULL || dest == None || 
	drawableHeight <= 0 || drawableDepth <= 0 ||
	pixelsPerPoint <= 0) {
	return dps_status_illegal_value;
    }

    if (context == NULL) {
        context = XDPSGetSharedContext(DisplayOfScreen(screen));
	if (context == NULL) {
	    FillPixmapWithGray(screen, dest, bbox, xOffset, yOffset,
			       pixelsPerPoint,
			       createMask);
	    return dps_status_no_extension;
	}
    }	

    (*rewindFunction)(file, rewindClientData);

    if (!waitForCompletion) {
	DPSWaitContext(context);
	/* Any status events before this point go to old handler */
	startReqNum = NextRequest(DisplayOfScreen(screen));
    }

    status = _XDPSTestComponentInitialized(context,
					   dps_init_bit_preview, &inited);
    if (status != dps_status_success) return status;
    if (!inited) {
	(void) _XDPSSetComponentInitialized(context, dps_init_bit_preview);
	_DPSPDefineExecFunction(context);
    }

    if (createMask) {
	if (drawableDepth != 1) return dps_status_illegal_value;
	maskMap.colormap = None;
	maskMap.red_max = 1;
	maskMap.red_mult = -1;
	maskMap.base_pixel = 1;
	rgbMap.colormap = None;
	rgbMap.red_max = rgbMap.green_max = rgbMap.blue_max = 
		rgbMap.red_mult = rgbMap.green_mult = rgbMap.blue_mult =
		rgbMap.base_pixel = 0;
	flags = XDPSContextGrayMap | XDPSContextRGBMap;
    }

    status = XDPSPushContextParameters(context, screen, drawableDepth,
				     dest, drawableHeight,
				     &rgbMap, &maskMap,
				     flags | XDPSContextScreenDepth |
					      XDPSContextDrawable, &cookie);

    if (status != dps_status_success) return status;

    _DPSPSetMatrix(context, xOffset, yOffset, pixelsPerPoint);

    if (clear) _DPSPClearArea(context, (int) bbox->x, (int) bbox->y,
			      (int) bbox->width, (int) bbox->height);

    if (createMask) _DPSPSetMaskTransfer(context);

    /* Prepare to read PostScript code */
    _DPSPSaveBeforeExec(context, !waitForCompletion);
    DPSWritePostScript(context, "\nexec\n", EXECLEN);

    imaging = True;
    while ((*getsFunction)(buf, BUFSIZE, file, getsClientData) != NULL) {
	DPSWritePostScript(context, buf, strlen(buf));
    }
    imaging = False;

    /* This marks the end of the data stream */
    DPSWritePostScript(context, eobuf, strlen(eobuf));

    if (!waitForCompletion) {
	*doneFlag = False;
	oldProc = XDPSRegisterStatusProc(context, HandlePreviewStatus);
	SetUpStatusVariables(context, cookie, doneFlag, startReqNum, oldProc);
	XDPSSetStatusMask(context, 0, 0, PSFROZENMASK);

	ms = timeStart;

	/* Check for done until we run out of time */
	doublings = 0;
	while (1) {
	    if (XDPSGetContextStatus(context) == PSFROZEN) {
		waitForCompletion = True;
		XDPSUnfreezeContext(context);
		break;
	    }
	    if (doublings >= maxDoubles) break;

	    /* Wait a while */
	    msleep(ms);
	    ms *= 2;
	    doublings++;
	}
    }

    /* If previous decided imaging is done, it changed waitForCompletion */

    if (waitForCompletion) return FinishUp(context, cookie);
    else {
	endReqNum = NextRequest(DisplayOfScreen(screen)) - 1;
	SetEndReqNum(context, endReqNum);
	return dps_status_imaging_incomplete;
    }
#undef EXECLEN
#undef BUFSIZE
}