summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2019-05-17 09:57:23 +0200
committerDidier Raboud <odyx@debian.org>2019-05-17 09:57:23 +0200
commit5a0f071ca4c281d62f712a963a7b09bf79298a24 (patch)
tree3bdd210f4cb65ecd2c70adb897125373e4c0df3b /filter
parentbd00f293b5c84f812fd1114557a61eb3ea8a6463 (diff)
New upstream version 1.23.0
Diffstat (limited to 'filter')
-rw-r--r--filter/imagetopdf.c148
-rw-r--r--filter/imagetoraster.c152
-rw-r--r--filter/mupdftoraster.c81
-rw-r--r--filter/pdftopdf/pdftopdf.cc30
-rw-r--r--filter/pdftopdf/pdftopdf_processor.cc42
-rw-r--r--filter/pdftopdf/pdftopdf_processor.h6
-rw-r--r--filter/pdftops.c275
-rw-r--r--filter/rastertops.c33
8 files changed, 426 insertions, 341 deletions
diff --git a/filter/imagetopdf.c b/filter/imagetopdf.c
index 0bf2618dd..d4ff36539 100644
--- a/filter/imagetopdf.c
+++ b/filter/imagetopdf.c
@@ -811,30 +811,6 @@ main(int argc, /* I - Number of command-line arguments */
}
}
- /*
- * print-scaling = fill functionality.
- */
- if((val = cupsGetOption("print-scaling",num_options,options)) !=0) {
- if(!strcasecmp(val,"fill")) {
- fillprint = 1;
- }
- }
- else if((val = cupsGetOption("fill",num_options,options))!=0) {
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
- {
- fillprint = 1;
- }
- }
- /*
- * crop-to-fit
- */
- if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
- {
- cropfit=1;
- }
- }
-
if ((val = cupsGetOption("OutputOrder",num_options,options)) != 0) {
if (!strcasecmp(val, "Reverse")) {
Reverse = 1;
@@ -900,21 +876,6 @@ main(int argc, /* I - Number of command-line arguments */
if ((val = cupsGetOption("brightness", num_options, options)) != NULL)
brightness = atoi(val) * 0.01f;
- if ((val = cupsGetOption("scaling", num_options, options)) != NULL)
- zoom = atoi(val) * 0.01;
- else if (((val =
- cupsGetOption("fit-to-page", num_options, options)) != NULL) ||
- ((val = cupsGetOption("fitplot", num_options, options)) != NULL))
- {
- if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
- !strcasecmp(val, "true"))
- zoom = 1.0;
- else
- zoom = 0.0;
- }
- else if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL)
- zoom = 0.0;
-
if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
{
if (sscanf(val, "%dx%d", &xppi, &yppi) < 2)
@@ -997,6 +958,113 @@ main(int argc, /* I - Number of command-line arguments */
colorspace = ColorDevice ? CUPS_IMAGE_RGB_CMYK : CUPS_IMAGE_WHITE;
img = cupsImageOpen(filename, colorspace, CUPS_IMAGE_WHITE, sat, hue, NULL);
+ if(img!=NULL){
+
+ int margin_defined = 0;
+ int fidelity = 0;
+ int document_large = 0;
+
+ if(ppd->custom_margins[0]||ppd->custom_margins[1]||
+ ppd->custom_margins[2]||ppd->custom_margins[3]) // In case of custom margins
+ margin_defined = 1;
+ if(PageLength!=PageTop-PageBottom||PageWidth!=PageRight-PageLeft)
+ margin_defined = 1;
+
+ if((val = cupsGetOption("ipp-attribute-fidelity",num_options,options)) != NULL) {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes")||
+ !strcasecmp(val,"on")) {
+ fidelity = 1;
+ }
+ }
+
+ float w = (float)cupsImageGetWidth(img);
+ float h = (float)cupsImageGetHeight(img);
+ float pw = PageRight-PageLeft;
+ float ph = PageTop-PageBottom;
+ int tempOrientation = Orientation;
+ if((val = cupsGetOption("orientation-requested",num_options,options))!=NULL) {
+ tempOrientation = atoi(val);
+ }
+ else if((val = cupsGetOption("landscape",num_options,options))!=NULL) {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes")) {
+ tempOrientation = 4;
+ }
+ }
+ if(tempOrientation==0) {
+ int temp1 = pw,
+ temp2 = ph,
+ temp3 = pw,
+ temp4 = ph;
+ if(temp1>w) temp1 = w;
+ if(temp2>h) temp2 = h;
+ if(temp3>h) temp3 = h;
+ if(temp4>w) temp4 = w;
+ if(temp1*temp2<temp3*temp4) {
+ tempOrientation = 4;
+ }
+ }
+ if(tempOrientation==4||tempOrientation==5) {
+ int tmp = pw;
+ pw = ph;
+ ph = tmp;
+ }
+ if(w>pw||h>ph) {
+ document_large = 1;
+ }
+
+ if((val = cupsGetOption("print-scaling",num_options,options)) != NULL) {
+ if(!strcasecmp(val,"auto")) {
+ if(fidelity||document_large) {
+ if(margin_defined)
+ zoom = 1.0; // fit method
+ else
+ fillprint = 1; // fill method
+ }
+ else
+ cropfit = 1; // none method
+ }
+ else if(!strcasecmp(val,"auto-fit")) {
+ if(fidelity||document_large)
+ zoom = 1.0; // fit method
+ else
+ cropfit = 1; // none method
+ }
+ else if(!strcasecmp(val,"fill"))
+ fillprint = 1; // fill method
+ else if(!strcasecmp(val,"fit"))
+ zoom = 1.0; // fitplot = 1 or fit method
+ else
+ cropfit=1; // none or crop-to-fit
+ }
+ else{ // print-scaling is not defined, look for alternate options.
+
+ if ((val = cupsGetOption("scaling", num_options, options)) != NULL)
+ zoom = atoi(val) * 0.01;
+ else if (((val =
+ cupsGetOption("fit-to-page", num_options, options)) != NULL) ||
+ ((val = cupsGetOption("fitplot", num_options, options)) != NULL))
+ {
+ if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+ !strcasecmp(val, "true"))
+ zoom = 1.0;
+ else
+ zoom = 0.0;
+ }
+ else if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL)
+ zoom = 0.0;
+
+ if((val = cupsGetOption("fill",num_options,options))!=0) {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes")) {
+ fillprint = 1;
+ }
+ }
+
+ if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes")) {
+ cropfit=1;
+ }
+ } }
+ }
if(fillprint||cropfit)
{
float w = (float)cupsImageGetWidth(img);
@@ -1004,7 +1072,7 @@ main(int argc, /* I - Number of command-line arguments */
float pw = PageRight-PageLeft;
float ph = PageTop-PageBottom;
int tempOrientation = Orientation;
- char *val;
+ const char *val;
int flag = 3;
if((val = cupsGetOption("orientation-requested",num_options,options))!=NULL)
{
diff --git a/filter/imagetoraster.c b/filter/imagetoraster.c
index 5b5674d8f..aaa5ff2ee 100644
--- a/filter/imagetoraster.c
+++ b/filter/imagetoraster.c
@@ -375,39 +375,6 @@ main(int argc, /* I - Number of command-line arguments */
b = 10.0f;
}
- if ((val = cupsGetOption("scaling", num_options, options)) != NULL)
- zoom = atoi(val) * 0.01;
- else if (((val =
- cupsGetOption("fit-to-page", num_options, options)) != NULL) ||
- ((val = cupsGetOption("fitplot", num_options, options)) != NULL))
- {
- if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
- !strcasecmp(val, "true"))
- zoom = 1.0;
- else
- zoom = 0.0;
- }
- else if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL)
- zoom = 0.0;
-
- if((val = cupsGetOption("print-scaling",num_options,options)) !=0) {
- if(!strcasecmp(val,"fill")) {
- fillprint = 1;
- }
- }
- else if((val = cupsGetOption("fill",num_options,options))!=0) {
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
- {
- fillprint = 1;
- }
- }
- if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
- if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
- {
- cropfit=1;
- }
- }
-
if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
{
if (sscanf(val, "%dx%d", &xppi, &yppi) < 2)
@@ -707,6 +674,123 @@ main(int argc, /* I - Number of command-line arguments */
img = cupsImageOpen(filename, primary, secondary, sat, hue, NULL);
else
img = cupsImageOpen(filename, primary, secondary, sat, hue, lut);
+
+ if(img!=NULL){
+
+ int margin_defined = 0;
+ int fidelity = 0;
+ int document_large = 0;
+
+ if(ppd->custom_margins[0]||ppd->custom_margins[1]
+ ||ppd->custom_margins[2]||ppd->custom_margins[3])
+ margin_defined = 1;
+
+ if(PageLength!=PageTop-PageBottom||PageWidth!=PageRight-PageLeft)
+ {
+ margin_defined = 1;
+ }
+
+ if((val = cupsGetOption("ipp-attribute-fidelity",num_options,options)) != NULL)
+ {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes")||
+ !strcasecmp(val,"on"))
+ {
+ fidelity = 1;
+ }
+ }
+
+ float w = (float)cupsImageGetWidth(img);
+ float h = (float)cupsImageGetHeight(img);
+ float pw = PageRight-PageLeft;
+ float ph = PageTop-PageBottom;
+ int tempOrientation = Orientation;
+ if((val = cupsGetOption("orientation-requested",num_options,options))!=NULL)
+ {
+ tempOrientation = atoi(val);
+ }
+ else if((val = cupsGetOption("landscape",num_options,options))!=NULL)
+ {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
+ {
+ tempOrientation = 4;
+ }
+ }
+ if(tempOrientation==0)
+ {
+ if(min(pw,w)*min(ph,h)<min(pw,h)*min(ph,w))
+ {
+ tempOrientation = 4;
+ }
+ }
+ if(tempOrientation==4||tempOrientation==5)
+ {
+ int tmp = pw;
+ pw = ph;
+ ph = tmp;
+ }
+ if(w>pw||h>ph)
+ {
+ document_large = 1;
+ }
+
+ if((val = cupsGetOption("print-scaling",num_options,options)) != NULL)
+ {
+ if(!strcasecmp(val,"auto"))
+ {
+ if(fidelity||document_large)
+ {
+ if(margin_defined)
+ zoom = 1.0; // fit method
+ else
+ fillprint = 1; // fill method
+ }
+ else
+ cropfit = 1; // none method
+ }
+ else if(!strcasecmp(val,"auto-fit"))
+ {
+ if(fidelity||document_large)
+ zoom = 1.0; // fit method
+ else
+ cropfit = 1; // none method
+ }
+ else if(!strcasecmp(val,"fill"))
+ fillprint = 1; // fill method
+ else if(!strcasecmp(val,"fit"))
+ zoom = 1.0; // fitplot = 1 or fit method
+ else
+ cropfit=1; // none or crop-to-fit
+ }
+ else{ // print-scaling is not defined, look for alternate options.
+ if ((val = cupsGetOption("scaling", num_options, options)) != NULL)
+ zoom = atoi(val) * 0.01;
+ else if (((val =
+ cupsGetOption("fit-to-page", num_options, options)) != NULL) ||
+ ((val = cupsGetOption("fitplot", num_options, options)) != NULL))
+ {
+ if (!strcasecmp(val, "yes") || !strcasecmp(val, "on") ||
+ !strcasecmp(val, "true"))
+ zoom = 1.0;
+ else
+ zoom = 0.0;
+ }
+ else if ((val = cupsGetOption("natural-scaling", num_options, options)) != NULL)
+ zoom = 0.0;
+
+ if((val = cupsGetOption("fill",num_options,options))!=0) {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
+ {
+ fillprint = 1;
+ }
+ }
+ if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
+ {
+ cropfit=1;
+ }
+ } }
+ }
+
if(img!=NULL)
{
if(fillprint||cropfit)
@@ -715,7 +799,7 @@ main(int argc, /* I - Number of command-line arguments */
float h = (float)cupsImageGetHeight(img);
float pw = PageRight-PageLeft;
float ph = PageTop-PageBottom;
- char *val;
+ const char *val;
int tempOrientation = Orientation;
int flag =3;
if((val = cupsGetOption("orientation-requested",num_options,options))!=NULL)
diff --git a/filter/mupdftoraster.c b/filter/mupdftoraster.c
index 3af235cb3..8ba7a5743 100644
--- a/filter/mupdftoraster.c
+++ b/filter/mupdftoraster.c
@@ -29,7 +29,7 @@ MIT Open Source License - http://www.opensource.org/
*/
-/* PS/PDF to CUPS Raster filter based on Mutool */
+/* PS/PDF to CUPS Raster filter based on mutool */
#include <config.h>
#include <cups/cups.h>
@@ -118,7 +118,7 @@ parse_pdf_header_options(FILE *fp, mupdf_page_header *h)
static void
add_pdf_header_options(mupdf_page_header *h,
- cups_array_t *mupdf_args)
+ cups_array_t *mupdf_args)
{
char tmpstr[1024];
@@ -158,29 +158,23 @@ add_pdf_header_options(mupdf_page_header *h,
case CUPS_CSPACE_W:
snprintf(tmpstr, sizeof(tmpstr), "-cmono");
break;
- }
+ }
cupsArrayAdd(mupdf_args, strdup(tmpstr));
}
static int
mutool_spawn (const char *filename,
cups_array_t *mupdf_args,
- char **envp,
- FILE *fp,
- int ipfiledes,
- int opfiledes)
+ char **envp)
{
char *argument;
- char buf[BUFSIZ];
char **mutoolargv;
const char* apos;
int i;
- int n;
int numargs;
int pid;
int status = 65536;
int wstatus;
- FILE *tempfp;
/* Put mutool command line argument into an array for the "exec()"
call */
@@ -192,8 +186,8 @@ mutool_spawn (const char *filename,
}
mutoolargv[i] = NULL;
- /* Debug output: Full Mutool command line and environment variables */
- fprintf(stderr, "DEBUG: Mutool command line:");
+ /* Debug output: Full mutool command line and environment variables */
+ fprintf(stderr, "DEBUG: mutool command line:");
for (i = 0; mutoolargv[i]; i ++) {
if ((strchr(mutoolargv[i],' ')) || (strchr(mutoolargv[i],'\t')))
apos = "'";
@@ -206,15 +200,8 @@ mutool_spawn (const char *filename,
for (i = 0; envp[i]; i ++)
fprintf(stderr, "DEBUG: envp[%d]=\"%s\"\n", i, envp[i]);
- /* save the contents for the file to a temporary location */
- tempfp = fdopen(ipfiledes, "wb");
- while ((n = fread(buf, 1, BUFSIZ, fp)) > 0)
- fwrite(buf, 1, n, tempfp);
-
- fclose(tempfp);
-
if ((pid = fork()) == 0) {
- /* Execute Mutool command line ... */
+ /* Execute mutool command line ... */
execvpe(filename, mutoolargv, envp);
perror(filename);
goto out;
@@ -224,24 +211,18 @@ mutool_spawn (const char *filename,
if (waitpid (pid, &wstatus, 0) == -1) {
if (errno == EINTR)
goto retry_wait;
- perror ("gs");
+ perror ("mutool");
goto out;
}
- /* How did Mutool process terminate */
+ /* How did mutool process terminate */
if (WIFEXITED(wstatus))
/* Via exit() anywhere or return() in the main() function */
status = WEXITSTATUS(wstatus);
else if (WIFSIGNALED(wstatus))
/* Via signal */
status = 256 * WTERMSIG(wstatus);
-
- /* write the output to stdout */
- tempfp = fdopen(opfiledes, "rb");
- while ((n = fread(buf, 1, BUFSIZ, tempfp)) > 0)
- fwrite(buf, 1, BUFSIZ, stdout);
-
- fclose(tempfp);
+ fprintf(stderr, "DEBUG: mutool completed, status: %d\n", status);
out:
free(mutoolargv);
@@ -254,16 +235,13 @@ main (int argc, char **argv, char *envp[])
char buf[BUFSIZ];
char *icc_profile = NULL;
char tmpstr[1024];
- char ipfilebuf[20],
- opfilebuf[20];
const char *t = NULL;
cups_array_t *mupdf_args = NULL;
cups_option_t *options = NULL;
FILE *fp = NULL;
+ char infilename[1024];
mupdf_page_header h;
- int fd,
- ipfiledes,
- opfiledes;
+ int fd = -1;
int cm_disabled;
int n;
int num_options;
@@ -302,13 +280,11 @@ main (int argc, char **argv, char *envp[])
if (argc == 6) {
/* stdin */
- fd = cupsTempFd(buf,BUFSIZ);
+ fd = cupsTempFd(infilename, 1024);
if (fd < 0) {
fprintf(stderr, "ERROR: Can't create temporary file\n");
goto out;
}
- /* remove name */
- unlink(buf);
/* copy stdin to the tmp file */
while ((n = read(0,buf,BUFSIZ)) > 0) {
@@ -336,6 +312,7 @@ main (int argc, char **argv, char *envp[])
fprintf(stderr, "ERROR: Can't open input file %s\n",argv[6]);
goto out;
}
+ strncpy(infilename, argv[6], 1024);
}
/* If doc type is not PDF exit */
@@ -352,18 +329,10 @@ main (int argc, char **argv, char *envp[])
if (!cm_disabled)
cmGetPrinterIccProfile(getenv("PRINTER"), &icc_profile, ppd);
- /* Create temporary input and output files */
- memset(ipfilebuf,0,sizeof(ipfilebuf));
- memset(opfilebuf,0,sizeof(opfilebuf));
- strncpy(ipfilebuf,CUPS_IPTEMPFILE,14);
- strncpy(opfilebuf,CUPS_OPTEMPFILE,14);
- ipfiledes = mkstemp(ipfilebuf);
- opfiledes = mkstemp(opfilebuf);
-
- /* Mutool parameters */
+ /* mutool parameters */
mupdf_args = cupsArrayNew(NULL, NULL);
if (!mupdf_args) {
- fprintf(stderr, "ERROR: Unable to allocate memory for Mutool arguments array\n");
+ fprintf(stderr, "ERROR: Unable to allocate memory for mutool arguments array\n");
goto out;
}
@@ -372,11 +341,10 @@ main (int argc, char **argv, char *envp[])
cupsArrayAdd(mupdf_args, strdup(tmpstr));
cupsArrayAdd(mupdf_args, strdup("draw"));
cupsArrayAdd(mupdf_args, strdup("-L"));
- snprintf(tmpstr, sizeof(tmpstr), "-o%s", opfilebuf);
- cupsArrayAdd(mupdf_args, strdup(tmpstr));
+ cupsArrayAdd(mupdf_args, strdup("-o-"));
cupsArrayAdd(mupdf_args, strdup("-smtf"));
- /* Mutool output parameters */
+ /* mutool output parameters */
cupsArrayAdd(mupdf_args, strdup("-Fpwg"));
/* Note that MuPDF only creates PWG Raster and never CUPS Raster,
@@ -431,18 +399,17 @@ main (int argc, char **argv, char *envp[])
h.MirrorPrint = CUPS_FALSE;
h.Orientation = CUPS_ORIENT_0;
- /* get all the data from the header and pass it to Mutool */
+ /* get all the data from the header and pass it to mutool */
add_pdf_header_options (&h, mupdf_args);
- snprintf(tmpstr, sizeof(tmpstr), "%s", ipfilebuf);
+ snprintf(tmpstr, sizeof(tmpstr), "%s", infilename);
cupsArrayAdd(mupdf_args, strdup(tmpstr));
- /* Execute Mutool command line ... */
+ /* Execute mutool command line ... */
snprintf(tmpstr, sizeof(tmpstr), "%s", CUPS_MUTOOL);
/* call mutool */
- rewind(fp);
- status = mutool_spawn (tmpstr, mupdf_args, envp, fp, ipfiledes, opfiledes);
+ status = mutool_spawn (tmpstr, mupdf_args, envp);
if (status != 0) status = 1;
out:
if (fp)
@@ -453,7 +420,7 @@ out:
free(icc_profile);
if (ppd)
ppdClose(ppd);
- unlink(ipfilebuf);
- unlink(opfilebuf);
+ if (fd >= 0)
+ unlink(infilename);
return status;
}
diff --git a/filter/pdftopdf/pdftopdf.cc b/filter/pdftopdf/pdftopdf.cc
index 3b9bb3043..0a299cc65 100644
--- a/filter/pdftopdf/pdftopdf.cc
+++ b/filter/pdftopdf/pdftopdf.cc
@@ -318,6 +318,25 @@ void getParameters(ppd_file_t *ppd,int num_options,cups_option_t *options,Proces
param.numCopies=1;
}
+ if((val = cupsGetOption("ipp-attribute-fidelity",num_options,options))!=NULL) {
+ if(!strcasecmp(val,"true")||!strcasecmp(val,"yes") ||
+ !strcasecmp(val,"on"))
+ param.fidelity = true;
+ }
+
+ if((val = cupsGetOption("print-scaling",num_options,options)) != NULL) {
+ if(!strcasecmp(val,"auto"))
+ param.autoprint = true;
+ else if(!strcasecmp(val,"auto-fit"))
+ param.autofit = true;
+ else if(!strcasecmp(val,"fill"))
+ param.fillprint = true;
+ else if(!strcasecmp(val,"fit"))
+ param.fitplot = true;
+ else
+ param.cropfit = true;
+ }
+ else {
if ((val=cupsGetOption("fitplot",num_options,options)) == NULL) {
if ((val=cupsGetOption("fit-to-page",num_options,options)) == NULL) {
val=cupsGetOption("ipp-attribute-fidelity",num_options,options);
@@ -326,26 +345,19 @@ void getParameters(ppd_file_t *ppd,int num_options,cups_option_t *options,Proces
// TODO? pstops checks =="true", pdftops !is_false ... pstops says: fitplot only for PS (i.e. not for PDF, cmp. cgpdftopdf)
param.fitplot=(val)&&(!is_false(val));
- if((val=cupsGetOption("print-scaling",num_options,options))!=NULL) {
- if(!strcasecmp(val,"fill")) {
- param.fillprint=true;
- }
- }
- else if((val = cupsGetOption("fill",num_options,options))!=0) {
+ if((val = cupsGetOption("fill",num_options,options))!=0) {
if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
{
param.fillprint = true;
}
}
- /*
- * crop-to-fit
- */
if((val = cupsGetOption("crop-to-fit",num_options,options))!= NULL){
if(!strcasecmp(val,"true")||!strcasecmp(val,"yes"))
{
param.cropfit=1;
}
}
+ }
if (ppd && (ppd->landscape < 0)) { // direction the printer rotates landscape (90 or -90)
param.normal_landscape=ROT_270;
diff --git a/filter/pdftopdf/pdftopdf_processor.cc b/filter/pdftopdf/pdftopdf_processor.cc
index 850bddc90..6d2d32ff5 100644
--- a/filter/pdftopdf/pdftopdf_processor.cc
+++ b/filter/pdftopdf/pdftopdf_processor.cc
@@ -175,6 +175,46 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
}
const int numPages=std::max(shuffle.size(),pages.size());
+ if(param.autoprint||param.autofit){
+ bool margin_defined = true;
+ bool document_large = false;
+ int pw = param.page.right-param.page.left;
+ int ph = param.page.top-param.page.bottom;
+ int w=0,h=0;
+ Rotation tempRot=param.orientation;
+ PageRect r= pages[0]->getRect();
+ w = r.width;
+ h = r.height;
+
+ if(tempRot==ROT_90||tempRot==ROT_270)
+ {
+ std::swap(w,h);
+ }
+ if(w>=pw||h>=ph)
+ {
+ document_large = true;
+ }
+ if((param.page.width==pw)&&
+ (param.page.height==ph))
+ margin_defined = false;
+ if(param.autoprint){
+ if(param.fidelity||document_large) {
+ if(margin_defined)
+ param.fitplot = true;
+ else
+ param.fillprint = true;
+ }
+ else
+ param.cropfit = true;
+ }
+ else{
+ if(param.fidelity||document_large)
+ param.fitplot = true;
+ else
+ param.cropfit = true;
+ }
+ }
+
if(param.fillprint||param.cropfit){
fprintf(stderr,"[DEBUG]: Cropping input pdf and Enabling fitplot.\n");
if(param.noOrientation&&pages.size())
@@ -186,7 +226,7 @@ bool processPDFTOPDF(PDFTOPDF_Processor &proc,ProcessingParameters &param) // {{
for(int i=0;i<(int)pages.size();i++)
{
std::shared_ptr<PDFTOPDF_PageHandle> page = pages[i];
- Rotation currRot = page->crop(param.page,param.orientation,param.xpos,param.ypos,!param.cropfit);
+ page->crop(param.page,param.orientation,param.xpos,param.ypos,!param.cropfit);
}
param.fitplot = 1;
}
diff --git a/filter/pdftopdf/pdftopdf_processor.h b/filter/pdftopdf/pdftopdf_processor.h
index b1bbac549..ec7b2997b 100644
--- a/filter/pdftopdf/pdftopdf_processor.h
+++ b/filter/pdftopdf/pdftopdf_processor.h
@@ -16,6 +16,9 @@ ProcessingParameters()
fitplot(false),
fillprint(false), //print-scaling = fill
cropfit(false),
+ autoprint(false),
+ autofit(false),
+ fidelity(false),
noOrientation(false),
orientation(ROT_0),normal_landscape(ROT_270),
paper_is_landscape(false),
@@ -59,6 +62,9 @@ ProcessingParameters()
bool fitplot;
bool fillprint; //print-scaling = fill
bool cropfit; // -o crop-to-fit
+ bool autoprint; // print-scaling = auto
+ bool autofit; // print-scaling = auto-fit
+ bool fidelity;
bool noOrientation;
PageRect page;
Rotation orientation,normal_landscape; // normal_landscape (i.e. default direction) is e.g. needed for number-up=2
diff --git a/filter/pdftops.c b/filter/pdftops.c
index 84b2b6e35..f50ba63da 100644
--- a/filter/pdftops.c
+++ b/filter/pdftops.c
@@ -107,17 +107,6 @@ const char *pstops_exclude_page_management[] = {
/*
- * Options which we do not pass on to the mupdftoraster and rastertops
- * filters when we render via MuPDF
- */
-
-const char *mupdf_exclude_general[] = {
- "Resolution",
- NULL
-};
-
-
-/*
* Check whether we were called after the "pdftopdf" filter and extract
* parameters passed over by "pdftopdf" in the header comments of the PDF
* file
@@ -297,25 +286,16 @@ main(int argc, /* I - Number of command-line args */
need_post_proc = 0, /* Post-processing needed? */
post_proc_pid = 0, /* Process ID of post-processing */
post_proc_pipe[2], /* Pipe to post-processing */
- need_rastertops = 0, /* rastertops (for MuPDF) needed */
- rastertops_pid = 0, /* Process ID of rastertops */
- rastertops_pipe[2], /* Pipe to rastertops */
wait_children, /* Number of child processes left */
wait_pid, /* Process ID from wait() */
wait_status, /* Status from child */
exit_status = 0; /* Exit status */
+ int gray_output = 0; /* Checking for monochrome/grayscale PostScript output */
char *pdf_argv[100], /* Arguments for pdftops/gs */
pstops_path[1024], /* Path to pstops program */
*pstops_argv[7], /* Arguments for pstops filter */
*pstops_options, /* Options for pstops filter */
*pstops_end, /* End of pstops filter option */
- rastertops_path[1024], /* Path to rastertops program */
- *rastertops_argv[7], /* Arguments for rastertops filter */
- mupdftoraster_path[1024], /* Path to mupdftoraster program */
- *mupdf_options, /* Options for mupdftoraster and
- rastertops filters */
- *mupdf_end, /* End of mupdftoraster and rastertops
- filter option */
*ptr; /* Pointer into value */
const char *cups_serverbin; /* CUPS_SERVERBIN environment
variable */
@@ -559,36 +539,43 @@ main(int argc, /* I - Number of command-line args */
log_command_line("pstops", pstops_argv);
/*
- * Build the rastertops command-line (MuPDF only)...
+ * Force monochrome/grayscale PostScript output
+ * if job is to be printed in monochrome/grayscale
*/
-
- if (renderer == MUPDF)
+ if (ppd->color_device == 0) /* Monochrome printer */
+ gray_output = 1;
+ else /*Color Printer - user option for Grayscale */
{
- if ((cups_serverbin = getenv("CUPS_SERVERBIN")) == NULL)
- cups_serverbin = CUPS_SERVERBIN;
-
- snprintf(rastertops_path, sizeof(rastertops_path), "%s/filter/rastertops",
- cups_serverbin);
-
- mupdf_options = strdup(argv[5]);
- remove_options(mupdf_options, mupdf_exclude_general);
-
- rastertops_argv[0] = argv[0]; /* Printer */
- rastertops_argv[1] = argv[1]; /* Job */
- rastertops_argv[2] = argv[2]; /* User */
- rastertops_argv[3] = argv[3]; /* Title */
- if (pdftopdfapplied)
- rastertops_argv[4] = deviceCopies; /* Copies */
- else
- rastertops_argv[4] = argv[4]; /* Copies */
- rastertops_argv[5] = mupdf_options; /* Options */
- rastertops_argv[6] = NULL;
-
- log_command_line("rastertops", rastertops_argv);
+ if ((val = cupsGetOption("pwg-raster-document-type", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("PwgRasterDocumentType", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("print-color-mode", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("PrintColorMode", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("color-space", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("ColorSpace", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("color-model", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("ColorModel", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("output-mode", num_options,
+ options)) != NULL ||
+ (val = cupsGetOption("OutputMode", num_options,
+ options)) != NULL)
+ {
+ if (strcasestr(val, "Black") ||
+ strcasestr(val, "Gray") ||
+ strcasestr(val, "Mono"))
+ gray_output = 1;
+ }
}
/*
- * Build the command-line for the pdftops, gs, pdftocairo, or
+ * Build the command-line for the pdftops, gs, mutool, pdftocairo, or
* acroread filter...
*/
@@ -612,7 +599,29 @@ main(int argc, /* I - Number of command-line args */
# endif /* HAVE_GHOSTSCRIPT_PS2WRITE */
pdf_argv[7] = (char *)"-dShowAcroForm";
pdf_argv[8] = (char *)"-sOUTPUTFILE=%stdout";
- pdf_argc = 9;
+ if (gray_output == 1) /* Checking for monochrome/grayscale PostScript
+ output */
+ {
+ pdf_argv[9] = (char *)"-sColorConversionStrategy=Gray";
+ pdf_argc = 10;
+ }
+ else
+ pdf_argc = 9;
+ }
+ else if (renderer == MUPDF)
+ {
+ pdf_argv[0] = (char *)"mutool";
+ pdf_argv[1] = (char *)"draw";
+ pdf_argv[2] = (char *)"-L";
+ pdf_argv[3] = (char *)"-smtf";
+ pdf_argv[4] = (char *)"-Fps";
+ pdf_argv[5] = (char *)"-o-";
+ if (gray_output == 1) /* Checking for monochrome/grayscale PostScript
+ output */
+ pdf_argv[6] = (char *)"-cgray";
+ else
+ pdf_argv[6] = (char *)"-crgb";
+ pdf_argc = 7;
}
else if (renderer == PDFTOCAIRO)
{
@@ -626,23 +635,6 @@ main(int argc, /* I - Number of command-line args */
pdf_argv[1] = (char *)"-toPostScript";
pdf_argc = 2;
}
- else if (renderer == MUPDF)
- {
- snprintf(mupdftoraster_path, sizeof(mupdftoraster_path),
- "%s/filter/mupdftoraster", cups_serverbin);
- pdf_argv[0] = "mupdftoraster";
- pdf_argv[1] = argv[1]; /* Job */
- pdf_argv[2] = argv[2]; /* User */
- pdf_argv[3] = argv[3]; /* Title */
- if (pdftopdfapplied)
- pdf_argv[4] = deviceCopies; /* Copies */
- else
- pdf_argv[4] = argv[4]; /* Copies */
- pdf_argv[5] = mupdf_options; /* Options */
- pdf_argv[6] = filename;
- pdf_argv[7] = NULL;
- pdf_argc = 8;
- }
/*
* Set language level and TrueType font handling...
@@ -660,11 +652,11 @@ main(int argc, /* I - Number of command-line args */
else if (renderer == GS)
pdf_argv[pdf_argc++] = (char *)"-dLanguageLevel=1";
else if (renderer == PDFTOCAIRO)
- fprintf(stderr, "WARNING: Level 1 PostScript not supported by pdftocairo.");
+ fprintf(stderr, "WARNING: Level 1 PostScript not supported by pdftocairo.\n");
else if (renderer == ACROREAD)
- fprintf(stderr, "WARNING: Level 1 PostScript not supported by acroread.");
+ fprintf(stderr, "WARNING: Level 1 PostScript not supported by acroread.\n");
else if (renderer == MUPDF)
- fprintf(stderr, "WARNING: Level 1 PostScript not supported by rastertops.");
+ fprintf(stderr, "WARNING: Level 1 PostScript not supported by mutool.\n");
}
else if (ppd->language_level == 2)
{
@@ -676,7 +668,8 @@ main(int argc, /* I - Number of command-line args */
}
else if (renderer == GS)
pdf_argv[pdf_argc++] = (char *)"-dLanguageLevel=2";
- else /* PDFTOCAIRO || ACROREAD */
+ else if (renderer != MUPDF) /* MuPDF is PS level 2 only */
+ /* PDFTOCAIRO, ACROREAD */
pdf_argv[pdf_argc++] = (char *)"-level2";
}
else
@@ -708,6 +701,8 @@ main(int argc, /* I - Number of command-line args */
else
pdf_argv[pdf_argc++] = (char *)"-dLanguageLevel=3";
}
+ else if (renderer == MUPDF)
+ fprintf(stderr, "WARNING: Level 3 PostScript not supported by mutool.\n");
else /* PDFTOCAIRO || ACROREAD */
pdf_argv[pdf_argc++] = (char *)"-level3";
}
@@ -730,7 +725,8 @@ main(int argc, /* I - Number of command-line args */
}
else if (renderer == GS)
pdf_argv[pdf_argc++] = (char *)"-dLanguageLevel=3";
- else /* PDFTOCAIRO || ACROREAD */
+ else if (renderer != MUPDF) /* MuPDF is PS level 2 only */
+ /* PDFTOCAIRO || ACROREAD */
pdf_argv[pdf_argc++] = (char *)"-level3";
}
@@ -863,6 +859,11 @@ main(int argc, /* I - Number of command-line args */
pdf_argv[pdf_argc++] = resolution;
fprintf(stderr, "DEBUG: Using image rendering resolution %d dpi\n", res);
#endif /* HAVE_POPPLER_PDFTOPS_WITH_RESOLUTION */
+ if (gray_output == 1) /* Checking for monochrome/grayscale PostScript output */
+ {
+ pdf_argv[1] = (char *)"-level1";
+ pdf_argv[pdf_argc++] = (char *)"-optimizecolorspace";
+ }
pdf_argv[pdf_argc++] = filename;
pdf_argv[pdf_argc++] = (char *)"-";
}
@@ -936,15 +937,12 @@ main(int argc, /* I - Number of command-line args */
* Add Resolution option to avoid slow processing by the printer when the
* resolution of embedded images does not match the printer's resolution
*/
- mupdf_options = realloc(mupdf_options, strlen(mupdf_options) + 30);
- if (!mupdf_options) {
- fprintf(stderr, "ERROR: Can't allocate mupdf_options\n");
- exit(2);
- }
- mupdf_end = mupdf_options + strlen(mupdf_options);
- snprintf(mupdf_end, 30, " Resolution=%ddpi", res);
- pdf_argv[5] = mupdf_options;
- rastertops_argv[5] = mupdf_options;
+ snprintf(resolution, 127, "-r%dx%d", res, res);
+ pdf_argv[pdf_argc++] = resolution;
+ /*
+ * Add input file name
+ */
+ pdf_argv[pdf_argc++] = filename;
}
pdf_argv[pdf_argc] = NULL;
@@ -977,16 +975,7 @@ main(int argc, /* I - Number of command-line args */
need_post_proc = 1;
/*
- * Do we need to run rastertops when we are using mupdftoraster as PDF
- * renderer
- */
-
- if (renderer == MUPDF)
- need_rastertops = 1;
-
- /*
- * Execute "pdftops/gs/mupdftoraster [ | rastertops ] [ | PS post-processing ]
- * | pstops"...
+ * Execute "pdftops/gs/mutool [ | PS post-processing ] | pstops"...
*/
@@ -1003,17 +992,6 @@ main(int argc, /* I - Number of command-line args */
goto error;
}
- if (need_rastertops)
- {
- if (pipe(rastertops_pipe))
- {
- perror("DEBUG: Unable to create pipe for rastertops");
-
- exit_status = 1;
- goto error;
- }
- }
-
if (need_post_proc)
{
if (pipe(post_proc_pipe))
@@ -1031,18 +1009,7 @@ main(int argc, /* I - Number of command-line args */
* Child comes here...
*/
- if (need_rastertops)
- {
- dup2(rastertops_pipe[1], 1);
- close(rastertops_pipe[0]);
- close(rastertops_pipe[1]);
- if (need_post_proc)
- {
- close(post_proc_pipe[0]);
- close(post_proc_pipe[1]);
- }
- }
- else if (need_post_proc)
+ if (need_post_proc)
{
dup2(post_proc_pipe[1], 1);
close(post_proc_pipe[0]);
@@ -1085,8 +1052,8 @@ main(int argc, /* I - Number of command-line args */
}
else if (renderer == MUPDF)
{
- execvp(mupdftoraster_path, pdf_argv);
- perror("DEBUG: Unable to execute mupdftoraster program");
+ execvp(CUPS_MUTOOL, pdf_argv);
+ perror("DEBUG: Unable to execute mutool program");
}
exit(1);
@@ -1106,7 +1073,7 @@ main(int argc, /* I - Number of command-line args */
else if (renderer == ACROREAD)
perror("DEBUG: Unable to execute acroread program");
else if (renderer == MUPDF)
- perror("DEBUG: Unable to execute mupdftoraster program");
+ perror("DEBUG: Unable to execute mutool program");
exit_status = 1;
goto error;
@@ -1114,47 +1081,6 @@ main(int argc, /* I - Number of command-line args */
fprintf(stderr, "DEBUG: Started filter %s (PID %d)\n", pdf_argv[0], pdf_pid);
- if (need_rastertops)
- {
- if ((rastertops_pid = fork()) == 0)
- {
- /*
- * Child comes here...
- */
-
- dup2(rastertops_pipe[0], 0);
- close(rastertops_pipe[0]);
- close(rastertops_pipe[1]);
- if (need_post_proc)
- {
- dup2(post_proc_pipe[1], 1);
- close(post_proc_pipe[0]);
- close(post_proc_pipe[1]);
- }
- else
- dup2(pstops_pipe[1], 1);
- close(pstops_pipe[0]);
- close(pstops_pipe[1]);
-
- execvp(rastertops_path, rastertops_argv);
- perror("DEBUG: Unable to execute rastertops program");
- }
- else if (post_proc_pid < 0)
- {
- /*
- * Unable to fork!
- */
-
- perror("DEBUG: Unable to execute rastertops program");
-
- exit_status = 1;
- goto error;
- }
-
- fprintf(stderr, "DEBUG: Started filter rastertops (PID %d)\n",
- rastertops_pid);
- }
-
if (need_post_proc)
{
if ((post_proc_pid = fork()) == 0)
@@ -1169,11 +1095,6 @@ main(int argc, /* I - Number of command-line args */
dup2(pstops_pipe[1], 1);
close(pstops_pipe[0]);
close(pstops_pipe[1]);
- if (need_rastertops)
- {
- close(rastertops_pipe[0]);
- close(rastertops_pipe[1]);
- }
fp = cupsFileStdin();
@@ -1500,11 +1421,6 @@ main(int argc, /* I - Number of command-line args */
dup2(pstops_pipe[0], 0);
close(pstops_pipe[0]);
close(pstops_pipe[1]);
- if (need_rastertops)
- {
- close(rastertops_pipe[0]);
- close(rastertops_pipe[1]);
- }
if (need_post_proc)
{
close(post_proc_pipe[0]);
@@ -1537,17 +1453,12 @@ main(int argc, /* I - Number of command-line args */
close(post_proc_pipe[0]);
close(post_proc_pipe[1]);
}
- if (need_rastertops)
- {
- close(rastertops_pipe[0]);
- close(rastertops_pipe[1]);
- }
/*
* Wait for the child processes to exit...
*/
- wait_children = 2 + need_rastertops + need_post_proc;
+ wait_children = 2 + need_post_proc;
while (wait_children > 0)
{
@@ -1560,8 +1471,6 @@ main(int argc, /* I - Number of command-line args */
if (job_canceled)
{
kill(pdf_pid, SIGTERM);
- if (need_rastertops)
- kill(rastertops_pid, SIGTERM);
if (need_post_proc)
kill(post_proc_pid, SIGTERM);
kill(pstops_pid, SIGTERM);
@@ -1592,12 +1501,11 @@ main(int argc, /* I - Number of command-line args */
(renderer == PDFTOCAIRO ? "pdftocairo" :
(renderer == GS ? "gs" :
(renderer == ACROREAD ? "acroread" :
- (renderer == MUPDF ? "mupdftoraster" :
+ (renderer == MUPDF ? "mutool" :
"Unknown renderer"))))) :
(wait_pid == pstops_pid ? "pstops" :
- (wait_pid == rastertops_pid ? "rastertops" :
(wait_pid == post_proc_pid ? "Post-processing" :
- "Unknown process"))),
+ "Unknown process")),
exit_status);
}
else if (WTERMSIG(wait_status) == SIGTERM)
@@ -1610,12 +1518,11 @@ main(int argc, /* I - Number of command-line args */
(renderer == PDFTOCAIRO ? "pdftocairo" :
(renderer == GS ? "gs" :
(renderer == ACROREAD ? "acroread" :
- (renderer == MUPDF ? "mupdftoraster" :
+ (renderer == MUPDF ? "mutool" :
"Unknown renderer"))))) :
(wait_pid == pstops_pid ? "pstops" :
- (wait_pid == rastertops_pid ? "rastertops" :
(wait_pid == post_proc_pid ? "Post-processing" :
- "Unknown process"))),
+ "Unknown process")),
exit_status);
}
else
@@ -1629,12 +1536,11 @@ main(int argc, /* I - Number of command-line args */
(renderer == PDFTOCAIRO ? "pdftocairo" :
(renderer == GS ? "gs" :
(renderer == ACROREAD ? "acroread" :
- (renderer == MUPDF ? "mupdftoraster" :
+ (renderer == MUPDF ? "mutool" :
"Unknown renderer"))))) :
(wait_pid == pstops_pid ? "pstops" :
- (wait_pid == rastertops_pid ? "rastertops" :
(wait_pid == post_proc_pid ? "Post-processing" :
- "Unknown process"))),
+ "Unknown process")),
exit_status);
}
}
@@ -1647,12 +1553,11 @@ main(int argc, /* I - Number of command-line args */
(renderer == PDFTOCAIRO ? "pdftocairo" :
(renderer == GS ? "gs" :
(renderer == ACROREAD ? "acroread" :
- (renderer == MUPDF ? "mupdftoraster" :
+ (renderer == MUPDF ? "mutool" :
"Unknown renderer"))))) :
(wait_pid == pstops_pid ? "pstops" :
- (wait_pid == rastertops_pid ? "rastertops" :
(wait_pid == post_proc_pid ? "Post-processing" :
- "Unknown process"))));
+ "Unknown process")));
}
}
diff --git a/filter/rastertops.c b/filter/rastertops.c
index 531eb7091..3d825a5da 100644
--- a/filter/rastertops.c
+++ b/filter/rastertops.c
@@ -44,14 +44,13 @@
*/
void
-writeProlog(cups_cspace_t mode, /* I - Color mode (gray or color) */
- int width, /* I - width of the image in pixels */
- int height) /* I - height of the image in pixels */
+writeProlog(int width, /* I - width of the image in points */
+ int height) /* I - height of the image in points */
{
/* Document header... */
printf("%%!PS-Adobe-3.0\n");
printf("%%%%BoundingBox: %d %d %d %d\n", 0, 0, width, height);
- printf("%%%%Creator: Cups-Filters\n");
+ printf("%%%%Creator: cups-filters\n");
printf("%%%%LanguageLevel: 2\n");
printf("%%%%DocumentData: Clean7Bit\n");
printf("%%%%Pages: (atend)\n");
@@ -100,11 +99,13 @@ find_bits(cups_cspace_t mode, /* I - Color space of data */
* 'writeImage()' - Write the information regarding the image
*/
-void /* O - Exit status */
-writeImage(int bpc, /* I - bits per color */
- int width, /* I - width of image */
- int height, /* I - height of image */
- cups_cspace_t mode) /* I - color model of image */
+void /* O - Exit status */
+writeImage(int pagewidth, /* I - width of page in points */
+ int pageheight, /* I - height of page in points */
+ int bpc, /* I - bits per color */
+ int pixwidth, /* I - width of image in pixels */
+ int pixheight, /* I - height of image in pixels */
+ cups_cspace_t mode) /* I - color model of image */
{
printf("gsave\n");
@@ -131,12 +132,12 @@ writeImage(int bpc, /* I - bits per color */
if (bpc == 16)
printf("/Input currentfile /FlateDecode filter def\n");
- printf("%d %d scale\n",width, height);
+ printf("%d %d scale\n", pagewidth, pageheight);
printf("<< \n"
"/ImageType 1\n"
"/Width %d\n"
"/Height %d\n"
- "/BitsPerComponent %d\n", width, height, find_bits(mode, bpc));
+ "/BitsPerComponent %d\n", pixwidth, pixheight, find_bits(mode, bpc));
switch (mode)
{
@@ -168,7 +169,7 @@ writeImage(int bpc, /* I - bits per color */
else
printf("/DataSource currentfile /FlateDecode filter\n");
- printf("/ImageMatrix [%d 0 0 %d 0 %d]\n", width, -1*height, height);
+ printf("/ImageMatrix [%d 0 0 %d 0 %d]\n", pixwidth, -1*pixheight, pixheight);
printf(">> image\n");
}
@@ -453,7 +454,7 @@ main(int argc, /* I - Number of command-line arguments */
if (!count)
{
count++;
- writeProlog(header.cupsColorSpace, header.cupsWidth, header.cupsHeight);
+ writeProlog(header.PageSize[0], header.PageSize[1]);
}
/*
@@ -469,12 +470,14 @@ main(int argc, /* I - Number of command-line arguments */
/*
* Write the starting of the page
*/
- writeStartPage(Page, header.cupsWidth, header.cupsHeight);
+ writeStartPage(Page, header.PageSize[0], header.PageSize[1]);
/*
* write the information regarding the image
*/
- writeImage(header.cupsBitsPerColor, header.cupsWidth, header.cupsHeight,
+ writeImage(header.PageSize[0], header.PageSize[1],
+ header.cupsBitsPerColor,
+ header.cupsWidth, header.cupsHeight,
header.cupsColorSpace);
/* Write the compressed image data*/