diff options
Diffstat (limited to 'platform/x11')
-rw-r--r-- | platform/x11/pdfapp.c | 48 | ||||
-rw-r--r-- | platform/x11/pdfapp.h | 3 |
2 files changed, 39 insertions, 12 deletions
diff --git a/platform/x11/pdfapp.c b/platform/x11/pdfapp.c index 8f5b09ac..58b160e6 100644 --- a/platform/x11/pdfapp.c +++ b/platform/x11/pdfapp.c @@ -84,6 +84,7 @@ char *pdfapp_usage(pdfapp_t *app) "-\t\t-- zoom out\n" "W\t\t-- zoom to fit window width\n" "H\t\t-- zoom to fit window height\n" + "Z\t\t-- zoom to fit page\n" "w\t\t-- shrinkwrap\n" "f\t\t-- fullscreen\n" "r\t\t-- reload file\n" @@ -979,6 +980,36 @@ void pdfapp_onresize(pdfapp_t *app, int w, int h) } } +void pdfapp_autozoom_vertical(pdfapp_t *app) +{ + app->resolution *= (double) app->winh / (double) fz_pixmap_height(app->ctx, app->image); + if (app->resolution > MAXRES) + app->resolution = MAXRES; + else if (app->resolution < MINRES) + app->resolution = MINRES; + pdfapp_showpage(app, 0, 1, 1, 0, 0); +} + +void pdfapp_autozoom_horizontal(pdfapp_t *app) +{ + app->resolution *= (double) app->winw / (double) fz_pixmap_width(app->ctx, app->image); + if (app->resolution > MAXRES) + app->resolution = MAXRES; + else if (app->resolution < MINRES) + app->resolution = MINRES; + pdfapp_showpage(app, 0, 1, 1, 0, 0); +} + +void pdfapp_autozoom(pdfapp_t *app) +{ + float page_aspect = (float) fz_pixmap_width(app->ctx, app->image) / fz_pixmap_height(app->ctx, app->image); + float win_aspect = (float) app->winw / app->winh; + if (page_aspect > win_aspect) + pdfapp_autozoom_horizontal(app); + else + pdfapp_autozoom_vertical(app); +} + void pdfapp_onkey(pdfapp_t *app, int c) { int oldpage = app->pageno; @@ -1066,20 +1097,13 @@ void pdfapp_onkey(pdfapp_t *app, int c) break; case 'W': - app->resolution *= (double) app->winw / (double) fz_pixmap_width(app->ctx, app->image); - if (app->resolution > MAXRES) - app->resolution = MAXRES; - else if (app->resolution < MINRES) - app->resolution = MINRES; - pdfapp_showpage(app, 0, 1, 1, 0, 0); + pdfapp_autozoom_horizontal(app); break; case 'H': - app->resolution *= (double) app->winh / (double) fz_pixmap_height(app->ctx, app->image); - if (app->resolution > MAXRES) - app->resolution = MAXRES; - else if (app->resolution < MINRES) - app->resolution = MINRES; - pdfapp_showpage(app, 0, 1, 1, 0, 0); + pdfapp_autozoom_vertical(app); + break; + case 'Z': + pdfapp_autozoom(app); break; case 'L': diff --git a/platform/x11/pdfapp.h b/platform/x11/pdfapp.h index 0286f82d..b2ff78da 100644 --- a/platform/x11/pdfapp.h +++ b/platform/x11/pdfapp.h @@ -150,6 +150,9 @@ void pdfapp_oncopy(pdfapp_t *app, unsigned short *ucsbuf, int ucslen); void pdfapp_onresize(pdfapp_t *app, int w, int h); void pdfapp_gotopage(pdfapp_t *app, int number); void pdfapp_reloadpage(pdfapp_t *app); +void pdfapp_autozoom_horizontal(pdfapp_t *app); +void pdfapp_autozoom_vertical(pdfapp_t *app); +void pdfapp_autozoom(pdfapp_t *app); void pdfapp_invert(pdfapp_t *app, const fz_rect *rect); void pdfapp_inverthit(pdfapp_t *app); |