diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index ca04c14..ca59d71 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -243,17 +243,39 @@ djvu_page_render(zathura_page_t* page) page_width, page_height, 3 * page_width, NULL, NULL); if(!pixbuf) { - free(buffer); - g_object_unref(pixbuf); - goto error_out; + goto error_free; + } + + /* rotate page */ + if(Zathura.document->rotate != 0) { + GdkPixbufRotation angle = GDK_PIXBUF_ROTATE_NONE; + + switch(Zathura.document->rotate) { + case 90: + angle = GDK_PIXBUF_ROTATE_CLOCKWISE; + break; + case 180: + angle = GDK_PIXBUF_ROTATE_UPSIDEDOWN; + break; + case 270: + angle = GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE; + break; + default: + goto error_free; + } + + GdkPixbuf* pixbuf_temp = gdk_pixbuf_rotate_simple(pixbuf, Zathura.document->rotate); + if(!pixbuf_temp) { + goto error_free; + } + + pixbuf = pixbuf_temp; } GtkWidget* image = gtk_image_new(); if(!image) { - free(buffer); - g_object_unref(pixbuf); - goto error_out; + goto error_free; } gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); @@ -261,6 +283,11 @@ djvu_page_render(zathura_page_t* page) return image; +error_free: + + free(buffer); + g_object_unref(pixbuf); + error_out: return NULL; diff --git a/zathura.c b/zathura.c index f0a41a9..7c81c1b 100644 --- a/zathura.c +++ b/zathura.c @@ -101,6 +101,26 @@ document_close() return true; } +bool +page_render(zathura_page_t* page) +{ + GtkWidget* image = zathura_page_render(page); + if(!image) { + goto error_out; + } + + /* draw new rendered page */ + if(!girara_set_view(Zathura.UI.session, image)) { + goto error_out; + } + + return true; + +error_out: + + return false; +} + bool page_set(unsigned int page_id) { @@ -114,12 +134,12 @@ page_set(unsigned int page_id) /* render page */ zathura_page_t* page = zathura_page_get(Zathura.document, page_id); + if(!page) { goto error_out; } - GtkWidget* image = zathura_page_render(page); - if(!image) { + if(!page_render(page)) { zathura_page_free(page); fprintf(stderr, "error: rendering failed\n"); goto error_out; @@ -127,11 +147,6 @@ page_set(unsigned int page_id) zathura_page_free(page); - /* draw new rendered page */ - if(!girara_set_view(Zathura.UI.session, image)) { - goto error_out; - } - /* update page number */ Zathura.document->current_page_number = page_id;