ftp.nice.ch/peanuts/GeneralData/Documents/adobe/DPS.UNIXReview.Aug94.tar.gz#/eps1.c

This is eps1.c in view mode; [Download] [Up]

#include <stdio.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <DPS/dpsXclient.h>
#include <DPS/dpsXpreview.h>
#include <ieeefp.h>

int isinf(double d) {return !finite(d);}

/*
 * The following declarations are part of the mechanism that
 * calls the Redisplay procedure whenever the contents need
 * to be updated.
 */

void Redisplay();
double PixelsPerPoint(Screen *);
String translations = "<Expose> : Redisplay()";
XtActionsRec actions[] = { {"Redisplay", Redisplay} };

Display *display;       /* Connection to the X server   */
Window window;          /* Window that we'll draw in    */
GC gc;                  /* X graphics context           */
DPSContext ctxt;
FILE *epsf;
Pixmap pixmap;
XRectangle pixmapSize;
XRectangle bbox;

void main(argc, argv)
  int argc;
  char **argv;
{
  Widget appShell, w;
  XtAppContext app;
  int retval;
  Bool doneFlag;
  char *file;
  double pixelsperpoint;
  int depth;

  /*
   * The call to XtAppInitialize creates a connection to the
   * X server. We extract that connection with the call to
   * XtDisplay()
   */

  appShell = XtAppInitialize(&app, "Demo", NULL, 0, &argc, argv, 
                             NULL, NULL, 0);
  if(argc < 2) {
    fprintf(stderr,"Usage: %s eps-file\n",argv[0]);
    exit(1);
  }
  file = argv[1];

  display = XtDisplay(appShell);
  depth = DefaultDepthOfScreen(XtScreen(appShell));
  pixelsperpoint = PixelsPerPoint(XtScreen(appShell));

  /*
   * XtAppAddActions adds Redisplay as an action procedure that 
   * is called when an Expose event is received by the widget.
   */
  XtAppAddActions(app, actions, XtNumber(actions));

  /*
   * Now we can create the window. First we set up some parameters
   * like width and height. The call to XtVaCreateManagedWidget and
   * XtRealize create and initialize the window. We extract the
   * window identifier with the XtWindow call.
   */

  w = XtVaCreateManagedWidget("main", coreWidgetClass, appShell,
                  XtNwidth,  500,
                  XtNheight, 500,
                  XtNtranslations,
		  XtParseTranslationTable(translations),
                  NULL);
  XtRealizeWidget(appShell);
  window = XtWindow(w);

  gc = XCreateGC(display, window, 0, NULL);

  /*
   * Create a context to which the PostScript language code
   * will be sent
   */
  ctxt = XDPSCreateSimpleContext(display, window, gc, 0, 400, 
                        DPSDefaultTextBackstop, 
                        DPSDefaultErrorProc, (DPSSpace) NULL);
  XDPSRegisterContext(ctxt, True);
  epsf = fopen(file, "r");
  if(epsf == NULL) {
    perror(file);
    exit(1);
  }
  retval = XDPSCreatePixmapForEPSF(ctxt,
		XtScreen(w), epsf,
		depth, pixelsperpoint, &pixmap,
		&pixmapSize, &bbox);
  switch(retval) {
  case dps_status_success:
    break;
  case dps_status_failure:
    fprintf(stderr,"File is not EPSF\n");
    exit(1);
  case dps_status_no_extension:
    fprintf(stderr,"Server does not support DPS\n");
    exit(1);
  default:
    fprintf(stderr, "Internal error %d\n", retval);
    exit(1);
  }
  retval = XDPSImageFileIntoDrawable(ctxt,
		XtScreen(w), pixmap, epsf,
		pixmapSize.height, depth,
		&bbox, -bbox.x, -bbox.y,
		pixelsperpoint, True, False, True, &doneFlag);
  switch(retval) {
  case dps_status_success:
    break;
  case dps_status_no_extension:
  case dps_status_unregistered_context:
  case dps_status_illegal_value:
  case dps_status_postscript_error:
  case dps_status_imaging_incomplete:
    fprintf(stderr, "XDPSImageFileIntoDrawable failed\n");
  }
  XtAppMainLoop(app);
}

/* The Redisplay procedure is called whenever the       */
/* contents of the window needs to be repainted.        */

void Redisplay(w, event, params, num)
  Widget w;
  XEvent *event;
  String *params;
  Cardinal *num;
{
  XCopyArea(XtDisplay(w),
		pixmap, window, gc, 0, 0,
		pixmapSize.width, pixmapSize.height, 0, 0);
}

double
PixelsPerPoint(Screen *screen)
{
    return (double) ((double)WidthOfScreen(screen) *
		     (double)(25.4 / 72.0) /
		     (double)(WidthMMOfScreen(screen)));
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.