diff --git a/utils.c b/utils.c index c03a5c9..6a0012a 100644 --- a/utils.c +++ b/utils.c @@ -120,3 +120,31 @@ execute_command(char* const argv[], char** output) return true; } + +GdkPixbuf* +page_blank(unsigned int width, unsigned int height) +{ + if((width == 0) || (height == 0)) { + return NULL; + } + + guchar* buffer = malloc(sizeof(guchar) * (width * height * 1)); + if(!buffer) { + return NULL; + } + + /* draw white */ + for(unsigned int i = 0; i < width * height; i++) { + buffer[i] = 255; + } + + GdkPixbuf* pixbuf = gdk_pixbuf_new_from_data(buffer, GDK_COLORSPACE_RGB, FALSE, 8, + width, height, 1, NULL, NULL); + + if(!pixbuf) { + free(buffer); + return NULL; + } + + return pixbuf; +} diff --git a/utils.h b/utils.h index c10ea26..f70b962 100644 --- a/utils.h +++ b/utils.h @@ -4,9 +4,11 @@ #define UTILS_H #include +#include bool file_exists(const char* path); const char* file_get_extension(const char* path); bool execute_command(char* const argv[], char** output); +GdkPixbuf* page_blank(unsigned int width, unsigned int height); #endif // UTILS_H diff --git a/zathura.c b/zathura.c index eb7d39b..60638e5 100644 --- a/zathura.c +++ b/zathura.c @@ -1,10 +1,13 @@ /* See LICENSE file for license and copyright information */ +#include + #include "callbacks.h" #include "config.h" #include "ft/document.h" #include "shortcuts.h" #include "zathura.h" +#include "utils.h" /* function implementation */ bool @@ -81,10 +84,30 @@ document_open(const char* path, const char* password) Zathura.document = document; - /*if(!page_set(0)) {*/ - /*zathura_document_free(document);*/ - /*return false;*/ - /*}*/ + GtkWidget* page_view = gtk_vbox_new(FALSE, 0); + gtk_box_set_spacing(GTK_BOX(page_view), 0); + + for(unsigned int i = 0; i < document->number_of_pages; i++) + { + GdkPixbuf* pixbuf = page_blank(document->pages[i]->width, document->pages[i]->height); + if(!pixbuf) { + return false; + } + + GtkWidget* image = gtk_image_new(); + if(!image) { + g_object_unref(pixbuf); + return false; + } + + gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf); + gtk_widget_show(image); + gtk_box_pack_start(GTK_BOX(page_view), image, TRUE, TRUE, 0); + } + + gtk_widget_show(page_view); + + girara_set_view(Zathura.UI.session, page_view); return true; }