diff options
author | Till Kamppeter <till.kamppeter@gmail.com> | 2020-08-27 10:22:00 +0200 |
---|---|---|
committer | Didier Raboud <odyx@debian.org> | 2020-10-23 11:14:29 +0200 |
commit | e548cefce787510694ba297860427d666fb81be8 (patch) | |
tree | 520cfddf6ffac0414c94050eda754901c8c5e88d | |
parent | 9c1db9cb884794efde6d2b687e370e1e07680793 (diff) |
Let the rastertopwg filter check rounding errors when calculating the page geometry
-rw-r--r-- | filter/rastertopwg.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/filter/rastertopwg.c b/filter/rastertopwg.c index 1e63e4ec0..bffd89a1f 100644 --- a/filter/rastertopwg.c +++ b/filter/rastertopwg.c @@ -41,8 +41,10 @@ main(int argc, /* I - Number of command-line args */ page_top, /* Top margin */ page_bottom, /* Bottom margin */ page_left, /* Left margin */ + page_right, /* Right margin */ linesize, /* Bytes per line */ lineoffset; /* Offset into line */ + int tmp; unsigned char white; /* White pixel */ ppd_file_t *ppd; /* PPD file */ ppd_attr_t *back; /* cupsBackSide attribute */ @@ -120,14 +122,30 @@ main(int argc, /* I - Number of command-line args */ fprintf(stderr, "PAGE: %d %d\n", page, inheader.NumCopies); page_width = (unsigned)(inheader.cupsPageSize[0] * inheader.HWResolution[0] / 72.0); + if (page_width < inheader.cupsWidth && + page_width >= inheader.cupsWidth - 2) + page_width = (unsigned)inheader.cupsWidth; page_height = (unsigned)(inheader.cupsPageSize[1] * inheader.HWResolution[1] / 72.0); + if (page_height < inheader.cupsHeight && + page_height >= inheader.cupsHeight - 2) + page_height = (unsigned)inheader.cupsHeight; page_left = (unsigned)(inheader.cupsImagingBBox[0] * inheader.HWResolution[0] / 72.0); page_bottom = (unsigned)(inheader.cupsImagingBBox[1] * inheader.HWResolution[1] / 72.0); - page_top = page_height - page_bottom - inheader.cupsHeight; + tmp = (int)(page_height - page_bottom - inheader.cupsHeight); + if (tmp < 0 && tmp >= -2) /* Rounding error */ + page_top = 0; + else + page_top = (unsigned)tmp; + tmp = (int)(page_width - page_left - inheader.cupsWidth); + if (tmp < 0 && tmp >= -2) /* Rounding error */ + page_right = 0; + else + page_right = (unsigned)tmp; linesize = (page_width * inheader.cupsBitsPerPixel + 7) / 8; lineoffset = page_left * inheader.cupsBitsPerPixel / 8; /* Round down */ - if (page_left > page_width || page_top > page_height || page_bottom > page_height) + fprintf(stderr, "DEBUG: In pixels: Width: %u Height: %u Left: %u Right: %u Top: %u Bottom: %u\n", page_width, page_height, page_left, page_right, page_top, page_bottom); + if (page_left > page_width || page_top > page_height || page_bottom > page_height || page_right > page_width) { _cupsLangPrintFilter(stderr, "ERROR", _("Unsupported raster data.")); fprintf(stderr, "DEBUG: Bad bottom/left/top margin on page %d.\n", page); @@ -291,8 +309,7 @@ main(int argc, /* I - Number of command-line args */ outheader.cupsInteger[1] = ~0U;/* CrossFeedTransform */ outheader.cupsInteger[2] = 1; /* FeedTransform */ - outheader.cupsInteger[3] = page_width - page_left - - inheader.cupsWidth; + outheader.cupsInteger[3] = page_right; /* ImageBoxLeft */ outheader.cupsInteger[4] = page_top; /* ImageBoxTop */ @@ -355,8 +372,7 @@ main(int argc, /* I - Number of command-line args */ outheader.cupsInteger[1] = ~0U;/* CrossFeedTransform */ outheader.cupsInteger[2] = ~0U;/* FeedTransform */ - outheader.cupsInteger[3] = page_width - page_left - - inheader.cupsWidth; + outheader.cupsInteger[3] = page_right; /* ImageBoxLeft */ outheader.cupsInteger[4] = page_bottom; /* ImageBoxTop */ |