summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4928e67)
raw | patch | inline | side by side (parent: 4928e67)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 21 Oct 2011 12:42:59 +0000 (14:42 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 21 Oct 2011 12:42:59 +0000 (14:42 +0200) |
Currently, when leaving those modes, the zoom will be reset to the value
before entering any of those modes. This is done on purpose ;-)
before entering any of those modes. This is done on purpose ;-)
src/gtk-tpdfv.c | patch | blob | history | |
src/gtk-tpdfv.h | patch | blob | history | |
src/tpdfview.c | patch | blob | history |
diff --git a/src/gtk-tpdfv.c b/src/gtk-tpdfv.c
index b04d2c6f9cb3ffb177e039dc45f10fa268b3f84d..4398719385557f7144ca42c674bdf66acfd47630 100644 (file)
--- a/src/gtk-tpdfv.c
+++ b/src/gtk-tpdfv.c
#include <stdlib.h>
#include <string.h>
+#define TPDFV_MIN(a, b) ((a) <= (b) ? (a) : (b))
+#define TPDFV_MAX(a, b) ((a) >= (b) ? (a) : (b))
+
+typedef enum {
+ TPDFV_ZOOM_CUSTOM = 0,
+ TPDFV_ZOOM_WIDTH,
+ TPDFV_ZOOM_HEIGHT,
+ TPDFV_ZOOM_FIT,
+} tpdfv_zoommode_t;
+
typedef struct {
char *filename;
int current_page_no;
int total_pages;
+ tpdfv_zoommode_t zoom_mode;
double zoom_factor;
double delta_x;
pdf->total_pages = poppler_document_get_n_pages(pdf->doc);
+ pdf->zoom_mode = TPDFV_ZOOM_CUSTOM;
pdf->zoom_factor = 1.0;
pdf->delta_x = pdf->delta_y = 0.0;
return TRUE;
cairo_clip(cr);
/* zoom, scrolling */
- cairo_scale(cr, pdf->zoom_factor, pdf->zoom_factor);
+ if (pdf->zoom_mode == TPDFV_ZOOM_CUSTOM) {
+ cairo_scale(cr, pdf->zoom_factor, pdf->zoom_factor);
+ }
+ else {
+ gdouble width;
+ gdouble height;
+
+ gdouble page_width = 0.0;
+ gdouble page_height = 0.0;
+
+ double zoom_factor = 1.0;
+
+ poppler_page_get_size(pdf->current_page, &page_width, &page_height);
+ width = (gdouble)tpdfv->allocation.width;
+ height = (gdouble)tpdfv->allocation.height;
+
+ if (pdf->zoom_mode == TPDFV_ZOOM_WIDTH) {
+ zoom_factor = (double)(width / page_width);
+ }
+ else if (pdf->zoom_mode == TPDFV_ZOOM_HEIGHT) {
+ zoom_factor = (double)(height / page_height);
+ }
+ else if (pdf->zoom_mode == TPDFV_ZOOM_FIT) {
+ zoom_factor = (double)TPDFV_MIN(width / page_width,
+ height / page_height);
+ }
+ else {
+ assert(0);
+ }
+
+ cairo_scale(cr, zoom_factor, zoom_factor);
+ }
+
cairo_translate(cr, pdf->delta_x, pdf->delta_y);
poppler_page_render(pdf->current_page, cr);
pdf = GTK_TPDFV_GET_PRIVATE(widget);
pdf->zoom_factor *= 1.2;
+ pdf->zoom_mode = TPDFV_ZOOM_CUSTOM;
do_redraw(widget);
} /* gtk_tpdfv_zoom_in */
if (pdf->zoom_factor > DBL_EPSILON * 2.0) {
pdf->zoom_factor /= 1.2;
+ pdf->zoom_mode = TPDFV_ZOOM_CUSTOM;
do_redraw(widget);
}
} /* gtk_tpdfv_zoom_out */
pdf = GTK_TPDFV_GET_PRIVATE(widget);
pdf->zoom_factor = 1.0;
+ pdf->zoom_mode = TPDFV_ZOOM_CUSTOM;
do_redraw(widget);
} /* gtk_tpdfv_zoom_1 */
+void
+gtk_tpdfv_zoom_width(GtkWidget *widget)
+{
+ gtk_tpdfv_t *pdf;
+
+ pdf = GTK_TPDFV_GET_PRIVATE(widget);
+ pdf->zoom_mode = TPDFV_ZOOM_WIDTH;
+ do_redraw(widget);
+} /* gtk_tpdfv_zoom_width */
+
+void
+gtk_tpdfv_zoom_height(GtkWidget *widget)
+{
+ gtk_tpdfv_t *pdf;
+
+ pdf = GTK_TPDFV_GET_PRIVATE(widget);
+ pdf->zoom_mode = TPDFV_ZOOM_HEIGHT;
+ do_redraw(widget);
+} /* gtk_tpdfv_zoom_width */
+
+void
+gtk_tpdfv_zoom_fit(GtkWidget *widget)
+{
+ gtk_tpdfv_t *pdf;
+
+ pdf = GTK_TPDFV_GET_PRIVATE(widget);
+ pdf->zoom_mode = TPDFV_ZOOM_FIT;
+ do_redraw(widget);
+} /* gtk_tpdfv_zoom_width */
+
void
gtk_tpdfv_scroll_up(GtkWidget *widget)
{
diff --git a/src/gtk-tpdfv.h b/src/gtk-tpdfv.h
index c4e0599416b8043f75e4ac2b81abc095a1e2143a..7d260bd28e5491c213567de01a31dd338cc2d8fb 100644 (file)
--- a/src/gtk-tpdfv.h
+++ b/src/gtk-tpdfv.h
gtk_tpdfv_zoom_out(GtkWidget *widget);
void
gtk_tpdfv_zoom_1(GtkWidget *widget);
+void
+gtk_tpdfv_zoom_width(GtkWidget *widget);
+void
+gtk_tpdfv_zoom_height(GtkWidget *widget);
+void
+gtk_tpdfv_zoom_fit(GtkWidget *widget);
/*
* gtk_tpdfv_scroll_up, gtk_tpdfv_scroll_down,
diff --git a/src/tpdfview.c b/src/tpdfview.c
index 8c556004540d712a2638292f35bce77e4056d684..d46aef030a44a977ebd72a4ed0d5b0f1aa40ca27 100644 (file)
--- a/src/tpdfview.c
+++ b/src/tpdfview.c
case GDK_1:
gtk_tpdfv_zoom_1(tpdfv);
break;
+ case GDK_w:
+ gtk_tpdfv_zoom_width(tpdfv);
+ break;
+ case GDK_h:
+ gtk_tpdfv_zoom_height(tpdfv);
+ break;
+ case GDK_z:
+ gtk_tpdfv_zoom_fit(tpdfv);
+ break;
/* scrolling */
case GDK_Up: