Continuous basics

This commit is contained in:
Moritz Lipp 2010-12-28 09:47:09 +01:00
parent eebdc8dece
commit 3f961f6c18
3 changed files with 57 additions and 4 deletions

28
utils.c
View File

@ -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;
}

View File

@ -4,9 +4,11 @@
#define UTILS_H
#include <stdbool.h>
#include <gtk/gtk.h>
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

View File

@ -1,10 +1,13 @@
/* See LICENSE file for license and copyright information */
#include <stdlib.h>
#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;
}