int x11_init(GraceApp *gapp) { X11Stuff *xstuff = gapp->gui->xstuff; XGCValues gc_val; long mrsize; int max_path_limit; xstuff->screennumber = DefaultScreen(xstuff->disp); xstuff->root = RootWindow(xstuff->disp, xstuff->screennumber); xstuff->gc = DefaultGC(xstuff->disp, xstuff->screennumber); xstuff->depth = DisplayPlanes(xstuff->disp, xstuff->screennumber); /* init colormap */ xstuff->cmap = DefaultColormap(xstuff->disp, xstuff->screennumber); /* redefine colormap, if needed */ if (gapp->gui->install_cmap == CMAP_INSTALL_ALWAYS) { xstuff->cmap = XCopyColormapAndFree(xstuff->disp, xstuff->cmap); gapp->gui->private_cmap = TRUE; } /* set GCs */ if (gapp->gui->invert) { gc_val.function = GXinvert; } else { gc_val.function = GXxor; } gcxor = XCreateGC(xstuff->disp, xstuff->root, GCFunction, &gc_val); /* XExtendedMaxRequestSize() appeared in X11R6 */ #if XlibSpecificationRelease > 5 mrsize = XExtendedMaxRequestSize(xstuff->disp); #else mrsize = 0; #endif if (mrsize <= 0) { mrsize = XMaxRequestSize(xstuff->disp); } max_path_limit = (mrsize - 3)/2; if (max_path_limit < get_max_path_limit(grace_get_canvas(gapp->grace))) { char buf[128]; sprintf(buf, "Setting max drawing path length to %d (limited by the X server)", max_path_limit); errmsg(buf); set_max_path_limit(grace_get_canvas(gapp->grace), max_path_limit); } xstuff->dpi = rint(MM_PER_INCH*DisplayWidth(xstuff->disp, xstuff->screennumber)/ DisplayWidthMM(xstuff->disp, xstuff->screennumber)); return RETURN_SUCCESS; }
int set_printer_by_name(GraceApp *gapp, const char *dname) { Canvas *canvas = grace_get_canvas(gapp->grace); int device; device = get_device_by_name(canvas, dname); return set_printer(gapp, device); }
/* * set the current print device */ int set_printer(GraceApp *gapp, int device) { Canvas *canvas = grace_get_canvas(gapp->grace); Device_entry *d = get_device_props(canvas, device); if (!d || d->type == DEVICE_TERM) { return RETURN_FAILURE; } else { gapp->rt->hdevice = device; if (d->type != DEVICE_PRINT) { set_ptofile(gapp, TRUE); } return RETURN_SUCCESS; } }
int set_set_colors(Quark *pset, unsigned int color) { set *p = set_get_data(pset); GraceApp *gapp = gapp_from_quark(pset); if (!p || !gapp) { return RETURN_FAILURE; } if (color < number_of_colors(grace_get_canvas(gapp->grace))) { p->line.line.pen.color = color; p->sym.line.pen.color = color; p->sym.fillpen.color = color; p->errbar.pen.color = color; quark_dirtystate_set(pset, TRUE); return RETURN_SUCCESS; } else { return RETURN_FAILURE; } }
Pixmap char_to_pixmap(Widget w, int font, char c, int csize) { X11Stuff *xstuff = gapp->gui->xstuff; CPixmap *pm; Pixmap pixmap = 0; int height, width, hshift, vshift; float fsize = 0.8*(float)csize; Canvas *canvas = grace_get_canvas(gapp->grace); pm = canvas_raster_char(canvas, grace_fmap(gapp->gp, canvas, font), c, fsize, &vshift, &hshift); if (pm != NULL && pm->bits != NULL) { long bg, fg; Pixmap ptmp; vshift = csize - vshift - 4; height = pm->height; width = pm->width; ptmp = XCreateBitmapFromData(xstuff->disp, xstuff->root, pm->bits, width, height); pixmap = XCreatePixmap(xstuff->disp, xstuff->root, csize, csize, xstuff->depth); XtVaGetValues(w, XmNbackground, &bg, XmNforeground, &fg, NULL); XSetFillStyle(xstuff->disp, xstuff->gc, FillSolid); XSetForeground(xstuff->disp, xstuff->gc, bg); XFillRectangle(xstuff->disp, pixmap, xstuff->gc, 0, 0, csize, csize); XSetBackground(xstuff->disp, xstuff->gc, bg); XSetForeground(xstuff->disp, xstuff->gc, fg); XCopyPlane(xstuff->disp, ptmp, pixmap, xstuff->gc, 0, 0, width, height, hshift, vshift, 1); XFreePixmap(xstuff->disp, ptmp); } canvas_cpixmap_free(pm); return pixmap; }
/* * If writing to a file, check to see if it exists */ void do_hardcopy(const GProject *gp) { Quark *project = gproject_get_top(gp); GraceApp *gapp = gapp_from_quark(project); RunTime *rt; Canvas *canvas; char fname[GR_MAXPATHLEN]; view v; double vx, vy; int truncated_out, res; FILE *prstream; if (!gapp) { return; } rt = gapp->rt; canvas = grace_get_canvas(gapp->grace); if (get_ptofile(gapp)) { if (string_is_empty(rt->print_file)) { Device_entry *dev = get_device_props(canvas, rt->hdevice); sprintf(rt->print_file, "%s.%s", QIDSTR(project), dev->fext); } strcpy(fname, rt->print_file); prstream = gapp_openw(gapp, fname); } else { strcpy(fname, "gappXXXXXX"); prstream = gapp_tmpfile(fname); } if (prstream == NULL) { return; } canvas_set_prstream(canvas, prstream); select_device(canvas, rt->hdevice); res = gproject_render(gp); gapp_close(prstream); if (res != RETURN_SUCCESS) { return; } get_bbox(canvas, BBOX_TYPE_GLOB, &v); project_get_viewport(project, &vx, &vy); if (v.xv1 < 0.0 - VP_EPSILON || v.xv2 > vx + VP_EPSILON || v.yv1 < 0.0 - VP_EPSILON || v.yv2 > vy + VP_EPSILON) { truncated_out = TRUE; } else { truncated_out = FALSE; } if (get_ptofile(gapp) == FALSE) { if (truncated_out == FALSE || yesno("Printout is truncated. Continue?", NULL, NULL, NULL)) { gapp_print(gapp, fname); #ifndef PRINT_CMD_UNLINKS remove(fname); #endif } } else { if (truncated_out == TRUE) { errmsg("Output is truncated - tune device dimensions"); } } }