This is HW_DPS_printf.c in view mode; [Download] [Up]
#include <X11/StringDefs.h> #include <X11/Intrinsic.h> #include <DPS/dpsXclient.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(); 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; void main(argc, argv) int argc; char **argv; { Widget appShell, w; XtAppContext app; /* * 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); display = XtDisplay(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, 600, XtNheight, 400, XtNtranslations, XtParseTranslationTable(translations), NULL); XtRealizeWidget(appShell); window = XtWindow(w); /* * The following creates an X graphics context */ 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); DPSPrintf(ctxt, "/Helvetica 72 selectfont\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; { /* * Use DPSPrintf to send PostScript language code to the ctxt context */ DPSPrintf(ctxt, "72 72 moveto (Hello World) show\n"); /*DPSPrintf(ctxt, "[3] 0 setdash (Hello World) false charpath stroke ");*/ }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.