diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-01-12 01:12:28 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-01-12 01:12:28 +0100 |
commit | 9994b3f49db7bd925a7ae7874cbc99025469ee9e (patch) | |
tree | c718919738e0c70cc94959aad1b5b4997f11389f | |
parent | 09086b236af6e49f2f090f80a450b1d82f217f30 (diff) | |
download | mupdf-9994b3f49db7bd925a7ae7874cbc99025469ee9e.tar.xz |
Use the same coordinate system for pdf and xps pages in the interface.
Move coordinate space tweaks into pdf_ and xps_run_page, and provide
neutral pdf_ and xps_bound_page functions to return the page size as
a zero-origined bounding box.
-rw-r--r-- | android/jni/mupdf.c | 12 | ||||
-rw-r--r-- | apps/pdfapp.c | 18 | ||||
-rw-r--r-- | apps/pdfapp.h | 1 | ||||
-rw-r--r-- | apps/pdfdraw.c | 8 | ||||
-rw-r--r-- | apps/xpsdraw.c | 10 | ||||
-rw-r--r-- | ios/document.c | 25 | ||||
-rw-r--r-- | pdf/mupdf.h | 1 | ||||
-rw-r--r-- | pdf/pdf_interpret.c | 8 | ||||
-rw-r--r-- | pdf/pdf_page.c | 10 | ||||
-rw-r--r-- | xps/muxps.h | 1 | ||||
-rw-r--r-- | xps/xps_doc.c | 10 | ||||
-rw-r--r-- | xps/xps_tile.c | 5 |
12 files changed, 56 insertions, 53 deletions
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c index 277bb7b3..f0d13b73 100644 --- a/android/jni/mupdf.c +++ b/android/jni/mupdf.c @@ -29,7 +29,6 @@ float pageWidth = 100; float pageHeight = 100; fz_display_list *currentPageList; fz_rect currentMediabox; -int currentRotate; fz_context *ctx; JNIEXPORT int JNICALL @@ -124,11 +123,8 @@ Java_com_artifex_mupdf_MuPDFCore_gotoPageInternal(JNIEnv *env, jobject thiz, int pagenum = page; currentPage = pdf_load_page(xref, pagenum); zoom = resolution / 72; - currentMediabox = currentPage->mediabox; - currentRotate = currentPage->rotate; - ctm = fz_translate(0, -currentMediabox.y1); - ctm = fz_concat(ctm, fz_scale(zoom, -zoom)); - ctm = fz_concat(ctm, fz_rotate(currentRotate)); + currentMediabox = pdf_bound_page(xref, currentPage); + ctm = fz_scale(zoom, zoom); bbox = fz_round_rect(fz_transform_rect(ctm, currentMediabox)); pageWidth = bbox.x1-bbox.x0; pageHeight = bbox.y1-bbox.y0; @@ -216,9 +212,7 @@ Java_com_artifex_mupdf_MuPDFCore_drawPage(JNIEnv *env, jobject thiz, jobject bit fz_clear_pixmap_with_color(pix, 0xff); zoom = resolution / 72; - ctm = fz_translate(-currentMediabox.x0, -currentMediabox.y1); - ctm = fz_concat(ctm, fz_scale(zoom, -zoom)); - ctm = fz_concat(ctm, fz_rotate(currentRotate)); + ctm = fz_scale(zoom, zoom); bbox = fz_round_rect(fz_transform_rect(ctm,currentMediabox)); /* Now, adjust ctm so that it would give the correct page width * heights. */ diff --git a/apps/pdfapp.c b/apps/pdfapp.c index 0f8dd7e3..250ca198 100644 --- a/apps/pdfapp.c +++ b/apps/pdfapp.c @@ -260,13 +260,8 @@ void pdfapp_close(pdfapp_t *app) static fz_matrix pdfapp_viewctm(pdfapp_t *app) { fz_matrix ctm; - ctm = fz_identity; - ctm = fz_concat(ctm, fz_translate(0, -app->page_bbox.y1)); - if (app->xref) - ctm = fz_concat(ctm, fz_scale(app->resolution/72.0f, -app->resolution/72.0f)); - else - ctm = fz_concat(ctm, fz_scale(app->resolution/96.0f, app->resolution/96.0f)); - ctm = fz_concat(ctm, fz_rotate(app->rotate + app->page_rotate)); + ctm = fz_scale(app->resolution/72.0f, app->resolution/72.0f); + ctm = fz_concat(ctm, fz_rotate(app->rotate)); return ctm; } @@ -308,8 +303,7 @@ static void pdfapp_loadpage_pdf(pdfapp_t *app) pdfapp_error(app, "cannot load page"); } - app->page_bbox = page->mediabox; - app->page_rotate = page->rotate; + app->page_bbox = pdf_bound_page(app->xref, page); app->page_links = page->links; page->links = NULL; @@ -343,11 +337,7 @@ static void pdfapp_loadpage_xps(pdfapp_t *app) pdfapp_error(app, "cannot load page"); } - app->page_bbox.x0 = 0; - app->page_bbox.y0 = 0; - app->page_bbox.x1 = page->width; - app->page_bbox.y1 = page->height; - app->page_rotate = 0; + app->page_bbox = xps_bound_page(app->xps, page); app->page_links = NULL; /* Create display list */ diff --git a/apps/pdfapp.h b/apps/pdfapp.h index 84d00979..b23f939a 100644 --- a/apps/pdfapp.h +++ b/apps/pdfapp.h @@ -45,7 +45,6 @@ struct pdfapp_s /* current page params */ int pageno; fz_rect page_bbox; - float page_rotate; fz_display_list *page_list; fz_text_span *page_text; fz_link *page_links; diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 885103bc..d811df07 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -193,17 +193,17 @@ static void drawpage(pdf_xref *xref, int pagenum) { float zoom; fz_matrix ctm; + fz_rect bounds; fz_bbox bbox; fz_pixmap *pix = NULL; fz_var(pix); + bounds = pdf_bound_page(xref, page); zoom = resolution / 72; - ctm = fz_translate(0, -page->mediabox.y1); - ctm = fz_concat(ctm, fz_scale(zoom, -zoom)); - ctm = fz_concat(ctm, fz_rotate(page->rotate)); + ctm = fz_scale(zoom, zoom); ctm = fz_concat(ctm, fz_rotate(rotation)); - bbox = fz_round_rect(fz_transform_rect(ctm, page->mediabox)); + bbox = fz_round_rect(fz_transform_rect(ctm, bounds)); /* TODO: banded rendering and multi-page ppm */ diff --git a/apps/xpsdraw.c b/apps/xpsdraw.c index 1058c390..50a2c3e3 100644 --- a/apps/xpsdraw.c +++ b/apps/xpsdraw.c @@ -137,13 +137,9 @@ static void drawpage(xps_document *doc, int pagenum) fz_bbox bbox; fz_pixmap *pix; - rect.x0 = rect.y0 = 0; - rect.x1 = page->width; - rect.y1 = page->height; - - zoom = resolution / 96; - ctm = fz_translate(0, -page->height); - ctm = fz_concat(ctm, fz_scale(zoom, zoom)); + rect = xps_bound_page(doc, page); + zoom = resolution / 72; + ctm = fz_scale(zoom, zoom); bbox = fz_round_rect(fz_transform_rect(ctm, rect)); /* TODO: banded rendering and multi-page ppm */ diff --git a/ios/document.c b/ios/document.c index dd893362..3d014d6b 100644 --- a/ios/document.c +++ b/ios/document.c @@ -120,15 +120,14 @@ measure_page(struct document *doc, int number, float *w, float *h) { load_page(doc, number); if (doc->pdf_page) { - pdf_page *page = doc->pdf_page; - fz_rect mediabox = fz_transform_rect(fz_rotate(page->rotate), page->mediabox); - *w = mediabox.x1 - mediabox.x0; - *h = mediabox.y1 - mediabox.y0; + fz_rect bounds = pdf_bound_page(doc->pdf, doc->pdf_page); + *w = bounds.x1 - bounds.x0; + *h = bounds.y1 - bounds.y0; } else if (doc->xps_page) { - xps_page *page = doc->xps_page; - *w = page->width * 72.0f / 96.0f; - *h = page->height * 72.0f / 96.0f; + fz_rect bounds = xps_bound_page(doc->xps, doc->xps_page); + *w = bounds.x1 - bounds.x0; + *h = bounds.y1 - bounds.y0; } else { *w = *h = 72; @@ -143,17 +142,9 @@ draw_page(struct document *doc, int number, fz_device *dev, fz_matrix ctm, fz_co fz_try (doc->ctx) { if (doc->pdf_page) { - pdf_page *page = doc->pdf_page; - fz_matrix page_ctm = fz_concat(fz_rotate(-page->rotate), fz_scale(1, -1)); - fz_rect mediabox = fz_transform_rect(page_ctm, page->mediabox); - page_ctm = fz_concat(page_ctm, fz_translate(-mediabox.x0, -mediabox.y0)); - ctm = fz_concat(page_ctm, ctm); - pdf_run_page(doc->pdf, page, dev, ctm, cookie); + pdf_run_page(doc->pdf, doc->pdf_page, dev, ctm, cookie); } else if (doc->xps_page) { - xps_page *page = doc->xps_page; - fz_matrix page_ctm = fz_scale(72.0f / 96.0f, 72.0f / 96.0f); - ctm = fz_concat(page_ctm, ctm); - xps_run_page(doc->xps, page, dev, ctm, cookie); + xps_run_page(doc->xps, doc->xps_page, dev, ctm, cookie); } } fz_catch (doc->ctx) diff --git a/pdf/mupdf.h b/pdf/mupdf.h index d9a6b7c6..1ec9d4f2 100644 --- a/pdf/mupdf.h +++ b/pdf/mupdf.h @@ -455,6 +455,7 @@ int pdf_find_page_number(pdf_xref *xref, fz_obj *pageobj); int pdf_count_pages(pdf_xref *xref); pdf_page *pdf_load_page(pdf_xref *xref, int number); +fz_rect pdf_bound_page(pdf_xref *xref, pdf_page *page); void pdf_free_page(fz_context *ctx, pdf_page *page); /* diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c index c8b65dd6..fe0e1ce8 100644 --- a/pdf/pdf_interpret.c +++ b/pdf/pdf_interpret.c @@ -2574,10 +2574,16 @@ pdf_run_buffer(pdf_csi *csi, fz_obj *rdb, fz_buffer *contents) void pdf_run_page_with_usage(pdf_xref *xref, pdf_page *page, fz_device *dev, fz_matrix ctm, char *event, fz_cookie *cookie) { + fz_context *ctx = dev->ctx; pdf_csi *csi; pdf_annot *annot; int flags; - fz_context *ctx = dev->ctx; + + /* Adjust CTM for rotation */ + fz_matrix page_ctm = fz_concat(fz_rotate(-page->rotate), fz_scale(1, -1)); + fz_rect mediabox = fz_transform_rect(page_ctm, page->mediabox); + page_ctm = fz_concat(page_ctm, fz_translate(-mediabox.x0, -mediabox.y0)); + ctm = fz_concat(page_ctm, ctm); if (page->transparency) fz_begin_group(dev, fz_transform_rect(ctm, page->mediabox), 1, 0, 0, 1); diff --git a/pdf/pdf_page.c b/pdf/pdf_page.c index e8b27ccc..536cd5ac 100644 --- a/pdf/pdf_page.c +++ b/pdf/pdf_page.c @@ -386,6 +386,16 @@ pdf_load_page(pdf_xref *xref, int number) return page; } +fz_rect +pdf_bound_page(pdf_xref *xref, pdf_page *page) +{ + fz_rect bounds, mediabox = fz_transform_rect(fz_rotate(page->rotate), page->mediabox); + bounds.x0 = bounds.y0 = 0; + bounds.x1 = mediabox.x1 - mediabox.x0; + bounds.y1 = mediabox.y1 - mediabox.y0; + return bounds; +} + void pdf_free_page(fz_context *ctx, pdf_page *page) { diff --git a/xps/muxps.h b/xps/muxps.h index 95b68860..96a8a1eb 100644 --- a/xps/muxps.h +++ b/xps/muxps.h @@ -105,6 +105,7 @@ void xps_free_page_list(xps_document *doc); int xps_count_pages(xps_document *doc); xps_page *xps_load_page(xps_document *doc, int number); +fz_rect xps_bound_page(xps_document *doc, xps_page *page); void xps_free_page(xps_document *doc, xps_page *page); fz_outline *xps_load_outline(xps_document *doc); diff --git a/xps/xps_doc.c b/xps/xps_doc.c index c01b7561..36903266 100644 --- a/xps/xps_doc.c +++ b/xps/xps_doc.c @@ -364,6 +364,16 @@ xps_load_page(xps_document *doc, int number) return NULL; } +fz_rect +xps_bound_page(xps_document *doc, xps_page *page) +{ + fz_rect bounds; + bounds.x0 = bounds.y0 = 0; + bounds.x1 = page->width * 72.0f / 96.0f; + bounds.y1 = page->height * 72.0f / 96.0f; + return bounds; +} + void xps_free_page(xps_document *doc, xps_page *page) { diff --git a/xps/xps_tile.c b/xps/xps_tile.c index 842e4cda..b672724b 100644 --- a/xps/xps_tile.c +++ b/xps/xps_tile.c @@ -360,6 +360,11 @@ xps_parse_fixed_page(xps_document *doc, fz_matrix ctm, xps_page *page) void xps_run_page(xps_document *doc, xps_page *page, fz_device *dev, fz_matrix ctm, fz_cookie *cookie) { + fz_matrix page_ctm; + + page_ctm = fz_scale(72.0f / 96.0f, 72.0f / 96.0f); + ctm = fz_concat(page_ctm, ctm); + doc->cookie = cookie; doc->dev = dev; xps_parse_fixed_page(doc, ctm, page); |