From 841533481464ea4cad3dcb8c6dd636c5d455e6eb Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Tue, 6 Dec 2011 15:46:44 +0000 Subject: Remove dead (duplicated) code from pdf_fontfile.c 2 if clauses were (harmlessly) duplicated in pdf_find_builtin_font, probably due to an automated code merge (or other cut/paste error). --- pdf/pdf_fontfile.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pdf/pdf_fontfile.c b/pdf/pdf_fontfile.c index fb85bee4..543ce763 100644 --- a/pdf/pdf_fontfile.c +++ b/pdf/pdf_fontfile.c @@ -18,14 +18,6 @@ unsigned char * pdf_find_builtin_font(char *name, unsigned int *len) { - if (!strcmp("Courier", name)) { - *len = sizeof pdf_font_NimbusMonL_Regu; - return (unsigned char*) pdf_font_NimbusMonL_Regu; - } - if (!strcmp("Courier-Bold", name)) { - *len = sizeof pdf_font_NimbusMonL_Bold; - return (unsigned char*) pdf_font_NimbusMonL_Bold; - } if (!strcmp("Courier", name)) { *len = sizeof pdf_font_NimbusMonL_Regu; return (unsigned char*) pdf_font_NimbusMonL_Regu; -- cgit v1.2.3 From 7a6b60d0ec1abac316917690878011c3228a6fb7 Mon Sep 17 00:00:00 2001 From: Robin Watts Date: Wed, 7 Dec 2011 17:58:00 +0000 Subject: Fix tile coverage calculations. The code attempts to spot cases where a pattern tile is so large that only 1 repeat is visible. Due to rounding errors, this test could sometimes fail, and (on badly formed files) we'd attempt to allocate huge pixmaps. The fix is to allow for rounding errors. --- draw/draw_device.c | 5 +++++ pdf/pdf_interpret.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/draw/draw_device.c b/draw/draw_device.c index 165cb1a9..788d8148 100644 --- a/draw/draw_device.c +++ b/draw/draw_device.c @@ -1438,6 +1438,11 @@ fz_draw_begin_tile(void *user, fz_rect area, fz_rect view, float xstep, float ys fz_knockout_begin(dev); bbox = fz_round_rect(fz_transform_rect(ctm, view)); + /* We should never have a bbox that entirely covers our destination. + * If we do, then the check for only 1 tile being visible above has + * failed. */ + assert(bbox.x0 > dev->dest->x || bbox.x1 < dev->dest->x + dev->dest->w || + bbox.y0 > dev->dest->y || bbox.y1 < dev->dest->y + dev->dest->h); dest = fz_new_pixmap_with_rect(model, bbox); /* FIXME: See note #1 */ fz_clear_pixmap(dest); diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index 55e66e61..f598e9fb 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -1151,10 +1151,15 @@ pdf_show_pattern(pdf_csi *csi, pdf_pattern *pat, fz_rect area, int what) /* patterns are painted using the ctm in effect at the beginning of the content stream */ /* get bbox of shape in pattern space for stamping */ area = fz_transform_rect(invptm, area); - x0 = floorf(area.x0 / pat->xstep); - y0 = floorf(area.y0 / pat->ystep); - x1 = ceilf(area.x1 / pat->xstep); - y1 = ceilf(area.y1 / pat->ystep); + + /* When calculating the number of tiles required, we adjust by a small + * amount to allow for rounding errors. By choosing this amount to be + * smaller than 1/256, we guarantee we won't cause problems that will + * be visible even under our most extreme antialiasing. */ + x0 = floorf(area.x0 / pat->xstep + 0.001); + y0 = floorf(area.y0 / pat->ystep + 0.001); + x1 = ceilf(area.x1 / pat->xstep - 0.001); + y1 = ceilf(area.y1 / pat->ystep - 0.001); oldtopctm = csi->top_ctm; oldtop = csi->gtop; -- cgit v1.2.3 From 164ae7a63b56da5a1a2cf63701583753aa433762 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Dec 2011 22:28:31 +0100 Subject: Undo pre-multiplied alpha when saving PNG with alpha channels. --- apps/pdfdraw.c | 3 +++ fitz/fitz.h | 1 + fitz/res_pixmap.c | 20 ++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index d79cd75c..9ad2b56c 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -189,6 +189,9 @@ static void drawpage(pdf_xref *xref, int pagenum) if (gamma_value != 1) fz_gamma_pixmap(pix, gamma_value); + if (savealpha) + fz_unmultiply_pixmap(pix); + if (output) { char buf[512]; diff --git a/fitz/fitz.h b/fitz/fitz.h index ccaa98b8..d0054f3e 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -626,6 +626,7 @@ void fz_clear_pixmap_with_color(fz_pixmap *pix, int value); void fz_clear_pixmap_rect_with_color(fz_pixmap *pix, int value, fz_bbox r); void fz_copy_pixmap_rect(fz_pixmap *dest, fz_pixmap *src, fz_bbox r); void fz_premultiply_pixmap(fz_pixmap *pix); +void fz_unmultiply_pixmap(fz_pixmap *pix); fz_pixmap *fz_alpha_from_gray(fz_pixmap *gray, int luminosity); fz_bbox fz_bound_pixmap(fz_pixmap *pix); void fz_invert_pixmap(fz_pixmap *pix); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 83f46526..b1f151c3 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -226,6 +226,26 @@ fz_premultiply_pixmap(fz_pixmap *pix) } } +void +fz_unmultiply_pixmap(fz_pixmap *pix) +{ + unsigned char *s = pix->samples; + int a, inva; + int k, x, y; + + for (y = 0; y < pix->h; y++) + { + for (x = 0; x < pix->w; x++) + { + a = s[pix->n - 1]; + inva = a ? 255 * 256 / a : 0; + for (k = 0; k < pix->n - 1; k++) + s[k] = (s[k] * inva) >> 8; + s += pix->n; + } + } +} + fz_pixmap * fz_alpha_from_gray(fz_pixmap *gray, int luminosity) { -- cgit v1.2.3 From 4e4c33095f62e9a02fc338baec367ae89fe51c2a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Dec 2011 22:29:03 +0100 Subject: Ignore invalid color key Masks that contain non-integer values. --- pdf/pdf_image.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 50292092..3ae0fdfc 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -154,7 +154,14 @@ pdf_load_image_imp(fz_pixmap **imgp, pdf_xref *xref, fz_obj *rdb, fz_obj *dict, { usecolorkey = 1; for (i = 0; i < n * 2; i++) + { + if (!fz_is_int(fz_array_get(obj, i))) + { + fz_warn("invalid value in color key mask"); + usecolorkey = 0; + } colorkey[i] = fz_to_int(fz_array_get(obj, i)); + } } /* Allocate now, to fail early if we run out of memory */ -- cgit v1.2.3 From ba531f60532022e3419628e506462b6b84279478 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 7 Dec 2011 22:29:27 +0100 Subject: Round instead of truncate when converting reals to ints in fz_to_int. --- fitz/base_object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fitz/base_object.c b/fitz/base_object.c index 64fafad0..8e8ac313 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -207,7 +207,7 @@ int fz_to_int(fz_obj *obj) if (fz_is_int(obj)) return obj->u.i; if (fz_is_real(obj)) - return obj->u.f; + return (int)(obj->u.f + 0.5f); /* No roundf in MSVC */ return 0; } -- cgit v1.2.3