diff --git a/document.c b/document.c index 48d97d1..b1d0e4f 100644 --- a/document.c +++ b/document.c @@ -124,7 +124,7 @@ zathura_document_plugins_free(void) bool zathura_document_plugin_register(zathura_document_plugin_t* new_plugin, void* handle) { - if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) + if( (new_plugin == NULL) || (new_plugin->file_extension == NULL) || (new_plugin->open_function == NULL) || (handle == NULL) ) { fprintf(stderr, "plugin: could not register\n"); return false; @@ -469,7 +469,7 @@ zathura_page_form_fields_free(zathura_list_t* list) return false; } -GtkWidget* +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page) { if (!page || !page->document) { @@ -481,13 +481,13 @@ zathura_page_render(zathura_page_t* page) return NULL; } - GtkWidget* widget = page->document->functions.page_render(page); + zathura_image_buffer_t* buffer = page->document->functions.page_render(page); - if (widget) { + if (buffer) { page->rendered = true; } - return widget; + return buffer; } zathura_index_element_t* @@ -523,3 +523,35 @@ zathura_index_element_free(zathura_index_element_t* index) g_free(index); } + +zathura_image_buffer_t* +zathura_image_buffer_create(unsigned int width, unsigned int height) +{ + zathura_image_buffer_t* image_buffer = malloc(sizeof(zathura_image_buffer_t)); + + if (image_buffer == NULL) { + return NULL; + } + + image_buffer->data = calloc(width * height * 3, sizeof(unsigned char)); + + if (image_buffer->data == NULL) { + free(image_buffer); + return NULL; + } + + image_buffer->width = width; + image_buffer->height = height; + + return image_buffer; +} + +void +zathura_image_buffer_free(zathura_image_buffer_t* image_buffer) +{ + if (image_buffer == NULL) { + return; + } + + free(image_buffer->data); +} diff --git a/document.h b/document.h index 6af627d..f05ee68 100644 --- a/document.h +++ b/document.h @@ -43,6 +43,32 @@ struct zathura_list_s struct zathura_list_s* next; /**> Next element in the list */ }; +/** + * Image buffer + */ +typedef struct zathura_image_buffer_s +{ + unsigned char* data; /**> Image buffer data */ + unsigned int height; /**> Height of the image */ + unsigned int width; /**> Width of the image */ +} zathura_image_buffer_t; + +/** + * Creates an image buffer + * + * @param width Width of the image stored in the buffer + * @param height Height of the image stored in the buffer + * @return Image buffer or NULL if an error occured + */ +zathura_image_buffer_t* zathura_image_buffer_create(unsigned int width, unsigned int height); + +/** + * Frees the image buffer + * + * @param zathura_image_buffer_t + */ +void zathura_image_buffer_free(zathura_image_buffer_t*); + /** * Rectangle structure */ @@ -141,83 +167,51 @@ struct zathura_document_s { /** * Frees the document - * - * @param document The document */ bool (*document_free)(zathura_document_t* document); /** * Generates the document index - * - * @param document The document - * @return NULL if an error occured or no index exists */ girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); /** * Save the document - * - * @param document The document - * @param path The new path - * @return true if no error occured */ bool (*document_save_as)(zathura_document_t* document, const char* path); /** * Get list of attachments - * - * @param document The document - * @return NULL if an error occured, otherwise the attachment list */ zathura_list_t* (*document_attachments_get)(zathura_document_t* document); /** * Gets the page object - * - * @param document The document - * @param page_id Number of the page - * @return The page object or NULL, if an error occured */ zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); /** * Search text - * - * @param page The page - * @param text Search item - * @return List of results */ zathura_list_t* (*page_search_text)(zathura_page_t* page, const char* text); /** * Get links on a page - * - * @param page - * @return List of links */ zathura_list_t* (*page_links_get)(zathura_page_t* page); /** * Get form fields - * - * @param page - * @return List of form fields */ zathura_list_t* (*page_form_fields_get)(zathura_page_t* page); /** * Renders the page - * - * @param page - * @return Rendered page */ - GtkWidget* (*page_render)(zathura_page_t* page); + zathura_image_buffer_t* (*page_render)(zathura_page_t* page); /** * Free page - * - * @param page - * @return true if no error occured, otherwise false */ bool (*page_free)(zathura_page_t* page); } functions; @@ -356,9 +350,9 @@ bool zathura_page_form_fields_free(zathura_list_t* list); * Render page * * @param page The page object - * @return Rendered page + * @return Image buffer or NULL if an error occured */ -GtkWidget* zathura_page_render(zathura_page_t* page); +zathura_image_buffer_t* zathura_page_render(zathura_page_t* page); /** * Create new index element diff --git a/ft/djvu/djvu.c b/ft/djvu/djvu.c index a45ac83..7c795ce 100644 --- a/ft/djvu/djvu.c +++ b/ft/djvu/djvu.c @@ -215,7 +215,7 @@ djvu_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->document) { diff --git a/ft/djvu/djvu.h b/ft/djvu/djvu.h index f043f69..31444ff 100644 --- a/ft/djvu/djvu.h +++ b/ft/djvu/djvu.h @@ -24,7 +24,7 @@ zathura_page_t* djvu_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* djvu_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* djvu_page_links_get(zathura_page_t* page); zathura_list_t* djvu_page_form_fields_get(zathura_page_t* page); -GtkWidget* djvu_page_render(zathura_page_t* page); +zathura_image_buffer_t* djvu_page_render(zathura_page_t* page); bool djvu_page_free(zathura_page_t* page); #endif // DJVU_H diff --git a/ft/pdf-mupdf/pdf.c b/ft/pdf-mupdf/pdf.c index 09bd3e0..a676826 100644 --- a/ft/pdf-mupdf/pdf.c +++ b/ft/pdf-mupdf/pdf.c @@ -173,7 +173,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-mupdf/pdf.h b/ft/pdf-mupdf/pdf.h index 9d53949..84d7b38 100644 --- a/ft/pdf-mupdf/pdf.h +++ b/ft/pdf-mupdf/pdf.h @@ -27,7 +27,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/ft/pdf-poppler/pdf.c b/ft/pdf-poppler/pdf.c index 36b192e..8415468 100644 --- a/ft/pdf-poppler/pdf.c +++ b/ft/pdf-poppler/pdf.c @@ -250,7 +250,7 @@ pdf_page_form_fields_get(zathura_page_t* page) return NULL; } -GtkWidget* +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page) { if (!Zathura.document || !page || !page->data || !page->document) { diff --git a/ft/pdf-poppler/pdf.h b/ft/pdf-poppler/pdf.h index 5b959d0..ce76613 100644 --- a/ft/pdf-poppler/pdf.h +++ b/ft/pdf-poppler/pdf.h @@ -22,7 +22,7 @@ zathura_page_t* pdf_page_get(zathura_document_t* document, unsigned int page); zathura_list_t* pdf_page_search_text(zathura_page_t* page, const char* text); zathura_list_t* pdf_page_links_get(zathura_page_t* page); zathura_list_t* pdf_page_form_fields_get(zathura_page_t* page); -GtkWidget* pdf_page_render(zathura_page_t* page); +zathura_image_buffer_t* pdf_page_render(zathura_page_t* page); bool pdf_page_free(zathura_page_t* page); #endif // PDF_H diff --git a/render.c b/render.c index f863ae7..c163638 100644 --- a/render.c +++ b/render.c @@ -132,9 +132,9 @@ bool render(zathura_page_t* page) { g_static_mutex_lock(&(page->lock)); - GtkWidget* image = zathura_page_render(page); + zathura_image_buffer_t* buffer = zathura_page_render(page); - if (!image) { + if (!buffer) { g_static_mutex_unlock(&(page->lock)); printf("error: rendering failed\n"); return false; @@ -148,7 +148,7 @@ render(zathura_page_t* page) if (!widget) { g_static_mutex_unlock(&(page->lock)); printf("error: page container does not exist\n"); - g_object_unref(image); + // TODO: zathura_image_buffer_free(image); return false; } @@ -164,13 +164,13 @@ render(zathura_page_t* page) gtk_container_remove(GTK_CONTAINER(Zathura.UI.page_view), widget); /* add new widget */ - gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); + // TODO: gtk_box_pack_start(GTK_BOX(Zathura.UI.page_view), image, TRUE, TRUE, 0); /* set old packaging values */ - gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); + // TODO: gtk_box_set_child_packing(GTK_BOX(Zathura.UI.page_view), image, expand, fill, padding, pack_type); /* reorder child */ - gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); + // TODO: gtk_box_reorder_child(GTK_BOX(Zathura.UI.page_view), image, page->number); g_static_mutex_unlock(&(page->lock)); return true;