}
if(fillprint||cropfit)
{
+ /* For cropfit do the math without the unprintable margins to get correct
+ centering */
+ if (cropfit)
+ {
+ PageBottom = 0.0;
+ PageTop = PageLength;
+ PageLeft = 0.0;
+ PageRight = PageWidth;
+ }
float w = (float)cupsImageGetWidth(img);
float h = (float)cupsImageGetHeight(img);
float pw = PageRight-PageLeft;
img = img2;
if(flag==4)
{
- PageBottom += (PageTop - PageBottom -
- final_w * 72.0 / img->xppi) / 2;
- PageTop = PageBottom +
- final_w * 72.0 / img->xppi;
- PageLeft += (PageRight - PageLeft -
- final_h * 72.0 / img->yppi) / 2;
- PageRight = PageLeft +
- final_h * 72.0 / img->yppi;
+ PageBottom += (PageLength - final_w * 72.0 / img->xppi) / 2;
+ PageTop = PageBottom + final_w * 72.0 / img->xppi;
+ PageLeft += (PageWidth - final_h * 72.0 / img->yppi) / 2;
+ PageRight = PageLeft + final_h * 72.0 / img->yppi;
}
else
{
- PageBottom += (PageTop - PageBottom -
- final_h * 72.0 / img->yppi) / 2;
- PageTop = PageBottom +
- final_h * 72.0 / img->yppi;
- PageLeft += (PageRight - PageLeft -
- final_w * 72.0 / img->xppi) / 2;
- PageRight = PageLeft +
- final_w * 72.0 / img->xppi;
+ PageBottom += (PageLength - final_h * 72.0 / img->yppi) / 2;
+ PageTop = PageBottom + final_h * 72.0 / img->yppi;
+ PageLeft += (PageWidth - final_w * 72.0 / img->xppi) / 2;
+ PageRight = PageLeft + final_w * 72.0 / img->xppi;
}
if(PageBottom<0) PageBottom = 0;
if(PageLeft<0) PageLeft = 0;
{
float w = (float)cupsImageGetWidth(img);
float h = (float)cupsImageGetHeight(img);
- float pw = PageRight-PageLeft;
- float ph = PageTop-PageBottom;
+ /* For cropfit do the math without the unprintable margins to get correct
+ centering, for fillprint, fill the printable area */
+ float pw = (cropfit ? PageWidth : PageRight-PageLeft);
+ float ph = (cropfit ? PageLength : PageTop-PageBottom);
const char *val;
int tempOrientation = Orientation;
int flag =3;
if (h > ph * img->yppi / 72.0)
final_h = ph * img->yppi / 72.0;
float posw=(w-final_w)/2,posh=(h-final_h)/2;
- posw = (1+XPosition)*posw;
+ posw = (1+XPosition)*posw;
posh = (1-YPosition)*posh;
- cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h);
- cupsImageClose(img);
- img = img2;
+ /* Check whether the unprintable margins hide away a part of the image,
+ if so, correct the image cut */
if(flag==4)
- {
- PageBottom += (PageTop - PageBottom -
- final_w * 72.0 / img->xppi) / 2;
- PageTop = PageBottom +
- final_w * 72.0 / img->xppi;
- PageLeft += (PageRight - PageLeft -
- final_h * 72.0 / img->yppi) / 2;
- PageRight = PageLeft +
- final_h * 72.0 / img->yppi;
+ {
+ float margin, cutoff;
+ margin = (PageLength - final_w * 72.0 / img->xppi) / 2;
+ if (margin >= PageBottom)
+ PageBottom = margin;
+ else
+ {
+ cutoff = (PageBottom - margin) * img->xppi / 72.0;
+ final_w -= cutoff;
+ posw += cutoff;
+ }
+ margin = PageBottom + final_w * 72.0 / img->xppi;
+ if (margin <= PageTop)
+ PageTop = margin;
+ else
+ final_w -= (margin - PageTop) * img->xppi / 72.0;
+ margin = (PageWidth - final_h * 72.0 / img->yppi) / 2;
+ if (margin >= PageLeft)
+ PageLeft = margin;
+ else
+ {
+ cutoff = (PageLeft - margin) * img->yppi / 72.0;
+ final_h -= cutoff;
+ posh += cutoff;
+ }
+ margin = PageLeft + final_h * 72.0 / img->yppi;
+ if (margin <= PageRight)
+ PageRight = margin;
+ else
+ final_h -= (margin - PageRight) * img->yppi / 72.0;
}
else
{
- PageBottom += (PageTop - PageBottom -
- final_h * 72.0 / img->yppi) / 2;
- PageTop = PageBottom +
- final_h * 72.0 / img->yppi;
- PageLeft += (PageRight - PageLeft -
- final_w * 72.0 / img->xppi) / 2;
- PageRight = PageLeft +
- final_w * 72.0 / img->xppi;
+ float margin, cutoff;
+ margin = (PageLength - final_h * 72.0 / img->yppi) / 2;
+ if (margin >= PageBottom)
+ PageBottom = margin;
+ else
+ {
+ cutoff = (PageBottom - margin) * img->yppi / 72.0;
+ final_h -= cutoff;
+ posh += cutoff;
+ }
+ margin = PageBottom + final_h * 72.0 / img->yppi;
+ if (margin <= PageTop)
+ PageTop = margin;
+ else
+ final_h -= (margin - PageTop) * img->yppi / 72.0;
+ margin = (PageWidth - final_w * 72.0 / img->xppi) / 2;
+ if (margin >= PageLeft)
+ PageLeft = margin;
+ else
+ {
+ cutoff = (PageLeft - margin) * img->xppi / 72.0;
+ final_w -= cutoff;
+ posw += cutoff;
+ }
+ margin = PageLeft + final_w * 72.0 / img->xppi;
+ if (margin <= PageRight)
+ PageRight = margin;
+ else
+ final_w -= (margin - PageRight) * img->xppi / 72.0;
}
if(PageBottom<0) PageBottom = 0;
if(PageLeft<0) PageLeft = 0;
+ cups_image_t *img2 = cupsImageCrop(img,posw,posh,final_w,final_h);
+ cupsImageClose(img);
+ img = img2;
}
}
}