From: Ali Gholami Rudi Date: Fri, 4 May 2012 12:16:05 +0000 (+0430) Subject: draw the page horizontally at the center X-Git-Url: https://repo.or.cz/w/fbpdf.git/commitdiff_plain/c4fe87b918c227407ef3b38c73d8ed72bead5628 draw the page horizontally at the center The main benefit is that the focus remains at the center after zooming in or out. I decided to make this change after trying Chuan Ji 's jfbpdf fork. --- diff --git a/djvulibre.c b/djvulibre.c index 427e038..322dd74 100644 --- a/djvulibre.c +++ b/djvulibre.c @@ -45,7 +45,7 @@ int doc_draw(struct doc *doc, fbval_t *bitmap, int p, int rows, int cols, ddjvu_page_t *page; ddjvu_rect_t rect; ddjvu_pageinfo_t info; - int iw, ih; + int w, h; int i, j; page = ddjvu_page_create_by_pageno(doc->doc, p - 1); if (!page) @@ -55,20 +55,22 @@ int doc_draw(struct doc *doc, fbval_t *bitmap, int p, int rows, int cols, return -1; ddjvu_document_get_pageinfo(doc->doc, p - 1, &info); - iw = ddjvu_page_get_width(page); - ih = ddjvu_page_get_height(page); rect.x = 0; rect.y = 0; - rect.w = iw; - rect.h = ih; + rect.w = ddjvu_page_get_width(page); + rect.h = ddjvu_page_get_height(page); /* mode: DDJVU_RENDER_(BLACK|COLOR|BACKGROUND|FOREGROUND) */ djvu_render(page, DDJVU_RENDER_FOREGROUND, img, SIZE, &rect, &rect); ddjvu_page_release(page); zoom /= 4; - for (i = 0; i < ih * zoom / 10; i++) - for (j = 0; j < iw * zoom / 10; j++) - bitmap[i * cols + j] = img[i * 10 / zoom * SIZE + j * 10 / zoom]; + w = MIN(cols, rect.w * zoom / 10); + h = MIN(cols, rect.h * zoom / 10); + for (i = 0; i < h; i++) { + int xs = i * cols + (cols - w) / 2; + for (j = 0; j < w; j++) + bitmap[xs + j] = img[i * 10 / zoom * SIZE + j * 10 / zoom]; + } return 0; } diff --git a/fbpdf.c b/fbpdf.c index fce0589..7ef8113 100644 --- a/fbpdf.c +++ b/fbpdf.c @@ -244,6 +244,7 @@ int main(int argc, char *argv[]) printinfo(); if (fb_init()) return 1; + left = (PDFCOLS - fb_cols()) / 2; if (FBM_BPP(fb_mode()) != sizeof(fbval_t)) fprintf(stderr, "fbpdf: fbval_t doesn't match fb depth\n"); else diff --git a/mupdf.c b/mupdf.c index 36ba996..9c61bd2 100644 --- a/mupdf.c +++ b/mupdf.c @@ -41,10 +41,11 @@ int doc_draw(struct doc *doc, fbval_t *bitmap, int p, int rows, int cols, int zo fz_free_device(dev); for (y = 0; y < h; y++) { + int xs = (h - y - 1) * cols + (cols - w) / 2; for (x = 0; x < w; x++) { unsigned char *s = fz_pixmap_samples(doc->ctx, pix) + y * fz_pixmap_width(doc->ctx, pix) * 4 + x * 4; - bitmap[(h - y - 1) * cols + x] = FB_VAL(s[0], s[1], s[2]); + bitmap[xs + x] = FB_VAL(s[0], s[1], s[2]); } }