From 7c66c5b60244433c8224dbe3454399c4f6948c0c Mon Sep 17 00:00:00 2001 From: malc Date: Tue, 12 Jul 2016 20:26:20 +0300 Subject: [PATCH] Sync with upstream Also fix some issues reported by valgrind. --- BUILDING | 2 +- link.c | 51 +++++++++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/BUILDING b/BUILDING index 1061f07..0fb23e7 100644 --- a/BUILDING +++ b/BUILDING @@ -11,7 +11,7 @@ Prerequisites for building from sources: llpp% git clone git://git.ghostscript.com/mupdf.git --recursive llpp% cd mupdf - mupdf% git checkout e2a85460370a3110b89fb838bc924c73f87f5b3c + mupdf% git checkout 6153a0761831bbc490213df7911ec596b6ea59f2 mupdf% git submodule update --recursive mupdf% make build=native libs mupdf% cd .. diff --git a/link.c b/link.c index cf6b62a..59a8396 100644 --- a/link.c +++ b/link.c @@ -644,25 +644,21 @@ static void trimctm (pdf_page *page, int pindex) fz_matrix ctm; struct pagedim *pdim = &state.pagedims[pindex]; + if (!page) return; if (!pdim->tctmready) { - if (state.trimmargins) { - fz_rect realbox, mediabox; - fz_matrix rm, sm, tm, im, ctm1, page_ctm; - - fz_rotate (&rm, -pdim->rotate); - fz_scale (&sm, 1, -1); - fz_concat (&ctm, &rm, &sm); - realbox = pdim->mediabox; - fz_transform_rect (&realbox, &ctm); - fz_translate (&tm, -realbox.x0, -realbox.y0); - fz_concat (&ctm1, &ctm, &tm); - pdf_page_transform (state.ctx, page, &mediabox, &page_ctm); - fz_invert_matrix (&im, &page_ctm); - fz_concat (&ctm, &im, &ctm1); - } - else { - ctm = fz_identity; - } + fz_rect realbox, mediabox; + fz_matrix rm, sm, tm, im, ctm1, page_ctm; + + fz_rotate (&rm, -pdim->rotate); + fz_scale (&sm, 1, -1); + fz_concat (&ctm, &rm, &sm); + realbox = pdim->mediabox; + fz_transform_rect (&realbox, &ctm); + fz_translate (&tm, -realbox.x0, -realbox.y0); + fz_concat (&ctm1, &ctm, &tm); + pdf_page_transform (state.ctx, page, &mediabox, &page_ctm); + fz_invert_matrix (&im, &page_ctm); + fz_concat (&ctm, &im, &ctm1); pdim->tctm = ctm; pdim->tctmready = 1; } @@ -709,6 +705,7 @@ static void *loadpage (int pageno, int pindex) fz_catch (state.ctx) { page->fzpage = NULL; } + fz_close_device (state.ctx, dev); fz_drop_device (state.ctx, dev); page->pdimno = pindex; @@ -796,6 +793,7 @@ static struct tile *rendertile (struct page *page, int x, int y, int w, int h, ctm = pagectm (page); fz_rect_from_irect (&rect, &bbox); fz_run_display_list (state.ctx, page->dlist, dev, &ctm, &rect, NULL); + fz_close_device (state.ctx, dev); fz_drop_device (state.ctx, dev); return tile; @@ -906,7 +904,7 @@ static void initpdims (int wthack) #endif for (pageno = 0; pageno < cxcount; ++pageno) { - int rotate; + int rotate = 0; struct pagedim *p; fz_rect mediabox; @@ -940,6 +938,7 @@ static void initpdims (int wthack) pdf_page_transform (ctx, page, &mediabox, &page_ctm); fz_invert_matrix (&ctm, &page_ctm); pdf_run_page (ctx, page, dev, &fz_identity, NULL); + fz_close_device (ctx, dev); fz_drop_device (ctx, dev); rect.x0 += state.trimfuzz.x0; @@ -1034,7 +1033,6 @@ static void initpdims (int wthack) fz_try (ctx) { page = fz_load_page (ctx, state.doc, pageno); fz_bound_page (ctx, page, &mediabox); - rotate = 0; if (state.trimmargins) { fz_rect rect; fz_device *dev; @@ -1042,6 +1040,7 @@ static void initpdims (int wthack) dev = fz_new_bbox_device (ctx, &rect); dev->hints |= FZ_IGNORE_SHADE; fz_run_page (ctx, page, dev, &fz_identity, NULL); + fz_close_device (ctx, dev); fz_drop_device (ctx, dev); rect.x0 += state.trimfuzz.x0; @@ -1489,6 +1488,7 @@ static void search (regex_t *re, int pageno, int y, int forward) } qsort (text->blocks, text->len, sizeof (*text->blocks), compareblocks); + fz_close_device (state.ctx, tdev); fz_drop_device (state.ctx, tdev); for (j = 0; j < text->len; ++j) { @@ -2692,11 +2692,12 @@ static struct annot *getannot (struct page *page, int x, int y) if (pdf) { for (i = 0; i < page->annotcount; ++i) { struct annot *a = &page->annots[i]; - pdf_annot *annot = (pdf_annot *) a->annot; - if (p.x >= annot->pagerect.x0 && p.x <= annot->pagerect.x1) { - if (p.y >= annot->pagerect.y0 && p.y <= annot->pagerect.y1) { + fz_rect rect; + + fz_bound_annot (state.ctx, a->annot, &rect); + if (p.x >= rect.x0 && p.x <= rect.x1) { + if (p.y >= rect.y0 && p.y <= rect.y1) return a; - } } } } @@ -2746,6 +2747,7 @@ static void ensuretext (struct page *page) tdev, &ctm, &fz_infinite_rect, NULL); qsort (page->text->blocks, page->text->len, sizeof (*page->text->blocks), compareblocks); + fz_close_device (state.ctx, tdev); fz_drop_device (state.ctx, tdev); } } @@ -3891,6 +3893,7 @@ CAMLprim value ml_getpagebox (value opaque_v) ctm = pagectm (page); fz_run_page (state.ctx, page->fzpage, dev, &ctm, NULL); + fz_close_device (state.ctx, dev); fz_drop_device (state.ctx, dev); fz_round_rect (&bbox, &rect); Field (ret_v, 0) = Val_int (bbox.x0); -- 2.11.4.GIT