Support for print-scaling feature has been added to imagetoraster,imagetopdf and pdftopdf filters.
}
}
- /*
- * 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;
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)
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;
+ int flag =3;
+ 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);
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)
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)
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);
// 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;
}
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())
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),
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