Exemple #1
0
void
do_print(Widget w)
{
	char	   *printer_val;
	char	   *param_val;
	char	    cmd[255],cmd2[255];
	char	   *c1;
	char	    backgrnd[10], grid[80];

	/* don't print if in the middle of drawing/editing */
	if (check_action_on())
		return;

	if (emptyfigure_msg(print_msg) && !batch_exists)
		return;

	/* create popup panel if not already there so we have all the
	   resources necessary (e.g. printer name etc.) */
	if (!print_popup) 
		create_print_panel(w);

	/* get the magnification into appres.magnification */
	get_magnif();

	/* update the figure size (magnification * bounding_box) */
	print_update_figure_size();

	printer_val = panel_get_value(printer_text);
	param_val = panel_get_value(param_text);

	/* get grid params and assemble into fig2dev parm */
	get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);

	if (batch_exists) {
	    gen_print_cmd(cmd,batch_file,printer_val,param_val);
	    if (system(cmd) != 0)
		file_msg("Error during PRINT");
	    /* clear the batch file and the count */
	    do_clear_batch(w);
	} else {
	    strcpy(cmd, param_val);
	    /* see if the user wants the filename in the param list (%f) */
	    if (!strstr(cur_filename,"%f")) {	/* don't substitute if the filename has a %f */
		while (c1=strstr(cmd,"%f")) {
		    strcpy(cmd2, c1+2);		/* save tail */
		    strcpy(c1, cur_filename);	/* change %f to filename */
		    strcat(c1, cmd2);		/* append tail */
		}
	    }
	    /* make a #rrggbb string from the background color */
	    make_rgb_string(export_background_color, backgrnd);
	    print_to_printer(printer_val, backgrnd, appres.magnification,
				print_all_layers, bound_active_layers, grid, cmd);
	}
}
Exemple #2
0
void write_fig_header(FILE *fp)
{
    char	    str[40], *com;
    int		    i, len;

    if (appres.write_v40) {
	fprintf(fp, "#FIG 4.0  Produced by xfig version %s.%s\n",FIG_VERSION,PATCHLEVEL);
	compound_bound(&objects, &objects.nwcorner.x, &objects.nwcorner.y,
			&objects.secorner.x, &objects.secorner.y);
	fprintf(fp, "Header {\n");
	fprintf(fp, "    Resolution	%d\n", appres.INCHES? PIX_PER_INCH: PIX_PER_CM);
	fprintf(fp, "    Bounds	%d %d %d %d\n", 
				objects.nwcorner.x, objects.nwcorner.y, 
				objects.secorner.x, objects.secorner.y);
	fprintf(fp, "    Orient	%s\n", appres.landscape? "Landscape": "Portrait");
	fprintf(fp, "    Units	%s\n", appres.INCHES? "Inches": "Metric");
	fprintf(fp, "    Uscale	%.3f%s=1%s\n", appres.userscale, appres.INCHES? "in":"cm", cur_fig_units);
	fprintf(fp, "    Pagejust	%s\n", appres.flushleft? "Flush left": "Center");
	fprintf(fp, "    Pagesize	%s\n", paper_sizes[appres.papersize].sname);
	fprintf(fp, "    Pages	%s\n", appres.multiple? "Multiple": "Single");
	fprintf(fp, "    Mag		%.2f\n", appres.magnification);
	get_grid_spec(str, export_grid_minor_text, export_grid_major_text);
	fprintf(fp, "    PGrid	%s\n", str);
	fprintf(fp, "    SGrid	%d\n", cur_gridmode);
	fprintf(fp, "    Smoothing	%d\n", appres.smooth_factor);
	fprintf(fp, "    ExportBgColor %d\n", export_background_color);
	fprintf(fp, "    Transp	%d\n", appres.transparent);
	fprintf(fp, "    Margin	%d\n", appres.export_margin);
#ifdef DONT_SHOW_DEPTHS
	if (dont_show_depths) {
	    fprintf(fp, "    DontShowDepths	{%s}\n", ......);
	}
#endif /* DONT_SHOW_DEPTHS */
	if (objects.comments) {
	    fprintf(fp, "    Description {\n");
	    /* escape any '{' we may find in the comments */
	    com = objects.comments;
	    len = strlen(com);
	    for (i=0; i<len; i++) {
		if (com[i] == '{')
		    fputc('\\', fp);
		fputc(com[i], fp);
	    }
	    fprintf(fp, "\n    }\n");
	}
	fprintf(fp, "}\n");
    } else {
Exemple #3
0
void
do_print_batch(Widget w)
{
	FILE	   *infp,*outfp;
	char	    tmp_exp_file[PATH_MAX];
	char	    str[255];
	char	    backgrnd[10], grid[80];
   int       fd;

	if (writing_batch || emptyfigure_msg(print_msg))
		return;

	/* set lock so we don't come here while still writing a file */
	/* this could happen if the user presses the button too fast */
	writing_batch = True;

	/* make a temporary name to write this figure to */
	snprintf(tmp_exp_file, sizeof(tmp_exp_file), "%s/xfig-exp.XXXXXX",
		TMPDIR);

	if (batch_exists != True) {
		/* make a temporary name to write the batch stuff to */
		sprintf(batch_file, "%s/xfig-batch.XXXXXX", TMPDIR);
		if ((fd = mkstemp(batch_file)) == -1) {
			file_msg("Error creating temporary file");
			return;
		}
		close(fd);
		batch_exists = True;
	}
	if (!print_popup) 
		create_print_panel(w);

	/* get magnification into appres.magnification */
	get_magnif();

	/* update the figure size (magnification * bounding_box) */
	print_update_figure_size();

	/* make a #rrggbb string from the background color */
	make_rgb_string(export_background_color, backgrnd);

	if ((fd = mkstemp(tmp_exp_file)) == -1) {
		file_msg("Error creating temporary file");
		return;
	}
	close(fd);

	/* get grid params and assemble into fig2dev parm */
	get_grid_spec(grid, print_grid_minor_text, print_grid_major_text);

	print_to_file(tmp_exp_file, "ps", appres.magnification, 0, 0, backgrnd,
				NULL, False, print_all_layers, bound_active_layers, 0, False, grid, appres.overlap);
	put_msg("Appending to batch file \"%s\" (%s mode) ... done",
		    batch_file, appres.landscape ? "LANDSCAPE" : "PORTRAIT");
	app_flush();		/* make sure message gets displayed */

	/* now append that to the batch file */
	if ((infp = fopen(tmp_exp_file, "rb")) == NULL) {
		file_msg("Error during PRINT - can't open temporary file to read");
		return;
		}
	if ((outfp = fopen(batch_file, "ab")) == NULL) {
		file_msg("Error during PRINT - can't open print file to append");
		return;
		}
	while (fgets(str,255,infp) != NULL)
		(void) fputs(str,outfp);
	fclose(infp);
	fclose(outfp);
	unlink(tmp_exp_file);
	/* count this batch figure */
	num_batch_figures++ ;
	/* and update the label widget */
	update_batch_count();
	/* we're done */
	writing_batch = False;
}