📄 gvcprn.c
字号:
if (!convert && (psfile.print_copies > 1))
copies = psfile.print_copies;
if (psfile.dsc == (CDSC *)NULL) {
/* copy non-DSC file */
if (copies > 1) {
fputs("%!\n", pcfile);
add_copies(pcfile, copies);
}
if (psfile.ispdf) {
/* PDF file hasn't been displayed so we don't know the page count */
/* Print/convert all pages */
char *p = psfile_name(&psfile);
fputc('(', pcfile);
for (; *p; p++)
if (*p == '\\')
fputc('/', pcfile);
else if ((*p == '(') || (*p == ')')) {
fputc('\\', pcfile);
fputc(*p, pcfile);
}
else
fputc(*p, pcfile);
fputs(") run\n", pcfile);
}
else if (!gsview_copygfile(pcfile, psfile.file)) {
play_sound(SOUND_ERROR);
fclose(pcfile);
return FALSE;
}
}
else {
if (psfile.ispdf) {
if (!pdf_extract(pcfile, copies)) {
fclose(pcfile);
return FALSE;
}
}
else {
if (psfile.dsc->epsf && !psfile.dsc->dcs2) {
/* Copy EPSF file, making sure it fits on the page
* and includes one and only one showpage
*/
psfile_epsf_print(pcfile, copies);
}
else {
/* copy DSC file */
if ((psfile.dsc->page_count == 0) ||
(!convert && psfile.print_ignoredsc)) {
CDSC *dsc = psfile.dsc;
ps_copy(pcfile, psfile.file, dsc->begincomments,
dsc->endcomments);
ps_copy(pcfile, psfile.file, dsc->begindefaults,
dsc->enddefaults);
ps_copy(pcfile, psfile.file, dsc->beginprolog,
dsc->endprolog);
copy_setup(pcfile, psfile.file, copies);
ps_copy(pcfile, psfile.file, dsc->begintrailer,
dsc->endtrailer);
}
else
if (!psfile_extract(pcfile, copies))
return FALSE;
}
}
}
return TRUE;
}
/* common printer/convert code */
BOOL
gsview_cprint(char *psname, char *optname, BOOL convert)
{
char buf[MAXSTR];
int i;
float print_xdpi, print_ydpi;
int width, height;
int widthpt, heightpt;
struct prop_item_s *proplist;
FILE *optfile;
FILE *pcfile;
char *p;
static char output[MAXSTR]; /* output filename for printing */
static char queue[MAXSTR]; /* output queue if not printing to file */
BOOL printtofile=FALSE;
float xoffset = 0;
float yoffset = 0;
char section[MAXSTR];
PROFILE *prf;
int prectrld=0;
int postctrld=0;
char psprolog[MAXSTR];
char psepilog[MAXSTR];
const char *device;
const char *resolution;
int method = option.print_method;
if (convert)
method = PRINT_CONVERT;
/* ASSUMES psfile.file is open */
if (convert ||
(((method == PRINT_GS) || (method == PRINT_PS)) &&
(option.print_to_file || (strcmp(option.printer_queue, "FILE:")==0)))
) {
printtofile = TRUE;
if (!get_filename(output, TRUE, FILTER_ALL, IDS_OUTPUTFILE, IDS_TOPICPRINT))
return FALSE;
}
else {
strcpy(queue, szSpoolPrefix);
strcat(queue, option.printer_queue);
}
/* create (temporary) file containing pages to print */
psname[0] = '\0';
if ((method == PRINT_PS) && printtofile && !psfile.ispdf) {
/* we want to write the PostScript file directly. */
if ((pcfile = fopen(output, "wb")) == (FILE *)NULL)
return FALSE;
strcpy(psname, output);
}
else if ( (pcfile = gp_open_scratch_file(szScratch, psname, "wb"))
== (FILE *)NULL) {
gserror(IDS_NOTEMP, NULL, MB_ICONEXCLAMATION, SOUND_ERROR);
play_sound(SOUND_ERROR);
return FALSE;
}
if ((method == PRINT_PS) && !psfile.ispdf) {
/* For PostScript printers, provide options for sending
* Ctrl+D before and after job, and sending a prolog
* and epilog file.
* These are set using the Advanced button on the Printer
* Setup dialog, only enabled for PostScript printer
* when document is PostScript.
*/
strcpy(section, option.printer_queue);
if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
profile_read_string(prf, section, "PreCtrlD", "0", buf,
sizeof(buf)-2);
if (sscanf(buf, "%d", &prectrld) != 1)
prectrld = 0;
profile_read_string(prf, section, "PostCtrlD", "0", buf,
sizeof(buf)-2);
if (sscanf(buf, "%d", &postctrld) != 1)
postctrld = 0;
profile_read_string(prf, section, "Prolog", "", psprolog,
sizeof(psprolog)-2);
profile_read_string(prf, section, "Epilog", "", psepilog,
sizeof(psepilog)-2);
profile_close(prf);
}
if (prectrld)
fputc('\004', pcfile);
if (strlen(psprolog)!=0) {
FILE *infile = fopen(psprolog, "rb");
if (infile != (FILE *)NULL) {
if (!gsview_copyfile(pcfile, infile)) {
play_sound(SOUND_ERROR);
return FALSE;
}
fclose(infile);
}
else
play_sound(SOUND_ERROR);
}
}
if (!copy_for_printer(pcfile, convert)) {
gs_addmess("Failed to copy document to temporary file for printing\n");
unlink(psname);
return FALSE;
}
if ((method == PRINT_PS) && !psfile.ispdf) {
if (strlen(psepilog)!=0) {
FILE *infile = fopen(psepilog, "rb");
if (infile != (FILE *)NULL) {
if (!gsview_copyfile(pcfile, infile)) {
play_sound(SOUND_ERROR);
return FALSE;
}
fclose(infile);
}
else
play_sound(SOUND_ERROR);
}
if (postctrld)
fputc('\004', pcfile);
}
fclose(pcfile);
if ((method == PRINT_PS) && printtofile && !psfile.ispdf) {
/* finished - not an error */
/* Don't continue with Ghostscript */
return FALSE;
}
if ((method == PRINT_PS) && !psfile.ispdf) {
/* Send PostScript files direct to printer */
/* If PDF, we must use Ghostscript to convert to PS */
if (!gp_printfile(psname, option.printer_queue)) {
play_sound(SOUND_ERROR);
return FALSE;
}
unlink(psname);
/* finished - not an error */
/* Don't continue with Ghostscript */
return FALSE;
}
if (convert) {
device = option.convert_device;
resolution = option.convert_resolution;
}
else if (method == PRINT_GDI) {
switch (option.print_gdi_depth) {
case IDC_COLOUR:
device = "bmp16m";
break;
case IDC_GREY:
device = "bmpgray";
break;
default:
device = "bmpmono";
break;
}
resolution = "300"; /* fix later */
}
else if (method == PRINT_PS) {
device = "pswrite";
resolution = "600"; /* a guess */
}
else {
device = option.printer_device;
resolution = option.printer_resolution;
}
/* calculate image size */
switch (sscanf(resolution, "%fx%f", &print_xdpi, &print_ydpi)) {
case EOF:
case 0:
print_xdpi = print_ydpi = DEFAULT_RESOLUTION;
break;
case 1:
print_ydpi = print_xdpi;
}
widthpt = get_paper_width();
heightpt = get_paper_height();
width = (unsigned int)(widthpt / 72.0 * print_xdpi + 0.5);
height = (unsigned int)(heightpt / 72.0 * print_ydpi + 0.5);
if (method == PRINT_GDI) {
/* Use values obtained from device context */
width = print_gdi_width;
height = print_gdi_height;
print_xdpi = (float)print_gdi_xdpi;
print_ydpi = (float)print_gdi_ydpi;
}
/* create options file */
#ifdef UNIX
if ((optname[0] != '\0') && !debug)
unlink(optname);
#endif
optname[0] = '\0';
if ( (optfile = gp_open_scratch_file(szScratch, optname, "w")) == (FILE *)NULL) {
play_sound(SOUND_ERROR);
return FALSE;
}
if (option.gsinclude[0])
fprintf(optfile, "-I\042%s\042\n", option.gsinclude);
fprintf(optfile, "-dNOPAUSE\n");
/* If using a PDF file, we set SAFER later after we have opened
* the PDF file.
*/
if (option.safer && (!psfile.ispdf || (option.gsversion < 704)))
fprintf(optfile, "-dSAFER\n");
if (strcmp(device, "uniprint") == 0) {
/* uniprint sets the device name and resolution in */
/* a configuration file */
/* Since we don't know the resolution, set the page size in points */
fprintf(optfile, "-dDEVICEWIDTHPOINTS=%u\n", widthpt);
fprintf(optfile, "-dDEVICEHEIGHTPOINTS=%u\n", heightpt);
}
else {
fprintf(optfile, "-sDEVICE=%s\n",device);
fprintf(optfile, "-dDEVICEXRESOLUTION=%g\n", (double)print_xdpi);
fprintf(optfile, "-dDEVICEYRESOLUTION=%g\n", (double)print_ydpi);
fprintf(optfile, "-dDEVICEWIDTH=%u\n", width);
fprintf(optfile, "-dDEVICEHEIGHT=%u\n", height);
}
if (method == PRINT_GDI) {
fprintf(optfile, "-sOutputFile=\042%%handle%%%08lx\042\n",
(unsigned long)print_gdi_write_handle);
}
else {
fprintf(optfile, "-sOutputFile=\042");
for (p=(printtofile) ? output : queue; *p != '\0'; p++)
fputc(*p,optfile);
fputc('\042',optfile);
fputc('\n',optfile);
}
if ((proplist = get_properties(device)) != (struct prop_item_s *)NULL) {
/* output current property selections */
for (i=0; proplist[i].name[0]; i++) {
if (strcmp(proplist[i].value, not_defined) != 0)
fprintf(optfile,"-%s=%s\n", proplist[i].name, proplist[i].value);
}
free((char *)proplist);
}
p = option.gsother;
while ((p = gs_argnext(p, buf, TRUE)) != NULL)
fprintf(optfile, "%s\n", buf);
/* Delay all things that call setpagedevice until the end */
strcpy(section, (method == PRINT_GDI) ? "GDI" : device);
strcat(section, " Options");
if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
/* Options */
profile_read_string(prf, section, "Options", "", buf, sizeof(buf)-2);
if (strlen(buf) > 0) {
if (buf[0] == '@') {
/* STUPID Windows *sometimes* removes the quotes.
* If the profile string contains quotes at the
* the start *and* end, Windows will remove them.
* Otherwise, quotes will be copied intact.
* The quotes are important, so we have to put
* them back in.
*/
fprintf(optfile, "\042%s\042\n", buf);
}
else
fprintf(optfile, "%s\n", buf);
}
/* PageOffset */
profile_read_string(prf, section, "Xoffset", "0", buf, sizeof(buf)-2);
if (sscanf(buf, "%f", &xoffset) != 1)
xoffset = 0;
profile_read_string(prf, section, "Yoffset", "0", buf, sizeof(buf)-2);
if (sscanf(buf, "%f", &yoffset) != 1)
yoffset = 0;
if ((xoffset != 0) || (yoffset != 0))
fprintf(optfile, "-c \042<< /PageOffset [%g %g] >> setpagedevice\042\n-f\n",
(double)xoffset, (double)yoffset);
profile_close(prf);
}
if ( ((method==PRINT_GS) && option.print_fixed_media)
|| ((method==PRINT_GDI) && option.print_gdi_fixed_media)
|| ((method==PRINT_CONVERT) && option.convert_fixed_media) ) {
/* Force page size to remain unchanged and let the
* GS page matching code rotate the pages as needed.
* Must do this after the device is opened.
*/
int fixed_media = option.print_fixed_media;
if (method == PRINT_GDI)
fixed_media = option.print_gdi_fixed_media;
if (method == PRINT_CONVERT)
fixed_media = option.convert_fixed_media;
fprintf(optfile,
"-c << /Policies << /PageSize %d >> /PageSize [%d %d] ",
(fixed_media == 1) ? 5 : 3, widthpt, heightpt);
fprintf(optfile, "/InputAttributes << 0 << /PageSize [%d %d] >> >> >> setpagedevice -f\n",
widthpt, heightpt);
}
if (strcmp(device, "pdfwrite")==0) {
if (option.gsversion >= 650)
fprintf(optfile, "-c .setpdfwrite -f\n");
else
fprintf(optfile, "-c save pop -f\n");
}
fclose(optfile);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -